httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: httpd-2.0/server/mpm/worker worker.c
Date Tue, 10 Feb 2004 14:53:29 GMT
trawick     2004/02/10 06:53:28

  Modified:    .        Tag: APACHE_2_0_BRANCH CHANGES STATUS
               modules/generators Tag: APACHE_2_0_BRANCH mod_cgid.c
               server/mpm/experimental/leader Tag: APACHE_2_0_BRANCH
                        leader.c
               server/mpm/experimental/threadpool Tag: APACHE_2_0_BRANCH
                        threadpool.c
               server/mpm/prefork Tag: APACHE_2_0_BRANCH prefork.c
               server/mpm/worker Tag: APACHE_2_0_BRANCH worker.c
  Log:
  mod_cgid: Restart the cgid daemon if it crashes.
  
  PR:            19849
  Submitted by:  Glenn Nielsen
  Reviewed by:   trawick, stoddard, jerenkrantz
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.988.2.239 +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.988.2.238
  retrieving revision 1.988.2.239
  diff -u -r1.988.2.238 -r1.988.2.239
  --- CHANGES	8 Feb 2004 19:16:31 -0000	1.988.2.238
  +++ CHANGES	10 Feb 2004 14:53:27 -0000	1.988.2.239
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0.49
   
  +  *) mod_cgid: Restart the cgid daemon if it crashes.  PR 19849
  +     [Glenn Nielsen <glenn apache.org>]
  +
     *) The whole codebase was relicensed and is now available under
        the Apache License, Version 2.0 (http://www.apache.org/licenses).
        [Apache Software Foundation]
  
  
  
  1.751.2.685 +1 -8      httpd-2.0/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/STATUS,v
  retrieving revision 1.751.2.684
  retrieving revision 1.751.2.685
  diff -u -r1.751.2.684 -r1.751.2.685
  --- STATUS	10 Feb 2004 12:09:56 -0000	1.751.2.684
  +++ STATUS	10 Feb 2004 14:53:27 -0000	1.751.2.685
  @@ -172,13 +172,6 @@
           server/mpm/winnt/child.c r1.21
         +1: trawick
   
  -    * mod_cgid: Restart the cgid daemon if it crashes.  PR 19849
  -        modules/generators/mod_cgid.c r1.152, r1.161
  -        server/mpm_common.c r1.111
  -        PREREQ: ap_mpm_query(mpm-state) support in Unix MPMs
  -        jerenkrantz asks: What does mpm_common.c r1.111 have to do with this?
  -        +1: trawick, stoddard, jerenkrantz
  -
       * piped log programs respawning after Apache is stopped. PR 24805
         bogus "piped log program '(null)' failed" messages during
         restart. PR 21648.  Two people have tested a similar log.c patch
  
  
  
  No                   revision
  No                   revision
  1.145.2.14 +70 -35    httpd-2.0/modules/generators/mod_cgid.c
  
  Index: mod_cgid.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/generators/mod_cgid.c,v
  retrieving revision 1.145.2.13
  retrieving revision 1.145.2.14
  diff -u -r1.145.2.13 -r1.145.2.14
  --- mod_cgid.c	9 Feb 2004 20:53:17 -0000	1.145.2.13
  +++ mod_cgid.c	10 Feb 2004 14:53:28 -0000	1.145.2.14
  @@ -74,6 +74,7 @@
   
   module AP_MODULE_DECLARE_DATA cgid_module; 
   
  +static int cgid_start(apr_pool_t *p, server_rec *main_server, apr_proc_t *procnew);
   static int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server);

   static int handle_exec(include_ctx_t *ctx, apr_bucket_brigade **bb, request_rec *r,
                          ap_filter_t *f, apr_bucket *head_ptr, apr_bucket **inserted_head);
  @@ -82,10 +83,12 @@
   static APR_OPTIONAL_FN_TYPE(ap_ssi_get_tag_and_value) *cgid_pfn_gtv;
   static APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgid_pfn_ps;
   
  -static apr_pool_t *pcgi; 
  +static apr_pool_t *pcgi = NULL; 
   static int total_modules = 0;
   static pid_t daemon_pid;
   static int daemon_should_exit = 0;
  +static server_rec *root_server = NULL;
  +static apr_pool_t *root_pool = NULL;
   
   /* Read and discard the data in the brigade produced by a CGI script */
   static void discard_script_output(apr_bucket_brigade *bb);
  @@ -224,27 +227,43 @@
   #if APR_HAS_OTHER_CHILD
   static void cgid_maint(int reason, void *data, apr_wait_t status)
   {
  -    pid_t *sd = data;
  +    apr_proc_t *proc = data;
  +    int mpm_state;
  +    int stopping;
   
       switch (reason) {
           case APR_OC_REASON_DEATH:
  +            apr_proc_other_child_unregister(data);
  +            /* If apache is not terminating or restarting,
  +             * restart the cgid daemon
  +             */
  +            stopping = 1; /* if MPM doesn't support query,
  +                           * assume we shouldn't restart daemon
  +                           */
  +            if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state) == APR_SUCCESS &&
  +                mpm_state != AP_MPMQ_STOPPING) {
  +                stopping = 0;
  +            }
  +            if (!stopping) {
  +                ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
  +                             "cgid daemon process died, restarting");
  +                cgid_start(root_pool, root_server, proc);
  +            }
  +            break;
           case APR_OC_REASON_RESTART:
               /* don't do anything; server is stopping or restarting */
               apr_proc_other_child_unregister(data);
               break;
           case APR_OC_REASON_LOST:
  -            /* it would be better to restart just the cgid child
  -             * process but for now we'll gracefully restart the entire 
  -             * server by sending AP_SIG_GRACEFUL to ourself, the httpd 
  -             * parent process
  -             */
  -            kill(getpid(), AP_SIG_GRACEFUL);
  +            /* Restart the child cgid daemon process */
  +            apr_proc_other_child_unregister(data);
  +            cgid_start(root_pool, root_server, proc);
               break;
           case APR_OC_REASON_UNREGISTER:
               /* we get here when pcgi is cleaned up; pcgi gets cleaned
                * up when pconf gets cleaned up
                */
  -            kill(*sd, SIGHUP); /* send signal to daemon telling it to die */
  +            kill(proc->pid, SIGHUP); /* send signal to daemon telling it to die */
               break;
       }
   }
  @@ -753,20 +772,51 @@
       return -1; 
   } 
   
  +static int cgid_start(apr_pool_t *p, server_rec *main_server,
  +                      apr_proc_t *procnew)
  +{
  +    daemon_should_exit = 0; /* clear setting from previous generation */
  +    if ((daemon_pid = fork()) < 0) {
  +        ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
  +                     "mod_cgid: Couldn't spawn cgid daemon process");
  +        return DECLINED;
  +    }
  +    else if (daemon_pid == 0) {
  +        if (pcgi == NULL) {
  +            apr_pool_create(&pcgi, p);
  +        }
  +        cgid_server(main_server);
  +        exit(-1);
  +    }
  +    procnew->pid = daemon_pid;
  +    procnew->err = procnew->in = procnew->out = NULL;
  +    apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
  +#if APR_HAS_OTHER_CHILD
  +    apr_proc_other_child_register(procnew, cgid_maint, procnew, NULL, p);
  +#endif
  +    return OK;
  +}
  +
   static int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, 
  -                      server_rec *main_server) 
  +                     server_rec *main_server) 
   { 
  -    apr_proc_t *procnew;
  -    void *data;
  +    apr_proc_t *procnew = NULL;
       int first_time = 0;
       const char *userdata_key = "cgid_init";
       module **m;
  +    int ret = OK;
  +
  +    root_server = main_server;
  +    root_pool = p;
   
  -    apr_pool_userdata_get(&data, userdata_key, main_server->process->pool);
  -    if (!data) {
  +    apr_pool_userdata_get((void **)&procnew, userdata_key, main_server->process->pool);
  +    if (!procnew) {
           first_time = 1;
  -        apr_pool_userdata_set((const void *)1, userdata_key,
  -                         apr_pool_cleanup_null, main_server->process->pool);
  +        procnew = apr_pcalloc(p, sizeof(*procnew));
  +        procnew->pid = -1;
  +        procnew->err = procnew->in = procnew->out = NULL;
  +        apr_pool_userdata_set((const void *)procnew, userdata_key,
  +                     apr_pool_cleanup_null, main_server->process->pool);
       }
   
       if (!first_time) {
  @@ -774,25 +824,10 @@
           for (m = ap_preloaded_modules; *m != NULL; m++)
               total_modules++;
   
  -        daemon_should_exit = 0; /* clear setting from previous generation */
  -        if ((daemon_pid = fork()) < 0) {
  -            ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, 
  -                         "mod_cgid: Couldn't spawn cgid daemon process"); 
  -            return DECLINED;
  +        ret = cgid_start(p, main_server, procnew);
  +        if (ret != OK ) {
  +            return ret;
           }
  -        else if (daemon_pid == 0) {
  -            apr_pool_create(&pcgi, p); 
  -            cgid_server(main_server);
  -            exit(-1);
  -        } 
  -        procnew = apr_pcalloc(p, sizeof(*procnew));
  -        procnew->pid = daemon_pid;
  -        procnew->err = procnew->in = procnew->out = NULL;
  -        apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
  -#if APR_HAS_OTHER_CHILD
  -        apr_proc_other_child_register(procnew, cgid_maint, &procnew->pid, NULL,
p);
  -#endif
  -
           cgid_pfn_reg_with_ssi = APR_RETRIEVE_OPTIONAL_FN(ap_register_include_handler);
           cgid_pfn_gtv          = APR_RETRIEVE_OPTIONAL_FN(ap_ssi_get_tag_and_value);
           cgid_pfn_ps           = APR_RETRIEVE_OPTIONAL_FN(ap_ssi_parse_string);
  @@ -804,7 +839,7 @@
               cgid_pfn_reg_with_ssi("exec", handle_exec);
           }
       }
  -    return OK;
  +    return ret;
   } 
   
   static void *create_cgid_config(apr_pool_t *p, server_rec *s) 
  
  
  
  No                   revision
  No                   revision
  1.26.2.8  +8 -1      httpd-2.0/server/mpm/experimental/leader/leader.c
  
  Index: leader.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/experimental/leader/leader.c,v
  retrieving revision 1.26.2.7
  retrieving revision 1.26.2.8
  diff -u -r1.26.2.7 -r1.26.2.8
  --- leader.c	9 Feb 2004 20:59:47 -0000	1.26.2.7
  +++ leader.c	10 Feb 2004 14:53:28 -0000	1.26.2.8
  @@ -427,7 +427,14 @@
   {
       apr_filepath_set(ap_coredump_dir, pconf);
       apr_signal(sig, SIG_DFL);
  -    if (ap_my_pid == parent_pid) {
  +    /* linuxthreads issue calling getpid() here:
  +     *   This comparison won't match if the crashing thread is
  +     *   some module's thread that runs in the parent process.
  +     *   The fallout, which is limited to linuxthreads:
  +     *   The special log message won't be written when such a
  +     *   thread in the parent causes the parent to crash.
  +     */
  +    if (getpid() == parent_pid) {
           ap_log_error(APLOG_MARK, APLOG_NOTICE,
                        0, ap_server_conf,
                        "seg fault or similar nasty error detected "
  
  
  
  No                   revision
  No                   revision
  1.14.2.9  +8 -1      httpd-2.0/server/mpm/experimental/threadpool/threadpool.c
  
  Index: threadpool.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/experimental/threadpool/threadpool.c,v
  retrieving revision 1.14.2.8
  retrieving revision 1.14.2.9
  diff -u -r1.14.2.8 -r1.14.2.9
  --- threadpool.c	9 Feb 2004 20:59:47 -0000	1.14.2.8
  +++ threadpool.c	10 Feb 2004 14:53:28 -0000	1.14.2.9
  @@ -503,7 +503,14 @@
   {
       apr_filepath_set(ap_coredump_dir, pconf);
       apr_signal(sig, SIG_DFL);
  -    if (ap_my_pid == parent_pid) {
  +    /* linuxthreads issue calling getpid() here:
  +     *   This comparison won't match if the crashing thread is
  +     *   some module's thread that runs in the parent process.
  +     *   The fallout, which is limited to linuxthreads:
  +     *   The special log message won't be written when such a
  +     *   thread in the parent causes the parent to crash.
  +     */
  +    if (getpid() == parent_pid) {
           ap_log_error(APLOG_MARK, APLOG_NOTICE,
                        0, ap_server_conf,
                        "seg fault or similar nasty error detected "
  
  
  
  No                   revision
  No                   revision
  1.272.2.9 +8 -1      httpd-2.0/server/mpm/prefork/prefork.c
  
  Index: prefork.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/prefork/prefork.c,v
  retrieving revision 1.272.2.8
  retrieving revision 1.272.2.9
  diff -u -r1.272.2.8 -r1.272.2.9
  --- prefork.c	9 Feb 2004 20:59:48 -0000	1.272.2.8
  +++ prefork.c	10 Feb 2004 14:53:28 -0000	1.272.2.9
  @@ -320,7 +320,14 @@
   {
       chdir(ap_coredump_dir);
       apr_signal(sig, SIG_DFL);
  -    if (ap_my_pid == parent_pid) {
  +    /* linuxthreads issue calling getpid() here:
  +     *   This comparison won't match if the crashing thread is
  +     *   some module's thread that runs in the parent process.
  +     *   The fallout, which is limited to linuxthreads:
  +     *   The special log message won't be written when such a
  +     *   thread in the parent causes the parent to crash.
  +     */
  +    if (getpid() == parent_pid) {
               ap_log_error(APLOG_MARK, APLOG_NOTICE,
                            0, ap_server_conf,
                            "seg fault or similar nasty error detected "
  
  
  
  No                   revision
  No                   revision
  1.133.2.10 +8 -1      httpd-2.0/server/mpm/worker/worker.c
  
  Index: worker.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/worker/worker.c,v
  retrieving revision 1.133.2.9
  retrieving revision 1.133.2.10
  diff -u -r1.133.2.9 -r1.133.2.10
  --- worker.c	9 Feb 2004 20:59:48 -0000	1.133.2.9
  +++ worker.c	10 Feb 2004 14:53:28 -0000	1.133.2.10
  @@ -342,7 +342,14 @@
   {
       apr_filepath_set(ap_coredump_dir, pconf);
       apr_signal(sig, SIG_DFL);
  -    if (ap_my_pid == parent_pid) {
  +    /* linuxthreads issue calling getpid() here:
  +     *   This comparison won't match if the crashing thread is
  +     *   some module's thread that runs in the parent process.
  +     *   The fallout, which is limited to linuxthreads:
  +     *   The special log message won't be written when such a
  +     *   thread in the parent causes the parent to crash.
  +     */
  +    if (getpid() == parent_pid) {
           ap_log_error(APLOG_MARK, APLOG_NOTICE,
                        0, ap_server_conf,
                        "seg fault or similar nasty error detected "
  
  
  

Mime
View raw message