]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.3-2004-04-15-19:34:36 import
authorIgor Sysoev <igor@sysoev.ru>
Thu, 15 Apr 2004 15:34:36 +0000 (15:34 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 15 Apr 2004 15:34:36 +0000 (15:34 +0000)
13 files changed:
src/core/nginx.c
src/core/ngx_connection.c
src/core/ngx_cycle.c
src/core/ngx_cycle.h
src/core/ngx_log.c
src/event/modules/ngx_devpoll_module.c
src/event/modules/ngx_epoll_module.c
src/event/modules/ngx_kqueue_module.c
src/event/modules/ngx_poll_module.c
src/event/modules/ngx_rtsig_module.c
src/event/modules/ngx_select_module.c
src/http/modules/proxy/ngx_http_proxy_handler.c
src/os/unix/ngx_process_cycle.c

index a784040a78fe5fa7c440c2f95185ebb1bcbda6b8..5f2603cfb3e38c950f4d3d7ba335706a8a6cfeac 100644 (file)
@@ -70,12 +70,14 @@ ngx_module_t  ngx_core_module = {
 };
 
 
-ngx_int_t  ngx_max_module;
+ngx_int_t   ngx_max_module;
 
-ngx_int_t  ngx_process;
-ngx_pid_t  ngx_pid;
-ngx_pid_t  ngx_new_binary;
-ngx_int_t  ngx_inherited;
+ngx_int_t   ngx_process;
+ngx_pid_t   ngx_pid;
+ngx_pid_t   ngx_new_binary;
+ngx_int_t   ngx_inherited;
+
+ngx_uint_t  ngx_test_config;
 
 
 int main(int argc, char *const *argv)
@@ -125,11 +127,6 @@ int main(int argc, char *const *argv)
         return 1;
     }
 
-    ngx_max_module = 0;
-    for (i = 0; ngx_modules[i]; i++) {
-        ngx_modules[i]->index = ngx_max_module++;
-    }
-
     if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
         return 1;
     }
@@ -138,11 +135,20 @@ int main(int argc, char *const *argv)
         return 1;
     }
 
+    ngx_max_module = 0;
+    for (i = 0; ngx_modules[i]; i++) {
+        ngx_modules[i]->index = ngx_max_module++;
+    }
+
     cycle = ngx_init_cycle(&init_cycle);
     if (cycle == NULL) {
         return 1;
     }
 
+    if (ngx_test_config) {
+        return 0;
+    }
+
     ngx_cycle = cycle;
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
@@ -276,6 +282,10 @@ static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle)
 
         switch (ctx->argv[i][1]) {
 
+        case 't':
+            ngx_test_config = 1;
+            break;
+
         case 'c':
             if (ctx->argv[i + 1] == NULL) {
                 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
index 8dedbd10e299fe4af469135f20d836570859a1f0..6382ec10c60e9e124babfe2c982179fab07e9868 100644 (file)
@@ -228,7 +228,17 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
         fd /= 4;
 #endif
 
-        ngx_del_event(&cycle->read_events[fd], NGX_READ_EVENT, NGX_CLOSE_EVENT);
+        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+            if (cycle->connections[fd].read->active) {
+                ngx_del_conn(&cycle->connections[fd], NGX_CLOSE_EVENT);
+            }
+
+        } else {
+            if (cycle->read_events[fd].active) {
+                ngx_del_event(&cycle->read_events[fd],
+                              NGX_READ_EVENT, NGX_CLOSE_EVENT);
+            }
+        }
 
         if (ngx_close_socket(ls[i].fd) == -1) {
             ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
index 077b12092fd5ac55737d501720b55a87e7206739..71a0b008028294d93f6a94058930c1e74e30e48e 100644 (file)
@@ -23,7 +23,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
 {
     void               *rv;
     ngx_uint_t          i, n, failed;
-    ngx_log_t          *log, *new_log;
+    ngx_log_t          *log;
     ngx_conf_t          conf;
     ngx_pool_t         *pool;
     ngx_cycle_t        *cycle, **old;
@@ -37,16 +37,14 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
     if (!(pool = ngx_create_pool(16 * 1024, log))) {
         return NULL;
     }
+    pool->log = log;
 
     if (!(cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t)))) {
         ngx_destroy_pool(pool);
         return NULL;
     }
     cycle->pool = pool;
-
-    pool->log = log;
     cycle->log = log;
-
     cycle->old_cycle = old_cycle;
     cycle->conf_file = old_cycle->conf_file;
 
@@ -74,7 +72,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
     cycle->open_files.pool = pool;
 
 
-    if (!(new_log = ngx_log_create_errlog(cycle, NULL))) {
+    if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
         ngx_destroy_pool(pool);
         return NULL;
     }
@@ -127,19 +125,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
 
     conf.ctx = cycle->conf_ctx;
     conf.cycle = cycle;
-    /* STUB */ conf.pool = cycle->pool;
+    conf.pool = pool;
     conf.log = log;
     conf.module_type = NGX_CORE_MODULE;
     conf.cmd_type = NGX_MAIN_CONF;
 
-    cycle->log = new_log;
 
     if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
         ngx_destroy_pool(pool);
         return NULL;
     }
 
-    cycle->log = log;
 
     for (i = 0; ngx_modules[i]; i++) {
         if (ngx_modules[i]->type != NGX_CORE_MODULE) {
@@ -208,8 +204,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
         }
     }
 
-    cycle->log = new_log;
-    pool->log = new_log;
+    cycle->log = cycle->new_log;
+    pool->log = cycle->new_log;
 
     if (!failed) {
         if (old_cycle->listening.nelts) {
index 1fac10e38fd8c64b08e57f22ce6592fb9cada267..3cecbc53e1bc3fff2a7d2b1b47d792762dda71ac 100644 (file)
@@ -9,7 +9,10 @@
 struct ngx_cycle_s {
     void           ****conf_ctx;
     ngx_pool_t        *pool;
+
     ngx_log_t         *log;
+    ngx_log_t         *new_log;
+
     ngx_array_t        listening;
     ngx_array_t        open_files;
     ngx_array_t        pathes;
index ace7f33e11a268c829e2f67979535839600d9ba5..531c8608097a2c47daff8ee581ee0721cf63e7e0 100644 (file)
@@ -311,23 +311,6 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
 }
 
 
-static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
-    ngx_str_t  *value;
-
-    value = cf->args->elts;
-
-    if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
-        cf->cycle->log->file = &ngx_stderr;
-
-    } else {
-        cf->cycle->log->file->name = value[1];
-    }
-
-    return ngx_set_error_log_levels(cf, cf->cycle->log);
-}
-
-
 char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
 {
     ngx_uint_t   i, n, d;
@@ -379,3 +362,20 @@ char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
 
     return NGX_CONF_OK;
 }
+
+
+static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_str_t  *value;
+
+    value = cf->args->elts;
+
+    if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
+        cf->cycle->new_log->file = &ngx_stderr;
+
+    } else {
+        cf->cycle->new_log->file->name = value[1];
+    }
+
+    return ngx_set_error_log_levels(cf, cf->cycle->new_log);
+}
index 6007c0d98a3b8a63e68f60bdbd73b51c91100eb2..204bcae2121f132eb9822cf4c80c69f4049d83c7 100644 (file)
@@ -333,7 +333,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                        "devpoll expired timer");
 
-        ngx_event_expire_timers(0);
+        ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
     }
 
     /* NGX_TIMER_INFINITE == INFTIM */
index f5bd6e5ba7b0858d1fb823477b2291ea5db5a825..bc4f7c3b87776b7c5c79824cafa67846cb79be3a 100644 (file)
@@ -363,7 +363,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                        "epoll expired timer");
 
-        ngx_event_expire_timers(0);
+        ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
     }
 
     /* NGX_TIMER_INFINITE == INFTIM */
index 33dd71296c24629eca1a28ac068da3e1f657d4f8..acd92f29a0d48f796bd42a400cc5d3e2cebcd5b5 100644 (file)
@@ -376,7 +376,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                        "kevent expired timer");
 
-        ngx_event_expire_timers(0);
+        ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
 
         /* TODO: if ngx_threaded then wake up the worker thread */
     }
index 968180dbb435b6aa7a0278e9b1b1a90d3541e22d..5d4d91f112b26c27883018561c3b35a24d44a831 100644 (file)
@@ -287,7 +287,7 @@ int ngx_poll_process_events(ngx_cycle_t *cycle)
             ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                            "poll expired timer");
 
-            ngx_event_expire_timers(0);
+            ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
         }
 
         /* NGX_TIMER_INFINITE == INFTIM */
index b55f84c47100b789015d40b7c681800f1430a00c..172608878dfd16bea71b14cd019343bac0f10a2b 100644 (file)
@@ -214,7 +214,7 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                        "rtsig expired timer");
 
-        ngx_event_expire_timers(0);
+        ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
     }
 
     expire = 1;
index 91563f2751fa49b94ecc8e18768ce3a7632388aa..85f3fcee5406b962d1c737d3b5a10163b838fc4a 100644 (file)
@@ -273,7 +273,7 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                        "select expired timer");
 
-        ngx_event_expire_timers(0);
+        ngx_event_expire_timers(ngx_elapsed_msec - ngx_old_elapsed_msec);
     }
 
     ngx_old_elapsed_msec = ngx_elapsed_msec;
index d7cbf960843e242907aac8c4161450233034ee01..027dc3cccb0382c5f804f475c4613efd0944f810 100644 (file)
@@ -428,18 +428,22 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev)
 
     err = ngx_socket_errno;
 
+    /*
+     * we do not need to disable the write event because
+     * that event has NGX_USE_CLEAR_EVENT type
+     */
+
     if (ev->write && (n >= 0 || err == NGX_EAGAIN)) {
         return;
     }
 
-    if (n > 0) {
-        if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
-            if (ngx_del_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
-                ngx_http_proxy_finalize_request(p,
-                                                NGX_HTTP_INTERNAL_SERVER_ERROR);
-            }
+    if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
+        if (ngx_del_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
+            ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         }
+    }
 
+    if (n > 0) {
         return;
     }
 
index 61cf0d54f18aaa83624678077124b31003f30ea3..7240adc57b1538c3362aa7f0d1a878bd473bbafa 100644 (file)
@@ -6,6 +6,7 @@
 #include <nginx.h>
 
 
+static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
 #if (NGX_THREADS)
@@ -15,21 +16,253 @@ static int ngx_worker_thread_cycle(void *data);
 
 ngx_int_t     ngx_process;
 ngx_pid_t     ngx_pid;
-ngx_pid_t     ngx_new_binary;
-ngx_int_t     ngx_inherited;
 ngx_int_t     ngx_threaded;
 
 sig_atomic_t  ngx_reap;
 sig_atomic_t  ngx_timer;
 sig_atomic_t  ngx_terminate;
 sig_atomic_t  ngx_quit;
-sig_atomic_t  ngx_noaccept;
 sig_atomic_t  ngx_reconfigure;
 sig_atomic_t  ngx_reopen;
+
 sig_atomic_t  ngx_change_binary;
+ngx_pid_t     ngx_new_binary;
+ngx_int_t     ngx_inherited;
 
+sig_atomic_t  ngx_noaccept;
+ngx_uint_t    ngx_noaccepting;
+ngx_uint_t    ngx_restart;
+
+
+void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
+{
+    int                signo;
+    sigset_t           set;
+    struct timeval     tv;
+    struct itimerval   itv;
+    ngx_uint_t         i, live;
+    ngx_msec_t         delay;
+    ngx_core_conf_t   *ccf;
+
+    sigemptyset(&set);
+    sigaddset(&set, SIGCHLD);
+    sigaddset(&set, SIGALRM);
+    sigaddset(&set, SIGINT);
+    sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
+    sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
+    sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL));
+    sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL));
+    sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
+    sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
+
+    if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "sigprocmask() failed");
+    }
+
+    sigemptyset(&set);
+
+    ngx_setproctitle("master process");
+
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+    ngx_start_worker_processes(ccf->worker_processes);
+
+    ngx_new_binary = 0;
+    delay = 0;
+    signo = 0;
+    live = 1;
+
+    for ( ;; ) {
+        if (delay) {
+            delay *= 2;
+
+            ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+                           "temination cycle: %d", delay);
+
+            itv.it_interval.tv_sec = 0;
+            itv.it_interval.tv_usec = 0;
+            itv.it_value.tv_sec = delay / 1000;
+            itv.it_value.tv_usec = (delay % 1000 ) * 1000;
+
+            if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                              "setitimer() failed");
+            }
+        }
+
+        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend");
+
+        sigsuspend(&set);
+
+        ngx_gettimeofday(&tv);
+        ngx_time_update(tv.tv_sec);
+
+        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up");
+
+        if (ngx_reap) {
+            ngx_reap = 0;
+            ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap childs");
+
+            live = 0;
+            for (i = 0; i < ngx_last_process; i++) {
+
+                ngx_log_debug5(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+                               "child: " PID_T_FMT " e:%d t:%d d:%d r:%d",
+                               ngx_processes[i].pid,
+                               ngx_processes[i].exiting,
+                               ngx_processes[i].exited,
+                               ngx_processes[i].detached,
+                               ngx_processes[i].respawn);
+
+                if (ngx_processes[i].exited) {
+
+                    if (ngx_processes[i].respawn
+                        && !ngx_processes[i].exiting
+                        && !ngx_terminate
+                        && !ngx_quit)
+                    {
+                         if (ngx_spawn_process(cycle, ngx_processes[i].proc,
+                                               ngx_processes[i].data,
+                                               ngx_processes[i].name, i)
+                                                                  == NGX_ERROR)
+                         {
+                             ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+                                           "can not respawn %s",
+                                           ngx_processes[i].name);
+                             continue;
+                         }
+
+                         live = 1;
+
+                         continue;
+                    }
+
+                    if (ngx_processes[i].pid == ngx_new_binary) {
+                        ngx_new_binary = 0;
+                        if (ngx_noaccepting) {
+                            ngx_restart = 1;
+                            ngx_noaccepting = 0;
+                        }
+                    }
+
+                    if (i != --ngx_last_process) {
+                        ngx_processes[i--] = ngx_processes[ngx_last_process];
+                    }
+
+                } else if (ngx_processes[i].exiting
+                           || !ngx_processes[i].detached)
+                {
+                    live = 1;
+                }
+            }
+        }
+
+        if (!live && (ngx_terminate || ngx_quit)) {
+            ngx_master_exit(cycle, ctx);
+        }
+
+        if (ngx_terminate) {
+            if (delay == 0) {
+                delay = 50;
+            }
+
+            if (delay > 1000) {
+                signo = SIGKILL;
+            } else {
+                signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
+            }
+
+        } else if (ngx_quit) {
+            signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+
+        } else if (ngx_timer) {
+            ngx_start_worker_processes(ccf->worker_processes);
+            signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+
+        } else if (ngx_reconfigure) {
+            ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring");
+
+            cycle = ngx_init_cycle(cycle);
+            if (cycle == NULL) {
+                cycle = (ngx_cycle_t *) ngx_cycle;
+                continue;
+            }
+
+            ngx_cycle = cycle;
+            ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
+                                                   ngx_core_module);
+            ngx_start_worker_processes(ccf->worker_processes);
+
+            ngx_reconfigure = 0;
+            signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+
+        } else if (ngx_restart) {
+            ngx_start_worker_processes(ccf->worker_processes);
+            ngx_restart = 0;
+
+        } else if (ngx_reopen) {
+                if (ngx_process == NGX_PROCESS_MASTER) {
+                    signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
+                    ngx_reopen = 0;
+
+                } else { /* NGX_PROCESS_SINGLE */
+                    ngx_reopen = 0;
+                }
+
+                ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+                              "reopening logs");
+                ngx_reopen_files(cycle, ccf->user);
+
+        } else if (ngx_change_binary) {
+                ngx_change_binary = 0;
+                ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+                              "changing binary");
+                ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
+
+            } else if (ngx_noaccept) {
+                signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+            }
+        }
+
+        if (signo) {
+            for (i = 0; i < ngx_last_process; i++) {
+
+                if (ngx_processes[i].detached) {
+                    continue;
+                }
+
+                ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
+                               "kill (" PID_T_FMT ", %d)" ,
+                               ngx_processes[i].pid, signo);
+
+                if (kill(ngx_processes[i].pid, signo) == -1) {
+                    ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                                  "kill(%d, %d) failed",
+                                  ngx_processes[i].pid, signo);
+                    continue;
+                }
+
+                if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
+                    ngx_processes[i].exiting = 1;
+                }
+            }
+
+            signo = 0;
+        }
+
+
+
+
+
+
+
+
+
+
+    }
+}
 
-/* TODO: broken NGX_PROCESS_SINGLE */
 
 void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 {
@@ -238,26 +471,20 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
                 } else if (ngx_timer) {
                     signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
 
-                } else {
+                } else if (ngx_reconfigure) {
+                    ngx_reconfigure = 0;
+                    ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring");
 
-                    if (ngx_noaccept) {
-                        signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
+                    cycle = ngx_init_cycle(cycle);
+                    if (cycle == NULL) {
+                        cycle = (ngx_cycle_t *) ngx_cycle;
+                        continue;
                     }
 
-                    if (ngx_change_binary) {
-                        ngx_change_binary = 0;
-                        ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
-                                      "changing binary");
-                        ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
-                    }
-
-                    if (ngx_reconfigure) {
-                        signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
-                        ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
-                                      "reconfiguring");
-                    }
+                    ngx_cycle = cycle;
+                    signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
 
-                    if (ngx_reopen) {
+                } else if (ngx_reopen) {
                         if (ngx_process == NGX_PROCESS_MASTER) {
                             signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
                             ngx_reopen = 0;
@@ -269,6 +496,15 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
                         ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
                                       "reopening logs");
                         ngx_reopen_files(cycle, ccf->user);
+
+                } else if (ngx_change_binary) {
+                        ngx_change_binary = 0;
+                        ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+                                      "changing binary");
+                        ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
+
+                    } else if (ngx_noaccept) {
+                        signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
                     }
                 }
 
@@ -330,6 +566,35 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 }
 
 
+static void ngx_start_worker_processes(ngx_cycle_y *cycle, ngx_int_t n)
+{
+    struct itimerval  itv;
+
+    ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start worker processes");
+
+    while (n--) {
+        ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
+                          "worker process", NGX_PROCESS_RESPAWN);
+    }
+
+    /*
+     * we have to limit the maximum life time of the worker processes
+     * by 10 days because our millisecond event timer is limited
+     * by 24 days on 32-bit platforms
+     */
+
+    itv.it_interval.tv_sec = 0;
+    itv.it_interval.tv_usec = 0;
+    itv.it_value.tv_sec = 10 * 24 * 60 * 60;
+    itv.it_value.tv_usec = 0;
+
+    if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "setitimer() failed");
+    }
+}
+
+
 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
 {
     ngx_delete_pidfile(cycle);