[PATCH] core dumps on crash

Mike Gerdts Michael.Gerdts at alcatel.com
Wed Aug 21 12:09:01 GMT 2002


When smbd dies, it would be nice if it could dump a core file.  For
several reasons, the current code is not able to do it.  The main
reasons that it could not do it were:

        1. Most UNIX variants disable core dumps in programs that have
           changed their uid or euid during operation.  This includes
           Solaris and Linux.
        2. It is quite possible that when smbd would crash it would not
           be running as root.  It may, therefore, be unable to dump the
           core file into its current directory.  
        3. There are logic errors in the code that make it so that the
           routines that would dump_core() are never called.

This set of patches addresses those issues and one other issue:  the
administrator should be able to choose whether core dumps are done or
not.  The changes introduced are:

        1. If the smb.conf parameter "core dump directory" is not
           defined, no attempt is made to dump core.  exit() is used
           rather than abort() (I think... I should verify that yet.)
        2. If the core dump directory is not safe, no attempt to dump
           core is made.  Safe is defined as mode 700, root, and not a
           symbolic link to somewhere else.
        3. If the system is Linux, prctl() is called to enable core
           dumps that were disabled by the kernel during set*uid() or
           set*gid() calls.  After enabling the core dump, it calls
           abort(), which should dump core in its CWD (core dump
           directory).  See fs/exec.c, include/linux/prctl.h, and
           kernel/sys.c in the Linux 2.4 kernel code.  My read was based
           off of the kernel-source rpm that accompanies redhat 7.3
        4. At least on Solaris, gcore(1) is an effective way to get core
           dumps to happen.  I suspect that this will be the case on a
           good number of OS's with BSD heritage.

Now the patches, in bite size pieces (against SAMBA_2_2):

    coredump-0-build.patch
    	
        Does the configure.in, makefile.in, etc. changes necessary for
        finding prctl and gcore.
    
    coredump-1-parameter.patch
    
        Add a new parameter "core dump directory" parameter.  This
        parameter gets used in the new dump_core() implementation.
    
    coredump-2-delete_coredump.patch
    
        nmbd/nmbd.c, nsswitch/winbindd.c and smbd/server.c all had the
        exact same function defined in them.  Since this was the real
        guts of what I was changing, it made sense to consolidate it in
        one place so that the duplicate code does not diverge over time.
    
    coredump-3-new_coredump.patch
    
        I started out by modifying the dump_core() implementation
        removed from one of the three copies removed in the previous
        patch.  By the time I got done, I think I changed everything
        except the ulimit mangling stuff.  This is where it actually
        handles doing the core dump either through an abort or call to
        the system's gcore command.


And for a not-so-bitesize piece:

    coredump.patch
    
        The combination of coredump-[0-3]-*.patch.  You can apply this
        instead of the other four to get the same effect.
    
After applying these patches, you will need to run autoconf and make
proto.

There is some additional cleanup that could be done in code that
surrounds this code.  I will hold off on that until after I get
feedback, and will probably only submit cleanup patches for HEAD.

Comments are encouraged.
Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coredump-0-build.patch
Type: text/x-patch
Size: 2848 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020821/76e60533/coredump-0-build.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coredump-1-parameter.patch
Type: text/x-patch
Size: 1189 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020821/76e60533/coredump-1-parameter.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coredump-2-delete_coredump.patch
Type: text/x-patch
Size: 4508 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020821/76e60533/coredump-2-delete_coredump.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coredump-3-new_coredump.patch
Type: text/x-patch
Size: 3376 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020821/76e60533/coredump-3-new_coredump.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coredump.patch
Type: text/x-patch
Size: 11921 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020821/76e60533/coredump.bin


More information about the samba-technical mailing list