nginx-0.2.0-RELEASE import

    *) 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.
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 10db555..09edae5 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -42,6 +42,13 @@
       offsetof(ngx_core_conf_t, master),
       NULL },
 
+    { ngx_string("pid"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_str_slot,
+      0,
+      offsetof(ngx_core_conf_t, pid),
+      NULL },
+
     { ngx_string("worker_processes"),
       NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_num_slot,
@@ -56,6 +63,41 @@
       offsetof(ngx_core_conf_t, debug_points),
       &ngx_debug_points },
 
+    { ngx_string("user"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
+      ngx_set_user,
+      0,
+      0,
+      NULL },
+
+    { ngx_string("worker_priority"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_set_priority,
+      0,
+      0,
+      NULL },
+
+    { ngx_string("worker_rlimit_nofile"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_num_slot,
+      0,
+      offsetof(ngx_core_conf_t, rlimit_nofile),
+      NULL },
+
+    { ngx_string("worker_rlimit_sigpending"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_num_slot,
+      0,
+      offsetof(ngx_core_conf_t, rlimit_sigpending),
+      NULL },
+
+    { ngx_string("working_directory"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_str_slot,
+      0,
+      offsetof(ngx_core_conf_t, working_directory),
+      NULL },
+
 #if (NGX_THREADS)
 
     { ngx_string("worker_threads"),
@@ -74,34 +116,6 @@
 
 #endif
 
-    { ngx_string("user"),
-      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
-      ngx_set_user,
-      0,
-      0,
-      NULL },
-
-    { ngx_string("worker_priority"),
-      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
-      ngx_set_priority,
-      0,
-      0,
-      NULL },
-
-    { ngx_string("pid"),
-      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_str_slot,
-      0,
-      offsetof(ngx_core_conf_t, pid),
-      NULL },
-
-    { ngx_string("working_directory"),
-      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_str_slot,
-      0,
-      offsetof(ngx_core_conf_t, working_directory),
-      NULL },
-
       ngx_null_command
 };
 
@@ -324,13 +338,15 @@
 }
 
 
-ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
+ngx_pid_t
+ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
 {
     char             *env[3], *var;
     u_char           *p;
     ngx_uint_t        i;
     ngx_pid_t         pid;
     ngx_exec_ctx_t    ctx;
+    ngx_core_conf_t  *ccf;
     ngx_listening_t  *ls;
 
     ctx.path = argv[0];
@@ -374,15 +390,42 @@
 
     ctx.envp = (char *const *) &env;
 
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+    if (ngx_rename_file((char *) ccf->pid.data, (char *) ccf->oldpid.data)
+        != NGX_OK)
+    {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      ngx_rename_file_n " %s to %s failed "
+                      "before executing new binary process \"%s\"",
+                      ccf->pid.data, ccf->oldpid.data, argv[0]);
+
+        ngx_free(var);
+
+        return NGX_INVALID_PID;
+    }
+
     pid = ngx_execute(cycle, &ctx);
 
+    if (pid == NGX_INVALID_PID) {
+        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 try to executing new binary process \"%s\"",
+                          ccf->oldpid.data, ccf->pid.data, argv[0]);
+        }
+    }
+
     ngx_free(var);
 
     return pid;
 }
 
 
-static ngx_int_t ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv)
+static ngx_int_t
+ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv)
 {
     ngx_int_t  i;
 
@@ -485,7 +528,7 @@
      * set by pcalloc()
      *
      *     ccf->pid = NULL;
-     *     ccf->newpid = NULL;
+     *     ccf->oldpid = NULL;
      *     ccf->priority = 0;
      */
 
@@ -493,8 +536,13 @@
     ccf->master = NGX_CONF_UNSET;
     ccf->worker_processes = NGX_CONF_UNSET;
     ccf->debug_points = NGX_CONF_UNSET;
+
+    ccf->rlimit_nofile = NGX_CONF_UNSET;
+    ccf->rlimit_sigpending = NGX_CONF_UNSET;
+
     ccf->user = (ngx_uid_t) NGX_CONF_UNSET_UINT;
     ccf->group = (ngx_gid_t) NGX_CONF_UNSET_UINT;
+
 #if (NGX_THREADS)
     ccf->worker_threads = NGX_CONF_UNSET;
     ccf->thread_stack_size = NGX_CONF_UNSET_SIZE;
@@ -558,15 +606,15 @@
         return NGX_CONF_ERROR;
     }
 
-    ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
+    ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT);
 
-    ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len);
-    if (ccf->newpid.data == NULL) {
+    ccf->oldpid.data = ngx_palloc(cycle->pool, ccf->oldpid.len);
+    if (ccf->oldpid.data == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
-               NGX_NEWPID_EXT, sizeof(NGX_NEWPID_EXT));
+    ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len),
+               NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT));
 
 #endif