]> granicus.if.org Git - apache/blobdiff - server/mpm/worker/worker.c
Switch all unix MPMs to use drop_privileges hook (mod_unixd) for startup
[apache] / server / mpm / worker / worker.c
index 6121a12c2875229c964180496c45f020c38ec7cf..16ade8fcac99e6c278c832fdb38fefa8f21eb6fa 100644 (file)
@@ -50,8 +50,6 @@
 #error The Worker MPM requires APR threads, but they are unavailable.
 #endif
 
-#define CORE_PRIVATE
-
 #include "ap_config.h"
 #include "httpd.h"
 #include "http_main.h"
@@ -252,6 +250,10 @@ static void wakeup_listener(void)
          */
         return;
     }
+
+    /* unblock the listener if it's waiting for a worker */
+    ap_queue_info_term(worker_queue_info); 
+
     /*
      * we should just be able to "kill(ap_my_pid, LISTENER_SIGNAL)" on all
      * platforms and wake up the listener thread since it is the only thread
@@ -290,7 +292,6 @@ static void signal_threads(int mode)
     if (mode == ST_UNGRACEFUL) {
         workers_may_exit = 1;
         ap_queue_interrupt_all(worker_queue);
-        ap_queue_info_term(worker_queue_info);
         close_worker_sockets(); /* forcefully kill all current connections */
     }
 }
@@ -512,17 +513,6 @@ static void set_signals(void)
  * Here follows a long bunch of generic server bookkeeping stuff...
  */
 
-int ap_graceful_stop_signalled(void)
-    /* XXX this is really a bad confusing obsolete name
-     * maybe it should be ap_mpm_process_exiting?
-     */
-{
-    /* note: for a graceful termination, listener_may_exit will be set before
-     *       workers_may_exit, so check listener_may_exit
-     */
-    return listener_may_exit;
-}
-
 /*****************************************************************
  * Child process main loop.
  */
@@ -532,11 +522,9 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num,
 {
     conn_rec *current_conn;
     long conn_id = ID_FROM_CHILD_THREAD(my_child_num, my_thread_num);
-    int csd;
     ap_sb_handle_t *sbh;
 
     ap_create_sb_handle(&sbh, p, my_child_num, my_thread_num);
-    apr_os_sock_get(&csd, sock);
 
     current_conn = ap_run_create_connection(p, ap_server_conf, sock,
                                             conn_id, sbh, bucket_alloc);
@@ -590,7 +578,7 @@ static void dummy_signal_handler(int sig)
      */
 }
 
-static void *listener_thread(apr_thread_t *thd, void * dummy)
+static void * APR_THREAD_FUNC listener_thread(apr_thread_t *thd, void * dummy)
 {
     proc_info * ti = dummy;
     int process_slot = ti->pid;
@@ -894,7 +882,7 @@ worker_pop:
         bucket_alloc = apr_bucket_alloc_create(ptrans);
         process_socket(ptrans, csd, process_slot, thread_slot, bucket_alloc);
         worker_sockets[thread_slot] = NULL;
-        requests_this_child--; /* FIXME: should be synchronized - aaron */
+        requests_this_child--; 
         apr_pool_clear(ptrans);
         last_ptrans = ptrans;
     }
@@ -1155,7 +1143,7 @@ static void child_main(int child_num_arg)
         clean_child_exit(APEXIT_CHILDFATAL);
     }
 
-    if (unixd_setup_child()) {
+    if (ap_run_drop_privileges(pchild, ap_server_conf)) {
         clean_child_exit(APEXIT_CHILDFATAL);
     }
 
@@ -1817,12 +1805,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 
             active_children = 0;
             for (index = 0; index < ap_daemons_limit; ++index) {
-                if (MPM_CHILD_PID(index) != 0) {
-                    if (kill(MPM_CHILD_PID(index), 0) == 0) {
-                            active_children = 1;
-                            /* Having just one child is enough to stay around */
-                            break;
-                    }
+                if (ap_mpm_safe_kill(MPM_CHILD_PID(index), 0) == APR_SUCCESS) {
+                    active_children = 1;
+                    /* Having just one child is enough to stay around */
+                    break;
                 }
             }
         } while (!shutdown_pending && active_children &&
@@ -1982,8 +1968,7 @@ static int worker_check_config(apr_pool_t *p, apr_pool_t *plog,
 {
     static int restart_num = 0;
     int startup = 0;
-    apr_status_t rv;
-    
+
     /* the reverse of pre_config, we want this only the first time around */
     if (restart_num++ == 0) {
         startup = 1;