compile errors. oops.
[Samba/gbeck.git] / docs / textdocs / Tracing.txt
blob6a9ba8b850d21391c2a70e3bafd5e8881fe1860b
1 This file describes how to do a system call trace on Samba to work out
2 what its doing wrong. This is not for the faint of heart, but if you
3 are reading this then you are probably desperate.
5 Actually its not as bad as the the above makes it sound, just don't
6 expect the output to be very pretty :-)
8 Ok, down to business. One of the big advantages of unix systems is
9 that they nearly all come with a system trace utility that allows you
10 to monitor all system calls that a program is making. This is
11 extremely using for debugging and also helps when trying to work out
12 why something is slower than you expect. You can use system tracing
13 without any special compilation options. 
15 The system trace utility is called different things on different
16 systems. On Linux systems its called strace. Under SunOS 4 its called
17 trace. Under SVR4 style systems (including solaris) its called
18 truss. Under many BSD systems its called ktrace. 
20 The first thing you should do is read the man page for your native
21 system call tracer. In the discussion below I'll assume its called
22 strace as strace is the only portable system tracer (its available for
23 free for many unix types) and its also got some of the nicest
24 features.
26 Next, try using strace on some simple commands. For example, "strace
27 ls" or "strace echo hello".
29 You'll notice that it produces a LOT of output. It is showing you the
30 arguments to every system call that the program makes and the
31 result. Very little happens in a program without a system call so you
32 get lots of output. You'll also find that it produces a lot of
33 "preamble" stuff showing the loading of shared libraries etc. Ignore
34 this (unless its going wrong!)
36 For example, the only line that really matters in the "strace echo
37 hello" output is:
39 write(1, "hello\n", 6)                  = 6
41 all the rest is just setting up to run the program.
43 Ok, now you're famialiar with strace. To use it on Samba you need to
44 strace the running smbd daemon. The way I tend ot use it is to first
45 login from my Windows PC to the Samba server, then use smbstatus to
46 find which process ID that client is attached to, then as root I do
47 "strace -p PID" to attach to that process. I normally redirect the
48 stderr output from this command to a file for later perusal. For
49 example, if I'm using a csh style shell:
51   strace -f -p 3872 >& strace.out
53 or with a sh style shell:
55   strace -f -p 3872 > strace.out 2>&1
57 Note the "-f" option. This is only available on some systems, and
58 allows you to trace not just the current process, but any children it
59 forks. This is great for finding printing problems caused by the
60 "print command" being wrong.
62 Once you are attached you then can do whatever it is on the client
63 that is causing problems and you will capture all the system calls
64 that smbd makes. 
66 So how do you interpret the results? Generally I search thorugh the
67 output for strings that I know will appear when the problem
68 happens. For example, if I am having touble with permissions on a file
69 I would search for that files name in the strace output and look at
70 the surrounding lines. Another trick is to match up file descriptor
71 numbers and "follow" what happens to an open file until it is closed.
73 Beyond this you will have to use your initiative. To give you an idea
74 of wehat you are looking for here is a piece of strace output that
75 shows that /dev/null is not world writeable, which causes printing to
76 fail with Samba:
78 [pid 28268] open("/dev/null", O_RDWR)   = -1 EACCES (Permission denied)
79 [pid 28268] open("/dev/null", O_WRONLY) = -1 EACCES (Permission denied)
81 the process is trying to first open /dev/null read-write then
82 read-only. Both fail. This means /dev/null has incorrect permissions.
84 Have fun!
86 (please send updates/fixes to this file to samba-bugs@samba.anu.edu.au)