13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 11 ■ TRACKING DOWN BUGS■ Note Some editors (for example, vim) are able to do syntax highlighting of strace output. This is very useful inmaking sense of the output because it helps your eye jump to the correct parts.Here are a couple of lines of output from running strace on a “Hello World” Perl program:execve("./helloworld.pl", ["./helloworld.pl"], [/* 20 vars */]) = 0uname({sys="<strong>Linux</strong>", node="client1.example.com", ...}) = 0The basic structure of each line is the same. Each line is a single system call, with the call name atthe start of the line, its arguments in brackets, and the return value after the = at the end of the line.The uname line here demonstrates another feature of strace. Some system calls involve a pointer to aparticular data structure. Here, uname returns a pointer to the system information data. stracedereferences the pointer for you and fills in the data. By default, it will print only a little of that datastructure; to get the whole thing, use the -v option to strace.Here’s some more sample output:access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)open("/etc/ld.so.cache", O_RDONLY) = 3fstat(3, {st_mode=S_IFREG|0644, st_size=43270, ...}) = 0mmap(NULL, 43270, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b8740901000close(3) = 0The access call shows what file the program is trying to access (for example, /etc/ld.so.preload)and whether it was successful. A value of –1 means unsuccessful, and then there’s an error code (E*****:in this case, ENOENT), which is translated for you. ENOENT means “no such file or directory,” but stracehelpfully looks up the plain-English meaning of the error code, so you shouldn’t need to do so. access, ifthe file does exist, checks whether the program is allowed to access it (for example, if the permissions arecorrectly set).■ Note The ld files are related to static and dynamic linking. Static linking means that a program creates its ownlibraries and uses those. Dynamic linking means that a program uses the system libraries, so you need only onecopy of all the standard libraries, not a copy per program. Nearly all <strong>Linux</strong> programs now use dynamic linking, soany program you run strace on will look for various ld files before doing anything else. Failure to find one of theld files isn’t necessarily a problem. See recipe 11-5 for comments on ltrace and ldd.open does exactly what you’d expect. It tries to open the specified file. If that file exists, the returnvalue is a positive number. This is the file descriptor, which is the “handle” that the system will use torefer to this file for subsequent system calls. <strong>Problem</strong>s with accessing or opening a particular file are oneof the most likely causes of a bug, so pay particular attention to these calls. However, be aware thatconfig files may be looked for in multiple locations, which will generate a cluster of failure-to-open callsthat are absolutely normal. Use the -e option (see recipe 11-4a) to trace only particular types of call.219Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!