s3/dump_core: Honour pipe symbol (|) in system-wide core_pattern under linux
authorAnoop C S <anoopcs@redhat.com>
Wed, 16 Nov 2016 08:55:13 +0000 (08:55 +0000)
committerMichael Adam <obnox@samba.org>
Wed, 23 Nov 2016 19:49:28 +0000 (20:49 +0100)
From man core(5):

"Since  kernel  2.6.19, Linux supports an alternate syntax for the
/proc/sys/kernel/core_pattern file.  If the first character of this
file is a pipe symbol (|), then the remainder of the line is interpreted
as a user-space program to be executed."

Discarding this symbol would result in misleading logs for smbd/nmbd/winbindd.
For example even if core_pattern contains '|', smbd logs would suggest the
following:

...
dumping core in /var/log/samba/cores/smbd
...

and coredump may or may not get created at that location depending on which
helper binary is being used for handling coredumps.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/lib/dumpcore.c

index c72aa882bd884213b6eb597f31054f02b59ac740..6c305ab81d773dd56367dd55d13f245ab42404be 100644 (file)
@@ -37,6 +37,7 @@
 #endif
 
 static char *corepath;
+static bool using_helper_binary = false;
 
 /**
  * Build up the default corepath as "<logbase>/cores/<progname>"
@@ -169,6 +170,12 @@ static char *get_linux_corepath(void)
                /*
                 * No absolute path, use the default (cwd)
                 */
+               if (result[0] == '|') {
+                       /*
+                       * Core dump handled by helper binaries
+                       */
+                       using_helper_binary = true;
+               }
                TALLOC_FREE(result);
                return NULL;
        }
@@ -291,16 +298,25 @@ void dump_core_setup(const char *progname, const char *log_file)
        }
 
        if (*corepath != '\0') {
-               /* The chdir might fail if we dump core before we finish
-                * processing the config file.
+               /*
+                * Check whether coredump is handled by helper binaries or not.
+                * If so skip chdir().
                 */
-               if (chdir(corepath) != 0) {
-                       DEBUG(0, ("unable to change to %s\n", corepath));
-                       DEBUGADD(0, ("refusing to dump core\n"));
-                       exit(1);
-               }
+               if (!using_helper_binary) {
+                       /* The chdir might fail if we dump core before we finish
+                        * processing the config file.
+                        */
+                       if (chdir(corepath) != 0) {
+                               DEBUG(0, ("unable to change to %s\n", corepath));
+                               DEBUGADD(0, ("refusing to dump core\n"));
+                               exit(1);
+                       }
 
-               DEBUG(0,("dumping core in %s\n", corepath));
+                       DEBUG(0,("dumping core in %s\n", corepath));
+               } else {
+                       DEBUG(0,("coredump is handled by helper binary "
+                                "specified at /proc/sys/kernel/core_pattern"));
+               }
        }
 
        umask(~(0700));