You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sander Striker <st...@apache.org> on 2002/07/10 17:14:02 UTC

RE: [PATCH] increase file descriptor limit automatically at httpdstartup

> From: Brian Pane [mailto:bpane@pacbell.net]
> Sent: 10 July 2002 17:00

> On Wed, 2002-07-10 at 04:16, Jeff Trawick wrote:
>> Brian Pane <bp...@pacbell.net> writes:

[...]
> What do you think about about setting the ulimit in apachectl
> (and not in the httpd) by default?
> 
> That would provide the intended benefit for normal users, but
> developers doing testing of the out-of-files error handling could
> easily comment out that line in apachectl.

I thought we were moving away from apachectl.

Sander


Re: [PATCH] increase file descriptor limit automatically at httpdstartup

Posted by Jeff Trawick <tr...@attglobal.net>.
"Sander Striker" <st...@apache.org> writes:

> > From: Brian Pane [mailto:bpane@pacbell.net]
> > Sent: 10 July 2002 17:00
> 
> > On Wed, 2002-07-10 at 04:16, Jeff Trawick wrote:
> >> Brian Pane <bp...@pacbell.net> writes:
> 
> [...]
> > What do you think about about setting the ulimit in apachectl
> > (and not in the httpd) by default?
> > 
> > That would provide the intended benefit for normal users, but
> > developers doing testing of the out-of-files error handling could
> > easily comment out that line in apachectl.
> 
> I thought we were moving away from apachectl.

We still have to have some shell script to set required environment
variables and which can be used to access arbitrary httpd function.

We still need apachectl since we need to supply something with the
proper user interface for an init script (see Mark Slemko's
back-to-reality post during prior discussions).

Apparently, most folks (not me) want apachectl to fulfill both
requirements.

-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

Re: FileDescriptorLimit & ScriptsockBacklog

Posted by Tsuyoshi SASAMOTO <na...@super.win.ne.jp>.
>> Also, how about "ScriptsockBacklog" - to specify the backlog number
>> of the cgid socket.
>
>+1, but can you figure out what is messed up with the parts of your
>patch to add ScriptsockBacklog?  The patch shows a lot of lines
>changed when they look the same (whitespace inadvertently changed I
>guess).  I don't have time to hand-merge it.

Thanks... The patch eliminates extra whitespaces at EOL, such as:

-  statement; <EOL>
+  statement;<EOL>

Here is a patch that doesn't eliminate them.


Tsuyoshi SASAMOTO
nazonazo@super.win.ne.jp

--- 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	Thu Jul 18 09:49:56 2002
@@ -183,6 +183,7 @@
     const char *logname; 
     long logbytes; 
     int bufbytes; 
+    int sockbacklog;
 } cgid_server_conf; 
 
 /* If a request includes query info in the URL (stuff after "?"), and
@@ -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;
@@ -723,6 +724,7 @@
     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; 
 } 
@@ -785,6 +787,16 @@
     return NULL; 
 } 
 
+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,
@@ -796,6 +808,9 @@
     AP_INIT_TAKE1("Scriptsock", set_script_socket, NULL, RSRC_CONF,
                   "the name of the socket to use for communication with "
                   "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} 
 }; 
 

Re: FileDescriptorLimit & ScriptsockBacklog (was: [PATCH] increase file descriptor limit automatically at httpd start up)

Posted by Jeff Trawick <tr...@attglobal.net>.
Tsuyoshi SASAMOTO <na...@super.win.ne.jp> writes:

> How about to make a new directive such as "FileDescriptorLimit"?

I think this was solved differently.

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

+1, but can you figure out what is messed up with the parts of your
patch to add ScriptsockBacklog?  The patch shows a lot of lines
changed when they look the same (whitespace inadvertently changed I
guess).  I don't have time to hand-merge it.

Thanks a bunch,

Jeff

-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

FileDescriptorLimit & ScriptsockBacklog (was: [PATCH] increase file descriptor limit automatically at httpd start up)

Posted by Tsuyoshi SASAMOTO <na...@super.win.ne.jp>.
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)