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 Sat, 13 Dec 2003 19:00:56 GMT
trawick     2003/12/13 11:00:56

  Modified:    server/mpm/experimental/leader leader.c
               server/mpm/experimental/threadpool threadpool.c
               server/mpm/worker worker.c
  Log:
  update leader, threadpool, and worker MPMs to return MPM state
  from ap_mpm_query()
  
  Revision  Changes    Path
  1.35      +25 -2     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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- leader.c	13 Dec 2003 15:46:09 -0000	1.34
  +++ leader.c	13 Dec 2003 19:00:56 -0000	1.35
  @@ -166,6 +166,7 @@
   static int requests_this_child;
   static int num_listensocks = 0;
   static int resource_shortage = 0;
  +static int mpm_state = AP_MPMQ_STARTING;
   
   typedef struct worker_wakeup_info worker_wakeup_info;
   
  @@ -400,6 +401,7 @@
           return;
       }
       terminate_mode = mode;
  +    mpm_state = AP_MPMQ_STOPPING;
       workers_may_exit = 1;
   
       worker_stack_term(idle_worker_stack);
  @@ -444,6 +446,9 @@
           case AP_MPMQ_MAX_DAEMONS:
               *result = ap_daemons_limit;
               return APR_SUCCESS;
  +        case AP_MPMQ_MPM_STATE:
  +            *result = mpm_state;
  +            return APR_SUCCESS;
       }
       return APR_ENOTIMPL;
   }
  @@ -452,6 +457,7 @@
   static void clean_child_exit(int code) __attribute__ ((noreturn));
   static void clean_child_exit(int code)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (pchild) {
           apr_pool_destroy(pchild);
       }
  @@ -496,6 +502,7 @@
   
   static void ap_start_shutdown(void)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (shutdown_pending == 1) {
           /* Um, is this _probably_ not an error, if the user has
            * tried to do a shutdown twice quickly, so we won't
  @@ -509,7 +516,7 @@
   /* do a graceful restart if graceful == 1 */
   static void ap_start_restart(int graceful)
   {
  -
  +    mpm_state = AP_MPMQ_STOPPING;
       if (restart_pending == 1) {
           /* Probably not an error - don't bother reporting it */
           return;
  @@ -1056,6 +1063,10 @@
       apr_threadattr_t *thread_attr;
       apr_thread_t *start_thread_id;
   
  +    mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
  +                                  * child initializes
  +                                  */
  +
       ap_my_pid = getpid();
       ap_fatal_signal_child_setup(ap_server_conf);
       apr_pool_create(&pchild, pconf);
  @@ -1133,6 +1144,8 @@
           clean_child_exit(APEXIT_CHILDFATAL);
       }
   
  +    mpm_state = AP_MPMQ_RUNNING;
  +
       /* If we are only running in one_process mode, we will want to
        * still handle signals. */
       if (one_process) {
  @@ -1505,6 +1518,7 @@
       if (rv != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                        "Couldn't create accept lock");
  +        mpm_state = AP_MPMQ_STOPPING;
           return 1;
       }
   
  @@ -1519,12 +1533,14 @@
               ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                            "Couldn't set permissions on cross-process lock; "
                            "check User and Group directives");
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
       }
   
       if (!is_graceful) {
           if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
           /* fix the generation number in the global score; we just got a new,
  @@ -1572,8 +1588,10 @@
   		apr_proc_mutex_defname());
   #endif
       restart_pending = shutdown_pending = 0;
  +    mpm_state = AP_MPMQ_RUNNING;
   
       server_main_loop(remaining_children_to_start);
  +    mpm_state = AP_MPMQ_STOPPING;
   
       if (shutdown_pending) {
           /* Time to gracefully shut down:
  @@ -1679,6 +1697,8 @@
       ap_directive_t *max_clients = NULL;
       apr_status_t rv;
   
  +    mpm_state = AP_MPMQ_STARTING;
  +
       /* make sure that "ThreadsPerChild" gets set before "MaxClients" */
       for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
           if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
  @@ -1773,7 +1793,10 @@
       one_process = 0;
   
       ap_hook_open_logs(leader_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
  -    ap_hook_pre_config(leader_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
  +    /* we need to set the MPM state before other pre-config hooks use MPM query
  +     * to retrieve it, so register as REALLY_FIRST
  +     */
  +    ap_hook_pre_config(leader_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
   }
   
   static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
  
  
  
  1.23      +24 -2     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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- threadpool.c	13 Dec 2003 18:25:57 -0000	1.22
  +++ threadpool.c	13 Dec 2003 19:00:56 -0000	1.23
  @@ -173,6 +173,7 @@
   static int requests_this_child;
   static int num_listensocks = 0;
   static int resource_shortage = 0;
  +static int mpm_state = AP_MPMQ_STARTING;
   
   /* The structure used to pass unique initialization info to each thread */
   typedef struct {
  @@ -466,6 +467,7 @@
           return;
       }
       terminate_mode = mode;
  +    mpm_state = AP_MPMQ_STOPPING;
   
       /* in case we weren't called from the listener thread, wake up the
        * listener thread
  @@ -521,6 +523,9 @@
           case AP_MPMQ_MAX_DAEMONS:
               *result = ap_daemons_limit;
               return APR_SUCCESS;
  +        case AP_MPMQ_MPM_STATE:
  +            *result = mpm_state;
  +            return APR_SUCCESS;
       }
       return APR_ENOTIMPL;
   }
  @@ -529,6 +534,7 @@
   static void clean_child_exit(int code) __attribute__ ((noreturn));
   static void clean_child_exit(int code)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (pchild) {
           apr_pool_destroy(pchild);
       }
  @@ -572,6 +578,7 @@
   
   static void ap_start_shutdown(void)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (shutdown_pending == 1) {
           /* Um, is this _probably_ not an error, if the user has
            * tried to do a shutdown twice quickly, so we won't
  @@ -585,7 +592,7 @@
   /* do a graceful restart if graceful == 1 */
   static void ap_start_restart(int graceful)
   {
  -
  +    mpm_state = AP_MPMQ_STOPPING;
       if (restart_pending == 1) {
           /* Probably not an error - don't bother reporting it */
           return;
  @@ -1272,6 +1279,9 @@
       apr_threadattr_t *thread_attr;
       apr_thread_t *start_thread_id;
   
  +    mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
  +                                   * child initializes
  +                                   */
       ap_my_pid = getpid();
       ap_fatal_signal_child_setup(ap_server_conf);
       apr_pool_create(&pchild, pconf);
  @@ -1350,6 +1360,8 @@
           clean_child_exit(APEXIT_CHILDFATAL);
       }
   
  +    mpm_state = AP_MPMQ_RUNNING;
  +    
       /* If we are only running in one_process mode, we will want to
        * still handle signals. */
       if (one_process) {
  @@ -1755,6 +1767,7 @@
       if (rv != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                        "Couldn't create accept lock");
  +        mpm_state = AP_MPMQ_STOPPING;
           return 1;
       }
   
  @@ -1769,12 +1782,14 @@
               ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                            "Couldn't set permissions on cross-process lock; "
                            "check User and Group directives");
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
       }
   
       if (!is_graceful) {
           if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
           /* fix the generation number in the global score; we just got a new,
  @@ -1822,8 +1837,10 @@
   		apr_proc_mutex_defname());
   #endif
       restart_pending = shutdown_pending = 0;
  +    mpm_state = AP_MPMQ_RUNNING;
   
       server_main_loop(remaining_children_to_start);
  +    mpm_state = AP_MPMQ_STOPPING;
   
       if (shutdown_pending) {
           /* Time to gracefully shut down:
  @@ -1934,6 +1951,8 @@
       ap_directive_t *max_clients = NULL;
       apr_status_t rv;
   
  +    mpm_state = AP_MPMQ_STARTING;
  +    
       /* make sure that "ThreadsPerChild" gets set before "MaxClients" */
       for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
           if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
  @@ -2028,7 +2047,10 @@
       one_process = 0;
   
       ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
  -    ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
  +    /* we need to set the MPM state before other pre-config hooks use MPM query
  +     * to retrieve it, so register as REALLY_FIRST
  +     */
  +    ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
   }
   
   static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
  
  
  
  1.142     +31 -4     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.141
  retrieving revision 1.142
  diff -u -r1.141 -r1.142
  --- worker.c	24 Nov 2003 01:34:04 -0000	1.141
  +++ worker.c	13 Dec 2003 19:00:56 -0000	1.142
  @@ -175,6 +175,7 @@
   static int resource_shortage = 0;
   static fd_queue_t *worker_queue;
   static fd_queue_info_t *worker_queue_info;
  +static int mpm_state = AP_MPMQ_STARTING;
   
   /* The structure used to pass unique initialization info to each thread */
   typedef struct {
  @@ -303,6 +304,7 @@
           return;
       }
       terminate_mode = mode;
  +    mpm_state = AP_MPMQ_STOPPING;
   
       /* in case we weren't called from the listener thread, wake up the
        * listener thread
  @@ -360,6 +362,9 @@
           case AP_MPMQ_MAX_DAEMONS:
               *result = ap_daemons_limit;
               return APR_SUCCESS;
  +        case AP_MPMQ_MPM_STATE:
  +            *result = mpm_state;
  +            return APR_SUCCESS;
       }
       return APR_ENOTIMPL;
   }
  @@ -368,6 +373,7 @@
   static void clean_child_exit(int code) __attribute__ ((noreturn));
   static void clean_child_exit(int code)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (pchild) {
           apr_pool_destroy(pchild);
       }
  @@ -411,6 +417,7 @@
   
   static void ap_start_shutdown(void)
   {
  +    mpm_state = AP_MPMQ_STOPPING;
       if (shutdown_pending == 1) {
           /* Um, is this _probably_ not an error, if the user has
            * tried to do a shutdown twice quickly, so we won't
  @@ -424,7 +431,7 @@
   /* do a graceful restart if graceful == 1 */
   static void ap_start_restart(int graceful)
   {
  -
  +    mpm_state = AP_MPMQ_STOPPING;
       if (restart_pending == 1) {
           /* Probably not an error - don't bother reporting it */
           return;
  @@ -710,7 +717,7 @@
                           continue;
                       }
   
  -                    /* apr_poll() will only return errors in catastrophic
  +                    /* apr_pollset_poll() will only return errors in catastrophic
                        * circumstances. Let's try exiting gracefully, for now. */
                       ap_log_error(APLOG_MARK, APLOG_ERR, rv,
                                    (const server_rec *) ap_server_conf,
  @@ -1063,6 +1070,11 @@
        *  "life_status" is almost right, but it's in the worker's structure, and 
        *  the name could be clearer.   gla
        */
  +/*
  +    while (1) {
  +      apr_sleep(apr_time_from_sec(10));
  +    }
  +*/
       apr_thread_exit(thd, APR_SUCCESS);
       return NULL;
   }
  @@ -1146,6 +1158,9 @@
       apr_threadattr_t *thread_attr;
       apr_thread_t *start_thread_id;
   
  +    mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
  +                                   * child initializes
  +                                   */
       ap_my_pid = getpid();
       ap_fatal_signal_child_setup(ap_server_conf);
       apr_pool_create(&pchild, pconf);
  @@ -1224,6 +1239,8 @@
           clean_child_exit(APEXIT_CHILDFATAL);
       }
   
  +    mpm_state = AP_MPMQ_RUNNING;
  +
       /* If we are only running in one_process mode, we will want to
        * still handle signals. */
       if (one_process) {
  @@ -1627,6 +1644,7 @@
       if (rv != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                        "Couldn't create accept lock");
  +        mpm_state = AP_MPMQ_STOPPING;
           return 1;
       }
   
  @@ -1641,12 +1659,14 @@
               ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                            "Couldn't set permissions on cross-process lock; "
                            "check User and Group directives");
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
       }
   
       if (!is_graceful) {
           if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
  +            mpm_state = AP_MPMQ_STOPPING;
               return 1;
           }
           /* fix the generation number in the global score; we just got a new,
  @@ -1694,8 +1714,10 @@
   		apr_proc_mutex_defname());
   #endif
       restart_pending = shutdown_pending = 0;
  -
  +    mpm_state = AP_MPMQ_RUNNING;
  +    
       server_main_loop(remaining_children_to_start);
  +    mpm_state = AP_MPMQ_STOPPING;
   
       if (shutdown_pending) {
           /* Time to gracefully shut down:
  @@ -1799,6 +1821,8 @@
       ap_directive_t *max_clients = NULL;
       apr_status_t rv;
   
  +    mpm_state = AP_MPMQ_STARTING;
  +
       /* make sure that "ThreadsPerChild" gets set before "MaxClients" */
       for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
           if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
  @@ -1893,7 +1917,10 @@
       one_process = 0;
   
       ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
  -    ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
  +    /* we need to set the MPM state before other pre-config hooks use MPM query
  +     * to retrieve it, so register as REALLY_FIRST
  +     */
  +    ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
   }
   
   static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
  
  
  

Mime
View raw message