Klaus Demo nginx / afad219
Fixed "changing binary" when reaper is not init. 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. Ruslan Ermilov 4 years ago
7 changed file(s) with 12 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
227227 #endif
228228
229229 ngx_pid = ngx_getpid();
230 ngx_parent = ngx_getppid();
230231
231232 log = ngx_log_init(ngx_prefix);
232233 if (log == NULL) {
2525 exit(0);
2626 }
2727
28 ngx_parent = ngx_pid;
2829 ngx_pid = ngx_getpid();
2930
3031 if (setsid() == -1) {
193193 return NGX_INVALID_PID;
194194
195195 case 0:
196 ngx_parent = ngx_pid;
196197 ngx_pid = ngx_getpid();
197198 proc(cycle, data);
198199 break;
370371 break;
371372
372373 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL):
373 if (getppid() > 1 || ngx_new_binary > 0) {
374 if (ngx_getppid() == ngx_parent || ngx_new_binary > 0) {
374375
375376 /*
376377 * Ignore the signal in the new binary if its parent is
377 * not the init process, i.e. the old binary's process
378 * is still running. Or ignore the signal in the old binary's
378 * not changed, i.e. the old binary's process is still
379 * running. Or ignore the signal in the old binary's
379380 * process if the new binary's process is already running.
380381 */
381382
5353
5454
5555 #define ngx_getpid getpid
56 #define ngx_getppid getppid
5657
5758 #ifndef ngx_log_pid
5859 #define ngx_log_pid ngx_pid
7879 extern char **ngx_os_argv;
7980
8081 extern ngx_pid_t ngx_pid;
82 extern ngx_pid_t ngx_parent;
8183 extern ngx_socket_t ngx_channel;
8284 extern ngx_int_t ngx_process_slot;
8385 extern ngx_int_t ngx_last_process;
3030 ngx_uint_t ngx_process;
3131 ngx_uint_t ngx_worker;
3232 ngx_pid_t ngx_pid;
33 ngx_pid_t ngx_parent;
3334
3435 sig_atomic_t ngx_reap;
3536 sig_atomic_t ngx_sigio;
1313
1414
1515 #define ngx_getpid GetCurrentProcessId
16 #define ngx_getppid() 0
1617 #define ngx_log_pid ngx_pid
1718
1819
7273 extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
7374
7475 extern ngx_pid_t ngx_pid;
76 extern ngx_pid_t ngx_parent;
7577
7678
7779 #endif /* _NGX_PROCESS_H_INCLUDED_ */
3030 ngx_uint_t ngx_process;
3131 ngx_uint_t ngx_worker;
3232 ngx_pid_t ngx_pid;
33 ngx_pid_t ngx_parent;
3334
3435 ngx_uint_t ngx_inherited;
3536 ngx_pid_t ngx_new_binary;