>Number:         3376
>Category:       mod_cgi
>Synopsis:       Cgis takeover the world and send the system spiraling down to 
>its death
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          change-request
>Submitter-Id:   apache
>Arrival-Date:   Tue Nov 10 17:20:01 PST 1998
>Last-Modified:
>Originator:     [EMAIL PROTECTED]
>Organization:
apache
>Release:        1.3.3
>Environment:
Test #1:
Linux update.vdi.net 2.0.35 #22 Sep 5 15:26:44 EDT 1998 i686 unknown

Test #2:
FreeBSD southpark.vdi.net 2.2.6-RELEASE FreeBSD 2.2.6-RELEASE #0: Web Mar 25 02:
28:49 GMT 1998      [EMAIL PROTECTED]:/usr/src/sys/compile/GENERIC i386  
>Description:
Cgis have a tendency to go out of control if you have lots of generic people 
running them. 
>How-To-Repeat:
#!/usr/bin/perl
$|=1;
print "Content-type: text/html\n\n"
while (1) {
        print "crash burn die\n";
}
exit;
>Fix:
--- mod_cgi.c.old       Mon Sep 21 17:09:51 1998
+++ mod_cgi.c   Tue Nov 10 19:20:33 1998
@@ -96,11 +96,13 @@
 
 #define DEFAULT_LOGBYTES 10385760
 #define DEFAULT_BUFBYTES 1024
+#define DEFAULT_CGIPRIO 0
 
 typedef struct {
     char *logname;
     long logbytes;
     int bufbytes;
+    int cgiprio;
 } cgi_server_conf;
 
 static void *create_cgi_config(pool *p, server_rec *s)
@@ -111,6 +113,7 @@
     c->logname = NULL;
     c->logbytes = DEFAULT_LOGBYTES;
     c->bufbytes = DEFAULT_BUFBYTES;
+    c->cgiprio = DEFAULT_CGIPRIO;
 
     return c;
 }
@@ -152,6 +155,16 @@
     return NULL;
 }
 
+static const char *set_cgi_priority(cmd_parms *cmd, void *dummy, char *arg)
+{
+    server_rec *s = cmd->server;
+    cgi_server_conf *conf =
+    (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
+
+    conf->cgiprio = atoi(arg);
+    return NULL;
+}
+
 static const command_rec cgi_cmds[] =
 {
     {"ScriptLog", set_scriptlog, NULL, RSRC_CONF, TAKE1,
@@ -160,6 +173,8 @@
      "the maximum length (in bytes) of the script debug log"},
     {"ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF, TAKE1,
      "the maximum size (in bytes) to record of a POST request"},
+    {"CgiPriority", set_cgi_priority, NULL, OR_FILEINFO, TAKE1,
+     "the priority to run cgis with"},
     {NULL}
 };
 
@@ -350,6 +365,7 @@
 
 static int cgi_handler(request_rec *r)
 {
+    int child_pid;
     int retval, nph, dbpos = 0;
     char *argv0, *dbuf = NULL;
     BUFF *script_out, *script_in, *script_err;
@@ -428,13 +444,21 @@
      * waiting for free_proc_chain to cleanup in the middle of an
      * SSI request -djg
      */
-    if (!ap_bspawn_child(r->main ? r->main->pool : r->pool, cgi_child,
-                        (void *) &cld, kill_after_timeout,
-                        &script_out, &script_in, &script_err)) {
+
+    child_pid = ap_bspawn_child(r->main ? r->main->pool : r->pool, cgi_child,
+    (void *)&cld, kill_after_timeout, &script_out, &script_in, &script_err);
+
+    if (!child_pid) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "couldn't spawn child process: %s", r->filename);
        return HTTP_INTERNAL_SERVER_ERROR;
     }
+
+#ifndef WIN32
+    if (conf->cgiprio) {
+           setpriority(0, child_pid, conf->cgiprio);
+    }
+#endif
 
     /* Transfer any put/post args, CERN style...
      * Note that if a buggy script fails to read everything we throw
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <[EMAIL PROTECTED]> in the Cc line ]
[and leave the subject line UNCHANGED.  This is not done]
[automatically because of the potential for mail loops. ]
[If you do not include this Cc, your reply may be ig-   ]
[nored unless you are responding to an explicit request ]
[from a developer.                                      ]
[Reply only with text; DO NOT SEND ATTACHMENTS!         ]



Reply via email to