diff src/os/unix/ngx_process_cycle.c @ 92:45945fa8b8ba NGINX_0_2_0

nginx 0.2.0 *) The pid-file names used during online upgrade was changed and now is not required a manual rename operation. The old master process adds the ".oldbin" suffix to its pid-file and executes a new binary file. The new master process creates usual pid-file without the ".newbin" suffix. If the master process exits, then old master process renames back its pid-file with the ".oldbin" suffix to the pid-file without suffix. *) Change: the "worker_connections" directive, new name of the "connections" directive; now the directive specifies maximum number of connections, but not maximum socket descriptor number. *) Feature: SSL supports the session cache inside one worker process. *) Feature: the "satisfy_any" directive. *) Change: the ngx_http_access_module and ngx_http_auth_basic_module do not run for subrequests. *) Feature: the "worker_rlimit_nofile" and "worker_rlimit_sigpending" directives. *) Bugfix: if all backend using in load-balancing failed after one error, then nginx did not try do connect to them during 60 seconds. *) Bugfix: in IMAP/POP3 command argument parsing. Thanks to Rob Mueller. *) Bugfix: errors while using SSL in IMAP/POP3 proxy. *) Bugfix: errors while using SSI and gzipping. *) Bugfix: the "Expires" and "Cache-Control" header lines were omitted from the 304 responses. Thanks to Alexandr Kukushkin.
author Igor Sysoev <http://sysoev.ru>
date Fri, 23 Sep 2005 00:00:00 +0400
parents 991c6e4c7654
children 45f7329b4bd0
line wrap: on
line diff
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -513,9 +513,10 @@ ngx_signal_worker_processes(ngx_cycle_t 
 static ngx_uint_t
 ngx_reap_childs(ngx_cycle_t *cycle)
 {
-    ngx_int_t      i, n;
-    ngx_uint_t     live;
-    ngx_channel_t  ch;
+    ngx_int_t         i, n;
+    ngx_uint_t        live;
+    ngx_channel_t     ch;
+    ngx_core_conf_t  *ccf;
 
     ch.command = NGX_CMD_CLOSE_CHANNEL;
     ch.fd = -1;
@@ -575,7 +576,7 @@ ngx_reap_childs(ngx_cycle_t *cycle)
                 if (ngx_spawn_process(cycle, ngx_processes[i].proc,
                                       ngx_processes[i].data,
                                       ngx_processes[i].name, i)
-                                                                  == NGX_ERROR)
+                    == NGX_INVALID_PID)
                 {
                     ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
                                   "can not respawn %s", ngx_processes[i].name);
@@ -615,6 +616,20 @@ ngx_reap_childs(ngx_cycle_t *cycle)
             }
 
             if (ngx_processes[i].pid == ngx_new_binary) {
+
+                ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
+                                                       ngx_core_module);
+
+                if (ngx_rename_file((char *) ccf->oldpid.data,
+                                    (char *) ccf->pid.data)
+                    != NGX_OK)
+                {
+                    ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                                  ngx_rename_file_n " %s back to %s failed "
+                                  "after the new binary process \"%s\" exited",
+                                  ccf->oldpid.data, ccf->pid.data, ngx_argv[0]);
+                }
+
                 ngx_new_binary = 0;
                 if (ngx_noaccepting) {
                     ngx_restart = 1;
@@ -795,6 +810,7 @@ ngx_worker_process_init(ngx_cycle_t *cyc
     sigset_t           set;
     ngx_int_t          n;
     ngx_uint_t         i;
+    struct rlimit      rlmt;
     struct timeval     tv;
     ngx_core_conf_t   *ccf;
     ngx_listening_t   *ls;
@@ -818,6 +834,30 @@ ngx_worker_process_init(ngx_cycle_t *cyc
             }
         }
 
+        if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
+            rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
+            rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
+
+            if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
+                ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                              "setrlimit(RLIMIT_NOFILE, %i) failed",
+                              ccf->rlimit_nofile);
+            }
+        }
+
+#ifdef RLIMIT_SIGPENDING
+        if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
+            rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
+            rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
+
+            if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
+                ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                              "setrlimit(RLIMIT_SIGPENDING, %i) failed",
+                              ccf->rlimit_sigpending);
+            }
+        }
+#endif
+
         if (setgid(ccf->group) == -1) {
             ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
                           "setgid(%d) failed", ccf->group);
@@ -874,7 +914,7 @@ ngx_worker_process_init(ngx_cycle_t *cyc
      */ 
     ls = cycle->listening.elts;
     for (i = 0; i < cycle->listening.nelts; i++) {
-        ls[i].remain = 0;
+        ls[i].previous = NULL;
     }
 
     for (i = 0; ngx_modules[i]; i++) {
@@ -928,6 +968,7 @@ static void
 ngx_channel_handler(ngx_event_t *ev)
 {
     ngx_int_t          n;
+    ngx_socket_t       fd;
     ngx_channel_t      ch;
     ngx_connection_t  *c;
 
@@ -945,12 +986,17 @@ ngx_channel_handler(ngx_event_t *ev)
     ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
 
     if (n == NGX_ERROR) {
-        if (close(c->fd) == -1) {
+
+        ngx_free_connection(c);
+
+        fd = c->fd;
+        c->fd = (ngx_socket_t) -1;
+
+        if (close(fd) == -1) {
             ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                           "close() channel failed");
         }
 
-        c->fd = -1;
         return;
     }
 
@@ -1144,7 +1190,7 @@ ngx_garbage_collector_cycle(ngx_cycle_t 
 
     ngx_worker_process_init(cycle, 0);
 
-    ev = &cycle->read_events[ngx_channel];
+    ev = &cycle->read_events0[ngx_channel];
 
     ngx_accept_mutex = NULL;