18 void (*handler)(
int signo);
23 static void ngx_execute_proc(
ngx_cycle_t *cycle,
void *data);
24 static void ngx_signal_handler(
int signo);
25 static void ngx_process_get_status(
void);
26 static void ngx_unlock_mutexes(
ngx_pid_t pid);
70 { SIGALRM,
"SIGALRM",
"", ngx_signal_handler },
72 { SIGINT,
"SIGINT",
"", ngx_signal_handler },
74 { SIGIO,
"SIGIO",
"", ngx_signal_handler },
76 { SIGCHLD,
"SIGCHLD",
"", ngx_signal_handler },
78 { SIGSYS,
"SIGSYS, SIG_IGN",
"", SIG_IGN },
80 { SIGPIPE,
"SIGPIPE, SIG_IGN",
"", SIG_IGN },
99 if (ngx_processes[s].pid == -1) {
106 "no more than %d processes can be spawned",
117 if (socketpair(AF_UNIX, SOCK_STREAM, 0, ngx_processes[s].channel) == -1)
120 "socketpair() failed while spawning \"%s\"", name);
146 if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) {
148 "ioctl(FIOASYNC) failed while spawning \"%s\"", name);
153 if (fcntl(ngx_processes[s].channel[0], F_SETOWN,
ngx_pid) == -1) {
155 "fcntl(F_SETOWN) failed while spawning \"%s\"", name);
160 if (fcntl(ngx_processes[s].channel[0], F_SETFD, FD_CLOEXEC) == -1) {
162 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"",
168 if (fcntl(ngx_processes[s].channel[1], F_SETFD, FD_CLOEXEC) == -1) {
170 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"",
179 ngx_processes[s].
channel[0] = -1;
180 ngx_processes[s].
channel[1] = -1;
192 "fork() failed while spawning \"%s\"", name);
207 ngx_processes[s].
pid = pid;
208 ngx_processes[s].
exited = 0;
214 ngx_processes[s].
proc = proc;
215 ngx_processes[s].
data = data;
216 ngx_processes[s].
name = name;
275 "execve() failed while executing %s \"%s\"",
289 for (sig = signals; sig->
signo != 0; sig++) {
292 sigemptyset(&sa.sa_mask);
293 if (sigaction(sig->
signo, &sa, NULL) == -1) {
295 "sigaction(%s) failed", sig->
signame);
305 ngx_signal_handler(
int signo)
316 for (sig = signals; sig->
signo != 0; sig++) {
317 if (sig->
signo == signo) {
334 action =
", shutting down";
340 action =
", exiting";
346 action =
", stop accepting connections";
352 action =
", reconfiguring";
357 action =
", reopening logs";
370 action =
", ignoring";
376 action =
", changing binary";
405 action =
", shutting down";
411 action =
", exiting";
416 action =
", reopening logs";
422 action =
", ignoring";
430 "signal %d (%s) received%s", signo, sig->
signame, action);
434 "the changing binary signal is ignored: "
435 "you should shutdown or terminate "
436 "before either old or new binary's process");
439 if (signo == SIGCHLD) {
440 ngx_process_get_status();
448 ngx_process_get_status(
void)
460 pid = waitpid(-1, &status, WNOHANG);
499 process =
"unknown process";
502 if (ngx_processes[i].pid == pid) {
503 ngx_processes[
i].
status = status;
505 process = ngx_processes[
i].
name;
510 if (WTERMSIG(status)) {
513 "%s %P exited on signal %d%s",
514 process, pid, WTERMSIG(status),
515 WCOREDUMP(status) ?
" (core dumped)" :
"");
518 "%s %P exited on signal %d",
519 process, pid, WTERMSIG(status));
524 "%s %P exited with code %d",
525 process, pid, WEXITSTATUS(status));
528 if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) {
530 "%s %P exited with fatal code %d "
531 "and cannot be respawned",
532 process, pid, WEXITSTATUS(status));
536 ngx_unlock_mutexes(pid);
564 shm_zone = part->
elts;
568 if (i >= part->
nelts) {
569 if (part->
next == NULL) {
573 shm_zone = part->
elts;
581 "shared memory zone \"%V\" was locked by %P",
613 for (sig = signals; sig->
signo != 0; sig++) {
615 if (kill(pid, sig->
signo) != -1) {
620 "kill(%P, %d) failed", pid, sig->
signo);