]> git.kaiwu.me - nginx.git/commitdiff
Fixed "changing binary" when reaper is not init.
authorRuslan Ermilov <ru@nginx.com>
Tue, 28 Nov 2017 09:00:24 +0000 (12:00 +0300)
committerRuslan Ermilov <ru@nginx.com>
Tue, 28 Nov 2017 09:00:24 +0000 (12:00 +0300)
On some systems, it's possible that reaper of orphaned processes is
set to something other than "init" process.  On such systems, the
changing binary procedure did not work.

The fix is to check if PPID has changed, instead of assuming it's
always 1 for orphaned processes.

src/core/nginx.c
src/os/unix/ngx_daemon.c
src/os/unix/ngx_process.c
src/os/unix/ngx_process.h
src/os/unix/ngx_process_cycle.c
src/os/win32/ngx_process.h
src/os/win32/ngx_process_cycle.c

index c3a29cc40d86a663bd4a6cb7cd8299a7f8cf3d18..3894c29fafb9975de6af9590e10f7f789a13fdc0 100644 (file)
@@ -228,6 +228,7 @@ main(int argc, char *const *argv)
 #endif
 
     ngx_pid = ngx_getpid();
+    ngx_parent = ngx_getppid();
 
     log = ngx_log_init(ngx_prefix);
     if (log == NULL) {
index ab672110838cee75e3081daab35b3e16164648db..385c49b6c3d1a8877b9d95ba44d428203b895ab0 100644 (file)
@@ -26,6 +26,7 @@ ngx_daemon(ngx_log_t *log)
         exit(0);
     }
 
+    ngx_parent = ngx_pid;
     ngx_pid = ngx_getpid();
 
     if (setsid() == -1) {
index 993c032ae1961103662962b5acb358d87008df96..15680237a6ba8339fcdbf5092ef282e4d32b7d9c 100644 (file)
@@ -194,6 +194,7 @@ ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data,
         return NGX_INVALID_PID;
 
     case 0:
+        ngx_parent = ngx_pid;
         ngx_pid = ngx_getpid();
         proc(cycle, data);
         break;
@@ -371,12 +372,12 @@ ngx_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
             break;
 
         case ngx_signal_value(NGX_CHANGEBIN_SIGNAL):
-            if (getppid() > 1 || ngx_new_binary > 0) {
+            if (ngx_getppid() == ngx_parent || ngx_new_binary > 0) {
 
                 /*
                  * Ignore the signal in the new binary if its parent is
-                 * not the init process, i.e. the old binary's process
-                 * is still running.  Or ignore the signal in the old binary's
+                 * not changed, i.e. the old binary's process is still
+                 * running.  Or ignore the signal in the old binary's
                  * process if the new binary's process is already running.
                  */
 
index 7b5e8c0c25ef722d4f6dff3356a2d82a04f0ac7e..3986639b47e63dc7d3d515ba6ea3f6751d605acf 100644 (file)
@@ -54,6 +54,7 @@ typedef struct {
 
 
 #define ngx_getpid   getpid
+#define ngx_getppid  getppid
 
 #ifndef ngx_log_pid
 #define ngx_log_pid  ngx_pid
@@ -79,6 +80,7 @@ extern char         **ngx_argv;
 extern char         **ngx_os_argv;
 
 extern ngx_pid_t      ngx_pid;
+extern ngx_pid_t      ngx_parent;
 extern ngx_socket_t   ngx_channel;
 extern ngx_int_t      ngx_process_slot;
 extern ngx_int_t      ngx_last_process;
index 1710ea81201daf3ceb51d60952997a4f8e4a20df..a20a515c76b45b1d8e914d41f2ca85cdd7a7ca3d 100644 (file)
@@ -31,6 +31,7 @@ static void ngx_cache_loader_process_handler(ngx_event_t *ev);
 ngx_uint_t    ngx_process;
 ngx_uint_t    ngx_worker;
 ngx_pid_t     ngx_pid;
+ngx_pid_t     ngx_parent;
 
 sig_atomic_t  ngx_reap;
 sig_atomic_t  ngx_sigio;
index a6a5aa29fc882af62d23a30ee6e5fd9bd0f4d3bd..7ec4cd92cecaf43561a39191e257a046f00d5dff 100644 (file)
@@ -14,6 +14,7 @@ typedef DWORD               ngx_pid_t;
 
 
 #define ngx_getpid          GetCurrentProcessId
+#define ngx_getppid()       0
 #define ngx_log_pid         ngx_pid
 
 
@@ -73,6 +74,7 @@ extern ngx_int_t            ngx_last_process;
 extern ngx_process_t        ngx_processes[NGX_MAX_PROCESSES];
 
 extern ngx_pid_t            ngx_pid;
+extern ngx_pid_t            ngx_parent;
 
 
 #endif /* _NGX_PROCESS_H_INCLUDED_ */
index 293b967ec457b4ff3382b3124a818359092c56c2..3aea874e01bd4c1fbb1d7024570163f44bf72856 100644 (file)
@@ -31,6 +31,7 @@ static ngx_thread_value_t __stdcall ngx_cache_loader_thread(void *data);
 ngx_uint_t     ngx_process;
 ngx_uint_t     ngx_worker;
 ngx_pid_t      ngx_pid;
+ngx_pid_t      ngx_parent;
 
 ngx_uint_t     ngx_inherited;
 ngx_pid_t      ngx_new_binary;