You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Lothar Märkle <lo...@netpioneer.de> on 2003/07/01 13:43:51 UTC

[PATCH] select kill policy for scripts

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 - lothar@netpioneer.de
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);


Re: [PATCH] util_ldap_cache shm broken in apache 2.x

Posted by Estrade Matthieu <es...@ifrance.com>.
Hi joe,

First, thanks for the answer.

I based my code on two examples:
First the broken util_ldap_cache_mgr.c and i just changed util_ldap_rmm 
by st->util_ldap_rmm.
Then on ssl_scache_shmht.c uring rmm to see if i have to check what 
return apr_rmm_malloc and calloc. (it's not done)

After this, i decided to not check it directly in my util_ald_alloc 
because of the example.

Matthieu

Joe Orton wrote:

>On Tue, Jul 01, 2003 at 03:01:43PM +0200, Estrade Matthieu wrote:
>...
>  
>
>> #if APR_HAS_SHARED_MEMORY
>>-    if (util_ldap_shm) {
>>-        return (void *)apr_rmm_addr_get(util_ldap_rmm, apr_rmm_calloc(util_ldap_rmm, size));
>>+    if (st->util_ldap_shm) {
>>+        return (void *)apr_rmm_addr_get(st->util_ldap_rmm, apr_rmm_calloc(st->util_ldap_rmm, size));
>>     } else {
>>    
>>
>
>Hi Matthieu - this will still break when the shmem segment fills up, the
>code needs to check for apr_rmm_malloc/calloc returning 0.
>
>joe
>_____________________________________________________________________
>Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
>http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France
>
>  
>


_____________________________________________________________________
Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France


Re: [PATCH] util_ldap_cache shm broken in apache 2.x

Posted by Joe Orton <jo...@redhat.com>.
On Tue, Jul 01, 2003 at 03:01:43PM +0200, Estrade Matthieu wrote:
...
>  #if APR_HAS_SHARED_MEMORY
> -    if (util_ldap_shm) {
> -        return (void *)apr_rmm_addr_get(util_ldap_rmm, apr_rmm_calloc(util_ldap_rmm, size));
> +    if (st->util_ldap_shm) {
> +        return (void *)apr_rmm_addr_get(st->util_ldap_rmm, apr_rmm_calloc(st->util_ldap_rmm, size));
>      } else {

Hi Matthieu - this will still break when the shmem segment fills up, the
code needs to check for apr_rmm_malloc/calloc returning 0.

joe

[PATCH] util_ldap_cache shm broken in apache 2.x

Posted by Estrade Matthieu <es...@ifrance.com>.
Hi,

I sent few weeks ago a patch for util_ldap shm cache which is broken in 
apache 2.0
The problem are:
 
shm file is unique for all httpd
-> i created a directive to specify a filename - creating default if not.

shm is initialized in child init hook
-> i move this to post_init hook

shm, rmm pointer are global and defined in util_ldap_cache.c
-> i created st->util_ldap_shm and st->util_ldap_rmm which are per root 
server address

All allocation or free with rmm are using global address
-> i made them using st->util_ldap_shm and rmm

The first patch i sent was my debug code, this one is cleaned and 
working with me in worker and prefork mpm
I would like to know if there is a reason that util_ldap.h is in 
include/ and all util_ldap code is in modules/experimental

Regards,

Matthieu