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 When files are opened to a numerical file descriptor, the numbers start at 3. This is because the 0–2 filedescriptors are already allocated: 0 to stdin, 1 to stdout, and 2 to stderr.fstat returns information about a file, with the first argument being the file descriptor, which, ashere, will have been set up by an earlier open call. The next section, in the brackets, is a stat structure,which contains various pieces of information about the file. To get the full information, use the -v optionto strace. What we see here from the stat structure is the file protection and the size (in bytes) of thefile. The protection uses the same coding as chmod, so here it’s 0644, meaning owner+group read, ownerwrite, and owner execute. (The other part of the mode field is a flag identifying whether it’s a regular file,directory, or something else. S_IFREG means it’s a regular file.) fstat returns 0 for success. File protectioncan be another source of problems.Later in your strace output, if you’re running an interpreted script in a language like Perl, you’ll seesome getuid and getgid calls, which fetch the user and group ID that the process is running as and alsothe effective user and group ID. If you’re running an executable like a C program directly, you won’t seethese checks, because they’ll already have been done before the program started running. A Perl scriptwill also have a readlink line like this, which loads up the path to the executable:readlink("/proc/self/exe", "/usr/bin/perl", 4095) = 13/proc/self/exe is a symbolic link to the executable path; the second buffer is the actual path.If running a compiled program, you won’t see a readlink call, because the code is executed directlyrather than locating an executable to feed it through. You’re less likely to see problems at this stage of thecode; user/group ID issues should generate a usable error message to stdout without having to fire upstrace.■ Note <strong>Linux</strong> system calls are very well documented. You can get information on any of the system calls you’llsee in strace output via their man pages (man functionname or man 2 functionname).11-4a. Setting strace OptionsHere are your strace options:• -f: Traces child processes (forks) as they’re created.• -t, -tt, -ttt: Puts the time of day at the start of each line given to the second,microsecond, or second+microsecond and written as seconds-since-epoch.• -T: Shows the time spent in system calls (that is, the time difference between thebeginning and end of each system call).• -r: Prints a relative timestamp at the start of each system call.220Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!