comparison src/os/unix/ngx_process.c @ 7162:8b84d60ef13d

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.
author Ruslan Ermilov <ru@nginx.com>
date Tue, 28 Nov 2017 12:00:24 +0300
parents f38647c651a8
children
comparison
equal deleted inserted replaced
7161:325b3042edd6 7162:8b84d60ef13d
192 "fork() failed while spawning \"%s\"", name); 192 "fork() failed while spawning \"%s\"", name);
193 ngx_close_channel(ngx_processes[s].channel, cycle->log); 193 ngx_close_channel(ngx_processes[s].channel, cycle->log);
194 return NGX_INVALID_PID; 194 return NGX_INVALID_PID;
195 195
196 case 0: 196 case 0:
197 ngx_parent = ngx_pid;
197 ngx_pid = ngx_getpid(); 198 ngx_pid = ngx_getpid();
198 proc(cycle, data); 199 proc(cycle, data);
199 break; 200 break;
200 201
201 default: 202 default:
369 ngx_reopen = 1; 370 ngx_reopen = 1;
370 action = ", reopening logs"; 371 action = ", reopening logs";
371 break; 372 break;
372 373
373 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): 374 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL):
374 if (getppid() > 1 || ngx_new_binary > 0) { 375 if (ngx_getppid() == ngx_parent || ngx_new_binary > 0) {
375 376
376 /* 377 /*
377 * Ignore the signal in the new binary if its parent is 378 * Ignore the signal in the new binary if its parent is
378 * not the init process, i.e. the old binary's process 379 * not changed, i.e. the old binary's process is still
379 * is still running. Or ignore the signal in the old binary's 380 * running. Or ignore the signal in the old binary's
380 * process if the new binary's process is already running. 381 * process if the new binary's process is already running.
381 */ 382 */
382 383
383 action = ", ignoring"; 384 action = ", ignoring";
384 ignore = 1; 385 ignore = 1;