this small patch allows to select how aggressive a cgi should be swept away. With the directive ScriptKillPolicy one can select per server, which kill_condition is passed to ap_bspawn_child and free_proc_chain.
lothar -- Lothar Märkle - [EMAIL PROTECTED] Netpioneer GmbH - Beiertheimer Allee 18a - D-76137 Karlsruhe Tel: 0721 / 9 20 60 43 Fax: 0721 / 9 20 60 30 Index: mod_cgi.c =================================================================== RCS file: /home/cvspublic/apache-1.3/src/modules/standard/mod_cgi.c,v retrieving revision 1.102 diff -u -r1.102 mod_cgi.c --- mod_cgi.c 3 Feb 2003 17:13:27 -0000 1.102 +++ mod_cgi.c 1 Jul 2003 11:08:40 -0000 @@ -97,11 +97,13 @@ #define DEFAULT_LOGBYTES 10385760 #define DEFAULT_BUFBYTES 1024 +#define DEFAULT_KILLPOLICY kill_after_timeout typedef struct { char *logname; long logbytes; int bufbytes; + enum kill_conditions killpolicy; } cgi_server_conf; static void *create_cgi_config(pool *p, server_rec *s) @@ -112,15 +114,21 @@ c->logname = NULL; c->logbytes = DEFAULT_LOGBYTES; c->bufbytes = DEFAULT_BUFBYTES; + c->killpolicy = DEFAULT_KILLPOLICY; return c; } static void *merge_cgi_config(pool *p, void *basev, void *overridesv) { - cgi_server_conf *base = (cgi_server_conf *) basev, *overrides = (cgi_server_conf *) overridesv; + cgi_server_conf *base = (cgi_server_conf *) basev, *overrides = (cgi_server_conf *) overridesv, *new = (cgi_server_conf *) ap_pcalloc(p, sizeof(cgi_server_conf)); - return overrides->logname ? overrides : base; + new->logname = overrides->logname ? overrides->logname : base->logname; + new->logbytes = overrides->logbytes ? overrides->logbytes : base->logbytes; + new->bufbytes = overrides->bufbytes ? overrides->bufbytes : base->bufbytes; + new->killpolicy = overrides->killpolicy ? overrides->killpolicy : base->killpolicy; + + return new; } static const char *set_scriptlog(cmd_parms *cmd, void *dummy, char *arg) @@ -153,6 +161,30 @@ return NULL; } +static const char *set_scriptkill_policy(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); + + if( strcmp( arg, "KillNever" ) == 0 ) { + conf->killpolicy = kill_never; + } else if( strcmp( arg, "KillAlways" ) == 0 ) { + conf->killpolicy = kill_always; + } else if( strcmp( arg, "KillAfterTimeout" ) == 0 ) { + conf->killpolicy = kill_after_timeout; + } else if( strcmp( arg, "JustWait" ) == 0 ) { + conf->killpolicy = just_wait; + } else if( strcmp( arg, "KillOnlyOnce" ) == 0 ) { + conf->killpolicy = kill_only_once; + } else { + return "ScriptKillPolicy must be set to KillAfterTimeout, KillNever, KillAlways, JustWait or KillOnlyOnce"; + } + + return NULL; +} + + + static const command_rec cgi_cmds[] = { {"ScriptLog", set_scriptlog, NULL, RSRC_CONF, TAKE1, @@ -161,6 +193,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"}, + {"ScriptKillPolicy", set_scriptkill_policy, NULL, RSRC_CONF, TAKE1, + "the kill policy used to get rid of silly scripts(KillAfterTimeout, KillNever, KillAlways, JustWait or KillOnlyOnce)"}, {NULL} }; @@ -377,7 +411,6 @@ void *sconf = r->server->module_config; cgi_server_conf *conf = (cgi_server_conf *) ap_get_module_config(sconf, &cgi_module); - struct cgi_child_stuff cld; if (r->method_number == M_OPTIONS) { @@ -459,8 +492,7 @@ * 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, + if (!ap_bspawn_child(r->main ? r->main->pool : r->pool, cgi_child, (void *) &cld, conf->killpolicy, &script_out, &script_in, &script_err)) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "couldn't spawn child process: %s", r->filename);