This checks for a couple of common conditions which prevent core dumps from being taken and writes a NOTICE message to the error log at startup if the condition is detected. BTW, the same code works with 1.3 with very minor tweaks (remove the apr_status_t parm from ap_log_error IIRC).

If there is positive encouragement, I'll commit to 2.1-dev, but I'd move the check_dumpable() function to ap_check_dumpable() in mpm_common.c and call it from all the Unix MPMs. The current patch is worker-specific.

If there is interest in the patch for 1.3, let me know and I'll post.

It is a bit motherly, but it can be a general educational tool for users and it also provides some appropriate negative feedback if the user is wondering why coredumps are not being written.
Index: server/mpm/worker/worker.c
===================================================================
RCS file: /cvs/phoenix/2.0.47/server/mpm/worker/worker.c,v
retrieving revision 1.5
diff -u -r1.5 worker.c
--- server/mpm/worker/worker.c  13 Feb 2004 16:56:27 -0000      1.5
+++ server/mpm/worker/worker.c  3 Mar 2004 10:37:03 -0000
@@ -1671,6 +1671,52 @@
     }
 }
 
+/* IHS addition */
+static void check_dumpable(server_rec *s)
+{
+    struct rlimit rl;
+    int rc;
+    int already_complained = 0;
+
+    rc = getrlimit(RLIMIT_CORE, &rl);
+    if (rc == 0) {
+        if (rl.rlim_cur == 0) { /* if it worked */
+            /* Regardless of whether or not the server was started as root,
+             * a soft limit of zero for core file size prevents core dumps
+             * from being written for any web server processes.
+             * Theoretically we could try to raise the soft limit to the
+             * hard limit (if it is higher), but perhaps this is the
+             * administrator's way to say they want no core dumps.
+             */
+            ap_log_error(APLOG_MARK, APLOG_NOTICE,
+                         0,
+                         s,
+                         "Core file limit is 0; core dumps will be not be "
+                         "written for server crashes");
+            already_complained = 1;
+        }
+    }
+
+    if (!already_complained &&
+        geteuid() == 0 &&
+        !ap_coredumpdir_configured) {
+        /* The server has started as root, so child processes run as another
+         * user.  They SHOULD NOT have permission to write to the web server
+         * install directory, so if CoreDumpDirectory hasn't been specified,
+         * then in general no core dump can be written.
+         * Exception: On Solaris, the coreadm command can be used to specify
+         * an alternate directory for core dumps to be written.
+         * Potentially the same feature is/will be available on other platforms.
+         */
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE,
+                     0,
+                     s,
+                     "CoreDumpDirectory not set; core dumps may not be written for "
+                     "child process crashes");
+    }
+}
+/* end IHS addition */
+
 int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 {
     int remaining_children_to_start;
@@ -1763,6 +1809,10 @@
                apr_proc_mutex_name(accept_mutex),
                apr_proc_mutex_defname());
 #endif
+    /* IHS addition */
+    check_dumpable(ap_server_conf);
+    /* end IHS addition */
+    
     restart_pending = shutdown_pending = 0;
 
     server_main_loop(remaining_children_to_start);

Reply via email to