httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tsuyoshi SASAMOTO <nazon...@super.win.ne.jp>
Subject FileDescriptorLimit & ScriptsockBacklog (was: [PATCH] increase file descriptor limit automatically at httpd start up)
Date Sat, 13 Jul 2002 10:08:56 GMT
How about to make a new directive such as "FileDescriptorLimit"?

Also, how about "ScriptsockBacklog" - to specify the backlog number
of the cgid socket.


Tsuyoshi SASAMOTO
nazonazo@super.win.ne.jp

--- httpd-2.0.39/os/unix/unixd.c	Sun May 26 17:27:10 2002
+++ httpd-2.0.39/os/unix/unixd.c	Sat Jul 13 14:17:29 2002
@@ -226,6 +226,70 @@
     return NULL;
 }
 
+AP_DECLARE(const char *) unixd_set_rlimit_nofile(cmd_parms *cmd, void *dummy,
+                                          const char *soft, const char *hard)
+{
+#if defined(RLIMIT_NOFILE) && APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
&& APR_HAVE_SETRLIMIT
+    struct rlimit glimit, slimit;
+
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL) {
+        return err;
+    }
+
+    if (getrlimit(RLIMIT_NOFILE, &glimit))  {
+        ap_log_error(APLOG_MARK, APLOG_ERR, errno, cmd->server,
+                     "%s: getrlimit failed", cmd->cmd->name);
+        return NULL;
+    }
+
+    if (!soft[strspn(soft, "0123456789")]) {
+        slimit.rlim_cur = atol(soft);
+    }
+    else if (!strcasecmp(soft, "max")) {
+        slimit.rlim_cur = glimit.rlim_max;
+    }
+    else {
+        return apr_pstrcat(cmd->temp_pool, cmd->cmd->name, 
+                           ": Invalid parameter: ", soft, NULL);
+    }
+
+    if (hard) {
+        if (!hard[strspn(hard, "0123456789")]) {
+            /* if we aren't running as root, cannot increase max */
+            if (geteuid()) {
+                slimit.rlim_max = glimit.rlim_max;
+                ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+                             "Must be uid 0 to raise maximum %s", cmd->cmd->name);
+            }
+            else {
+                slimit.rlim_max = atol(hard);
+            }
+        }
+        else {
+            return apr_pstrcat(cmd->temp_pool, cmd->cmd->name, 
+                               ": Invalid parameter: ", hard, NULL);
+        }
+    }
+    else {
+        slimit.rlim_max = glimit.rlim_max;
+    }
+
+    if (setrlimit(RLIMIT_NOFILE, &slimit)) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, errno, cmd->server,
+                     "%s: unable to set file descriptor limit "
+                     "%ld/%ld (soft/hard)", cmd->cmd->name,
+                     (long)slimit.rlim_cur, (long)slimit.rlim_max);
+    }
+
+    return NULL;
+
+#else
+    return apr_pstrcat(cmd->temp_pool, "Platform does not support rlimit for ",
+                       cmd->cmd->name, NULL);
+#endif
+}
+
 AP_DECLARE(void) unixd_pre_config(apr_pool_t *ptemp)
 {
     apr_finfo_t wrapper;
--- httpd-2.0.39/os/unix/unixd.h	Tue May  7 03:19:53 2002
+++ httpd-2.0.39/os/unix/unixd.h	Sat Jul 13 14:17:29 2002
@@ -116,6 +116,8 @@
                                         const char *arg);
 AP_DECLARE(const char *) unixd_set_group(cmd_parms *cmd, void *dummy, 
                                          const char *arg);
+AP_DECLARE(const char *) unixd_set_rlimit_nofile(cmd_parms *cmd, void *dummy,
+                                          const char *soft, const char *hard);
 #if defined(RLIMIT_CPU) || defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_NPROC)
|| defined(RLIMIT_AS)
 AP_DECLARE(void) unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
                            const char *arg, const char * arg2, int type);
@@ -136,6 +138,8 @@
 AP_INIT_TAKE1("User", unixd_set_user, NULL, RSRC_CONF, \
   "Effective user id for this server"), \
 AP_INIT_TAKE1("Group", unixd_set_group, NULL, RSRC_CONF, \
-  "Effective group id for this server")
+  "Effective group id for this server"), \
+AP_INIT_TAKE12("FileDescriptorLimit", unixd_set_rlimit_nofile, NULL, RSRC_CONF, \
+  "Soft/hard limits of the number of file descriptors for this server")
 
 #endif
--- httpd-2.0.39/modules/generators/mod_cgid.c	Fri Jun 14 04:41:17 2002
+++ httpd-2.0.39/modules/generators/mod_cgid.c	Fri Jul 12 07:35:06 2002
@@ -178,12 +178,13 @@
 #define DEFAULT_CONNECT_ATTEMPTS  15
 #endif
 
-typedef struct { 
+typedef struct {
     const char *sockname;
-    const char *logname; 
-    long logbytes; 
-    int bufbytes; 
-} cgid_server_conf; 
+    const char *logname;
+    long logbytes;
+    int bufbytes;
+    int sockbacklog;
+} cgid_server_conf;
 
 /* If a request includes query info in the URL (stuff after "?"), and
  * the query info does not contain "=" (indicative of a FORM submission),
@@ -544,7 +545,7 @@
         return errno;
     } 
 
-    if (listen(sd, DEFAULT_CGID_LISTENBACKLOG) < 0) {
+    if (listen(sd, sconf->sockbacklog) < 0) {
         ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, 
                      "Couldn't listen on unix domain socket"); 
         return errno;
@@ -715,17 +716,18 @@
     return OK;
 } 
 
-static void *create_cgid_config(apr_pool_t *p, server_rec *s) 
-{ 
-    cgid_server_conf *c = 
-    (cgid_server_conf *) apr_pcalloc(p, sizeof(cgid_server_conf)); 
+static void *create_cgid_config(apr_pool_t *p, server_rec *s)
+{
+    cgid_server_conf *c =
+    (cgid_server_conf *) apr_pcalloc(p, sizeof(cgid_server_conf));
 
-    c->logname = NULL; 
-    c->logbytes = DEFAULT_LOGBYTES; 
-    c->bufbytes = DEFAULT_BUFBYTES; 
-    c->sockname = ap_server_root_relative(p, DEFAULT_SOCKET); 
-    return c; 
-} 
+    c->logname = NULL;
+    c->logbytes = DEFAULT_LOGBYTES;
+    c->bufbytes = DEFAULT_BUFBYTES;
+    c->sockbacklog = DEFAULT_CGID_LISTENBACKLOG;
+    c->sockname = ap_server_root_relative(p, DEFAULT_SOCKET);
+    return c;
+}
 
 static void *merge_cgid_config(apr_pool_t *p, void *basev, void *overridesv) 
 { 
@@ -785,19 +787,32 @@
     return NULL; 
 } 
 
-static const command_rec cgid_cmds[] = 
-{ 
+static const char *set_scriptsock_backlog(cmd_parms *cmd, void *dummy, const char *arg)
+{
+    server_rec *s = cmd->server;
+    cgid_server_conf *conf = ap_get_module_config(s->module_config,
+                                                  &cgid_module);
+
+    conf->sockbacklog = atoi(arg);
+    return NULL;
+}
+
+static const command_rec cgid_cmds[] =
+{
     AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
-                  "the name of a log for script debugging info"), 
+                  "the name of a log for script debugging info"),
     AP_INIT_TAKE1("ScriptLogLength", set_scriptlog_length, NULL, RSRC_CONF,
-                  "the maximum length (in bytes) of the script debug log"), 
+                  "the maximum length (in bytes) of the script debug log"),
     AP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
-                  "the maximum size (in bytes) to record of a POST request"), 
+                  "the maximum size (in bytes) to record of a POST request"),
     AP_INIT_TAKE1("Scriptsock", set_script_socket, NULL, RSRC_CONF,
                   "the name of the socket to use for communication with "
-                  "the cgi daemon."), 
-    {NULL} 
-}; 
+                  "the cgi daemon."),
+    AP_INIT_TAKE1("ScriptsockBacklog", set_scriptsock_backlog, NULL, RSRC_CONF,
+                  "the maximum length of the queue of pending connections "
+                  "for `Scriptsock`"),
+    {NULL}
+};
 
 static int log_scripterror(request_rec *r, cgid_server_conf * conf, int ret, 
                            apr_status_t rv, char *error) 

Mime
View raw message