It logs the fd, core file size, file size, and number of process
limits at level trace1.

The platform check is not so pretty (low-level feature checks similar
to those for the RLimit* directives) but OTOH it would be more
boilerplate code that has to be added to most MPMs.

Any thoughts on improving the placement of the call to the logging
function (or anything else, of course)?
Index: os/unix/unixd.c
===================================================================
--- os/unix/unixd.c     (revision 1057345)
+++ os/unix/unixd.c     (working copy)
@@ -54,6 +54,41 @@
 
 APLOG_USE_MODULE(core);
 
+#if APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
+static void log_rlimit(server_rec *main, int resource, const char *description)
+{
+    struct rlimit limit;
+
+    if (getrlimit(resource, &limit) != 0) {
+        ap_log_error(APLOG_MARK, APLOG_TRACE1, errno, main,
+                     "getrlimit(%d/%s) failed", resource, description);
+    }
+    else {
+        ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, main,
+                     "%s limits: %ld (hard), %ld (soft)",
+                     description, (long)limit.rlim_max, (long)limit.rlim_cur);
+    }
+}
+
+AP_DECLARE(void) ap_unixd_log_rlimits(server_rec *main)
+{
+    if (APLOGtrace1(main)) {
+#ifdef RLIMIT_NOFILE
+        log_rlimit(main, RLIMIT_NOFILE, "File descriptor");
+#endif
+#ifdef RLIMIT_CORE
+        log_rlimit(main, RLIMIT_CORE,   "Core file size");
+#endif
+#ifdef RLIMIT_FSIZE
+        log_rlimit(main, RLIMIT_FSIZE,  "File size");
+#endif
+#ifdef RLIMIT_NPROC
+        log_rlimit(main, RLIMIT_NPROC,  "Process");
+#endif
+    }
+}
+#endif /* APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT */
+
 AP_DECLARE(void) ap_unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
                                      const char *arg,
                                      const char * arg2, int type)
Index: os/unix/unixd.h
===================================================================
--- os/unix/unixd.h     (revision 1057345)
+++ os/unix/unixd.h     (working copy)
@@ -81,6 +81,10 @@
 } unixd_config_rec;
 AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config;
 
+#if APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
+AP_DECLARE(void) ap_unixd_log_rlimits(server_rec *main);
+#endif
+
 #if defined(RLIMIT_CPU) || defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || 
defined(RLIMIT_NPROC) || defined(RLIMIT_AS)
 AP_DECLARE(void) ap_unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
                                      const char *arg, 
Index: server/core.c
===================================================================
--- server/core.c       (revision 1057345)
+++ server/core.c       (working copy)
@@ -4013,6 +4013,20 @@
                      "or other system security module is loaded.");
         return !OK;
     }
+
+#if APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
+    {
+        const char *key = "core.c::configpass";
+
+        if (ap_retained_data_get(key) == NULL) {
+            ap_retained_data_create(key, 1);
+        }
+        else {
+            ap_unixd_log_rlimits(s);
+        }
+    }
+#endif
+
     return OK;
 }
 

Reply via email to