Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_process.c @ 3015:26ac108cfc39
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 10 Aug 2009 12:49:06 +0000 |
parents | ae81441e23f4 |
children | d82993af1da0 4b5cf483c6a8 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
391
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
391
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
391
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
391
diff
changeset
|
5 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
9 #include <ngx_event.h> |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
10 #include <ngx_channel.h> |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
539 | 13 typedef struct { |
14 int signo; | |
15 char *signame; | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
16 char *name; |
539 | 17 void (*handler)(int signo); |
18 } ngx_signal_t; | |
19 | |
20 | |
21 | |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
22 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); |
539 | 23 static void ngx_signal_handler(int signo); |
24 static void ngx_process_get_status(void); | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
25 |
452 | 26 |
27 int ngx_argc; | |
28 char **ngx_argv; | |
29 char **ngx_os_argv; | |
30 | |
31 ngx_int_t ngx_process_slot; | |
32 ngx_socket_t ngx_channel; | |
33 ngx_int_t ngx_last_process; | |
34 ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 |
539 | 37 ngx_signal_t signals[] = { |
38 { ngx_signal_value(NGX_RECONFIGURE_SIGNAL), | |
39 "SIG" ngx_value(NGX_RECONFIGURE_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
40 "reload", |
539 | 41 ngx_signal_handler }, |
42 | |
43 { ngx_signal_value(NGX_REOPEN_SIGNAL), | |
44 "SIG" ngx_value(NGX_REOPEN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
45 "reopen", |
539 | 46 ngx_signal_handler }, |
47 | |
48 { ngx_signal_value(NGX_NOACCEPT_SIGNAL), | |
49 "SIG" ngx_value(NGX_NOACCEPT_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
50 "", |
539 | 51 ngx_signal_handler }, |
52 | |
53 { ngx_signal_value(NGX_TERMINATE_SIGNAL), | |
54 "SIG" ngx_value(NGX_TERMINATE_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
55 "stop", |
539 | 56 ngx_signal_handler }, |
57 | |
58 { ngx_signal_value(NGX_SHUTDOWN_SIGNAL), | |
59 "SIG" ngx_value(NGX_SHUTDOWN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
60 "quit", |
539 | 61 ngx_signal_handler }, |
62 | |
63 { ngx_signal_value(NGX_CHANGEBIN_SIGNAL), | |
64 "SIG" ngx_value(NGX_CHANGEBIN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
65 "", |
539 | 66 ngx_signal_handler }, |
67 | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
68 { SIGALRM, "SIGALRM", "", ngx_signal_handler }, |
539 | 69 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
70 { SIGINT, "SIGINT", "", ngx_signal_handler }, |
539 | 71 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
72 { SIGIO, "SIGIO", "", ngx_signal_handler }, |
539 | 73 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
74 { SIGCHLD, "SIGCHLD", "", ngx_signal_handler }, |
539 | 75 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
76 { SIGPIPE, "SIGPIPE, SIG_IGN", "", SIG_IGN }, |
539 | 77 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
78 { 0, NULL, "", NULL } |
539 | 79 }; |
80 | |
81 | |
515 | 82 ngx_pid_t |
83 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, | |
84 char *name, ngx_int_t respawn) | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
86 u_long on; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
87 ngx_pid_t pid; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
88 ngx_int_t s; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
89 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
90 if (respawn >= 0) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
91 s = respawn; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
92 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
93 } else { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
94 for (s = 0; s < ngx_last_process; s++) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
95 if (ngx_processes[s].pid == -1) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
96 break; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
97 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
98 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
99 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
100 if (s == NGX_MAX_PROCESSES) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
101 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
102 "no more than %d processes can be spawned", |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
103 NGX_MAX_PROCESSES); |
543 | 104 return NGX_INVALID_PID; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
105 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
106 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
107 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
108 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
109 if (respawn != NGX_PROCESS_DETACHED) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
110 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
111 /* Solaris 9 still has no AF_LOCAL */ |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
112 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
113 if (socketpair(AF_UNIX, SOCK_STREAM, 0, ngx_processes[s].channel) == -1) |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
114 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
115 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
116 "socketpair() failed while spawning \"%s\"", name); |
543 | 117 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
118 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
119 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
120 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
121 "channel %d:%d", |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
122 ngx_processes[s].channel[0], |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
123 ngx_processes[s].channel[1]); |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
124 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
125 if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
126 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
127 ngx_nonblocking_n " failed while spawning \"%s\"", |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
128 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
129 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 130 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
131 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
132 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
133 if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
134 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
135 ngx_nonblocking_n " failed while spawning \"%s\"", |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
136 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
137 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 138 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
139 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
140 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
141 on = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
142 if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
143 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
144 "ioctl(FIOASYNC) failed while spawning \"%s\"", name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
145 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 146 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
147 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
148 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
149 if (fcntl(ngx_processes[s].channel[0], F_SETOWN, ngx_pid) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
150 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
151 "fcntl(F_SETOWN) failed while spawning \"%s\"", name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
152 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 153 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
154 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
155 |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
156 if (fcntl(ngx_processes[s].channel[0], F_SETFD, FD_CLOEXEC) == -1) { |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
157 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
158 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"", |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
159 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
160 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 161 return NGX_INVALID_PID; |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
162 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
163 |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
164 if (fcntl(ngx_processes[s].channel[1], F_SETFD, FD_CLOEXEC) == -1) { |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
165 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
166 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"", |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
167 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
168 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 169 return NGX_INVALID_PID; |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
170 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
171 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
172 ngx_channel = ngx_processes[s].channel[1]; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
173 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
174 } else { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
175 ngx_processes[s].channel[0] = -1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
176 ngx_processes[s].channel[1] = -1; |
360
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
177 } |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
178 |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
179 ngx_process_slot = s; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
180 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 pid = fork(); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
184 switch (pid) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
185 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
186 case -1: |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
187 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
188 "fork() failed while spawning \"%s\"", name); |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
189 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 190 return NGX_INVALID_PID; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 case 0: |
249
2a0540287298
nginx-0.0.2-2004-02-03-19:43:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
193 ngx_pid = ngx_getpid(); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
194 proc(cycle, data); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 break; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 default: |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
198 break; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
477 | 201 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start %s %P", name, pid); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
202 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
203 ngx_processes[s].pid = pid; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
204 ngx_processes[s].exited = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
205 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
206 if (respawn >= 0) { |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
207 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
208 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
210 ngx_processes[s].proc = proc; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
211 ngx_processes[s].data = data; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
212 ngx_processes[s].name = name; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
213 ngx_processes[s].exiting = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
214 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
215 switch (respawn) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
216 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
217 case NGX_PROCESS_RESPAWN: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
218 ngx_processes[s].respawn = 1; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
219 ngx_processes[s].just_respawn = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
220 ngx_processes[s].detached = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
221 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
222 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
223 case NGX_PROCESS_JUST_RESPAWN: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
224 ngx_processes[s].respawn = 1; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
225 ngx_processes[s].just_respawn = 1; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
226 ngx_processes[s].detached = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
227 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
228 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
229 case NGX_PROCESS_DETACHED: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
230 ngx_processes[s].respawn = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
231 ngx_processes[s].just_respawn = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
232 ngx_processes[s].detached = 1; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
233 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
234 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
235 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
236 if (s == ngx_last_process) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
237 ngx_last_process++; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
238 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
240 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
241 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
242 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
243 |
515 | 244 ngx_pid_t |
245 ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
246 { |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
247 return ngx_spawn_process(cycle, ngx_execute_proc, ctx, ctx->name, |
226
b0c1e21e68db
nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
225
diff
changeset
|
248 NGX_PROCESS_DETACHED); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 |
515 | 252 static void |
253 ngx_execute_proc(ngx_cycle_t *cycle, void *data) | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
254 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
255 ngx_exec_ctx_t *ctx = data; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
256 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
257 if (execve(ctx->path, ctx->argv, ctx->envp) == -1) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
258 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
259 "execve() failed while executing %s \"%s\"", |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
260 ctx->name, ctx->path); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
261 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
262 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
263 exit(1); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
264 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
265 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
266 |
539 | 267 ngx_int_t |
268 ngx_init_signals(ngx_log_t *log) | |
269 { | |
270 ngx_signal_t *sig; | |
271 struct sigaction sa; | |
272 | |
273 for (sig = signals; sig->signo != 0; sig++) { | |
274 ngx_memzero(&sa, sizeof(struct sigaction)); | |
275 sa.sa_handler = sig->handler; | |
276 sigemptyset(&sa.sa_mask); | |
277 if (sigaction(sig->signo, &sa, NULL) == -1) { | |
278 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
279 "sigaction(%s) failed", sig->signame); | |
280 return NGX_ERROR; | |
281 } | |
282 } | |
283 | |
284 return NGX_OK; | |
285 } | |
286 | |
287 | |
515 | 288 void |
539 | 289 ngx_signal_handler(int signo) |
290 { | |
291 char *action; | |
292 ngx_int_t ignore; | |
293 ngx_err_t err; | |
294 ngx_signal_t *sig; | |
295 | |
296 ignore = 0; | |
297 | |
298 err = ngx_errno; | |
299 | |
300 for (sig = signals; sig->signo != 0; sig++) { | |
301 if (sig->signo == signo) { | |
302 break; | |
303 } | |
304 } | |
305 | |
563 | 306 ngx_time_update(0, 0); |
539 | 307 |
308 action = ""; | |
309 | |
310 switch (ngx_process) { | |
311 | |
312 case NGX_PROCESS_MASTER: | |
313 case NGX_PROCESS_SINGLE: | |
314 switch (signo) { | |
315 | |
316 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
317 ngx_quit = 1; | |
318 action = ", shutting down"; | |
319 break; | |
320 | |
321 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
322 case SIGINT: | |
323 ngx_terminate = 1; | |
324 action = ", exiting"; | |
325 break; | |
326 | |
327 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
328 ngx_noaccept = 1; | |
329 action = ", stop accepting connections"; | |
330 break; | |
331 | |
332 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
333 ngx_reconfigure = 1; | |
334 action = ", reconfiguring"; | |
335 break; | |
336 | |
337 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
338 ngx_reopen = 1; | |
339 action = ", reopening logs"; | |
340 break; | |
341 | |
342 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
343 if (getppid() > 1 || ngx_new_binary > 0) { | |
344 | |
345 /* | |
346 * Ignore the signal in the new binary if its parent is | |
347 * not the init process, i.e. the old binary's process | |
698 | 348 * is still running. Or ignore the signal in the old binary's |
539 | 349 * process if the new binary's process is already running. |
350 */ | |
351 | |
352 action = ", ignoring"; | |
353 ignore = 1; | |
354 break; | |
355 } | |
356 | |
357 ngx_change_binary = 1; | |
358 action = ", changing binary"; | |
359 break; | |
360 | |
361 case SIGALRM: | |
362 break; | |
363 | |
364 case SIGIO: | |
365 ngx_sigio = 1; | |
366 break; | |
367 | |
368 case SIGCHLD: | |
369 ngx_reap = 1; | |
370 break; | |
371 } | |
372 | |
373 break; | |
374 | |
375 case NGX_PROCESS_WORKER: | |
376 switch (signo) { | |
377 | |
378 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
379 ngx_debug_quit = 1; | |
380 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
381 ngx_quit = 1; | |
382 action = ", shutting down"; | |
383 break; | |
384 | |
385 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
386 case SIGINT: | |
387 ngx_terminate = 1; | |
388 action = ", exiting"; | |
389 break; | |
390 | |
391 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
392 ngx_reopen = 1; | |
393 action = ", reopening logs"; | |
394 break; | |
395 | |
396 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
397 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
398 case SIGIO: | |
399 action = ", ignoring"; | |
400 break; | |
401 } | |
402 | |
403 break; | |
404 } | |
405 | |
406 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, | |
407 "signal %d (%s) received%s", signo, sig->signame, action); | |
408 | |
409 if (ignore) { | |
410 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0, | |
411 "the changing binary signal is ignored: " | |
412 "you should shutdown or terminate " | |
413 "before either old or new binary's process"); | |
414 } | |
415 | |
416 if (signo == SIGCHLD) { | |
417 ngx_process_get_status(); | |
418 } | |
419 | |
420 ngx_set_errno(err); | |
421 } | |
422 | |
423 | |
424 static void | |
515 | 425 ngx_process_get_status(void) |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
426 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
427 int status; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
428 char *process; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
429 ngx_pid_t pid; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
430 ngx_err_t err; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
431 ngx_int_t i; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
432 ngx_uint_t one; |
477 | 433 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
434 one = 0; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
435 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
436 for ( ;; ) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
437 pid = waitpid(-1, &status, WNOHANG); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
438 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
439 if (pid == 0) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
440 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
441 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
442 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
443 if (pid == -1) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
444 err = ngx_errno; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
445 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
446 if (err == NGX_EINTR) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
447 continue; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
448 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
449 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
450 if (err == NGX_ECHILD && one) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
451 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
452 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
453 |
943
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
454 #if (NGX_SOLARIS || NGX_FREEBSD) |
452 | 455 |
456 /* | |
457 * Solaris always calls the signal handler for each exited process | |
943
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
458 * despite waitpid() may be already called for this process. |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
459 * |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
460 * When several processes exit at the same time FreeBSD may |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
461 * erroneously call the signal handler for exited process |
1963 | 462 * despite waitpid() may be already called for this process. |
452 | 463 */ |
464 | |
465 if (err == NGX_ECHILD) { | |
466 ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, errno, | |
467 "waitpid() failed"); | |
563 | 468 return; |
452 | 469 } |
470 | |
471 #endif | |
472 | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
473 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, errno, |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
474 "waitpid() failed"); |
452 | 475 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
476 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
477 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
478 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
479 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
480 if (ngx_accept_mutex_ptr) { |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
481 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
482 /* |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
483 * unlock the accept mutex if the abnormally exited process |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
484 * held it |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
485 */ |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
486 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
487 ngx_atomic_cmp_set(ngx_accept_mutex_ptr, pid, 0); |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
488 } |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
489 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
490 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
491 one = 1; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
492 process = "unknown process"; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
493 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
494 for (i = 0; i < ngx_last_process; i++) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
495 if (ngx_processes[i].pid == pid) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
496 ngx_processes[i].status = status; |
222
99df0edb63ed
nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
221
diff
changeset
|
497 ngx_processes[i].exited = 1; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
498 process = ngx_processes[i].name; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
499 break; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
500 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
501 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
502 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
503 if (WTERMSIG(status)) { |
2494 | 504 #ifdef WCOREDUMP |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
505 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
461 | 506 "%s %P exited on signal %d%s", |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
507 process, pid, WTERMSIG(status), |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
508 WCOREDUMP(status) ? " (core dumped)" : ""); |
2494 | 509 #else |
510 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, | |
511 "%s %P exited on signal %d", | |
512 process, pid, WTERMSIG(status)); | |
513 #endif | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
514 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
515 } else { |
477 | 516 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
461 | 517 "%s %P exited with code %d", |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
518 process, pid, WEXITSTATUS(status)); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
519 } |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
520 |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
521 if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) { |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
522 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
1963 | 523 "%s %P exited with fatal code %d " |
524 "and can not be respawn", | |
525 process, pid, WEXITSTATUS(status)); | |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
526 ngx_processes[i].respawn = 0; |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
527 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
528 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
529 } |
461 | 530 |
531 | |
515 | 532 void |
533 ngx_debug_point(void) | |
461 | 534 { |
535 ngx_core_conf_t *ccf; | |
536 | |
537 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | |
538 ngx_core_module); | |
539 | |
540 switch (ccf->debug_points) { | |
541 | |
542 case NGX_DEBUG_POINTS_STOP: | |
543 raise(SIGSTOP); | |
544 break; | |
545 | |
546 case NGX_DEBUG_POINTS_ABORT: | |
563 | 547 ngx_abort(); |
461 | 548 } |
549 } | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
550 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
551 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
552 ngx_int_t |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
553 ngx_os_signal_process(ngx_cycle_t *cycle, char *name, ngx_int_t pid) |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
554 { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
555 ngx_signal_t *sig; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
556 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
557 for (sig = signals; sig->signo != 0; sig++) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
558 if (ngx_strcmp(name, sig->name) == 0) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
559 if (kill(pid, sig->signo) != -1) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
560 return 0; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
561 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
562 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
563 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
564 "kill(%P, %d) failed", pid, sig->signo); |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
565 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
566 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
567 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
568 return 1; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
569 } |