Mercurial > hg > nginx-vendor-1-0
comparison src/os/unix/ngx_process.c @ 88:e916a291e9aa NGINX_0_1_44
nginx 0.1.44
*) Feature: the IMAP/POP3 proxy supports SSL.
*) Feature: the "proxy_timeout" directive of the ngx_imap_proxy_module.
*) Feature: the "userid_mark" directive.
*) Feature: the $remote_user variable value is determined independently
of authorization use.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 06 Sep 2005 00:00:00 +0400 |
parents | 5db440287648 |
children | 45945fa8b8ba |
comparison
equal
deleted
inserted
replaced
87:5b7ec80c3c40 | 88:e916a291e9aa |
---|---|
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <ngx_channel.h> | 10 #include <ngx_channel.h> |
11 | 11 |
12 | 12 |
13 typedef struct { | |
14 int signo; | |
15 char *signame; | |
16 void (*handler)(int signo); | |
17 } ngx_signal_t; | |
18 | |
19 | |
20 | |
13 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); | 21 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); |
22 static void ngx_signal_handler(int signo); | |
23 static void ngx_process_get_status(void); | |
14 | 24 |
15 | 25 |
16 int ngx_argc; | 26 int ngx_argc; |
17 char **ngx_argv; | 27 char **ngx_argv; |
18 char **ngx_os_argv; | 28 char **ngx_os_argv; |
19 | 29 |
20 ngx_int_t ngx_process_slot; | 30 ngx_int_t ngx_process_slot; |
21 ngx_socket_t ngx_channel; | 31 ngx_socket_t ngx_channel; |
22 ngx_int_t ngx_last_process; | 32 ngx_int_t ngx_last_process; |
23 ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; | 33 ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; |
34 | |
35 | |
36 ngx_signal_t signals[] = { | |
37 { ngx_signal_value(NGX_RECONFIGURE_SIGNAL), | |
38 "SIG" ngx_value(NGX_RECONFIGURE_SIGNAL), | |
39 ngx_signal_handler }, | |
40 | |
41 { ngx_signal_value(NGX_REOPEN_SIGNAL), | |
42 "SIG" ngx_value(NGX_REOPEN_SIGNAL), | |
43 ngx_signal_handler }, | |
44 | |
45 { ngx_signal_value(NGX_NOACCEPT_SIGNAL), | |
46 "SIG" ngx_value(NGX_NOACCEPT_SIGNAL), | |
47 ngx_signal_handler }, | |
48 | |
49 { ngx_signal_value(NGX_TERMINATE_SIGNAL), | |
50 "SIG" ngx_value(NGX_TERMINATE_SIGNAL), | |
51 ngx_signal_handler }, | |
52 | |
53 { ngx_signal_value(NGX_SHUTDOWN_SIGNAL), | |
54 "SIG" ngx_value(NGX_SHUTDOWN_SIGNAL), | |
55 ngx_signal_handler }, | |
56 | |
57 { ngx_signal_value(NGX_CHANGEBIN_SIGNAL), | |
58 "SIG" ngx_value(NGX_CHANGEBIN_SIGNAL), | |
59 ngx_signal_handler }, | |
60 | |
61 { SIGALRM, "SIGALRM", ngx_signal_handler }, | |
62 | |
63 { SIGINT, "SIGINT", ngx_signal_handler }, | |
64 | |
65 { SIGIO, "SIGIO", ngx_signal_handler }, | |
66 | |
67 { SIGCHLD, "SIGCHLD", ngx_signal_handler }, | |
68 | |
69 { SIGPIPE, "SIGPIPE, SIG_IGN", SIG_IGN }, | |
70 | |
71 { 0, NULL, NULL } | |
72 }; | |
24 | 73 |
25 | 74 |
26 ngx_pid_t | 75 ngx_pid_t |
27 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, | 76 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, |
28 char *name, ngx_int_t respawn) | 77 char *name, ngx_int_t respawn) |
206 | 255 |
207 exit(1); | 256 exit(1); |
208 } | 257 } |
209 | 258 |
210 | 259 |
260 ngx_int_t | |
261 ngx_init_signals(ngx_log_t *log) | |
262 { | |
263 ngx_signal_t *sig; | |
264 struct sigaction sa; | |
265 | |
266 for (sig = signals; sig->signo != 0; sig++) { | |
267 ngx_memzero(&sa, sizeof(struct sigaction)); | |
268 sa.sa_handler = sig->handler; | |
269 sigemptyset(&sa.sa_mask); | |
270 if (sigaction(sig->signo, &sa, NULL) == -1) { | |
271 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
272 "sigaction(%s) failed", sig->signame); | |
273 return NGX_ERROR; | |
274 } | |
275 } | |
276 | |
277 return NGX_OK; | |
278 } | |
279 | |
280 | |
211 void | 281 void |
282 ngx_signal_handler(int signo) | |
283 { | |
284 char *action; | |
285 struct timeval tv; | |
286 ngx_int_t ignore; | |
287 ngx_err_t err; | |
288 ngx_signal_t *sig; | |
289 | |
290 ignore = 0; | |
291 | |
292 err = ngx_errno; | |
293 | |
294 for (sig = signals; sig->signo != 0; sig++) { | |
295 if (sig->signo == signo) { | |
296 break; | |
297 } | |
298 } | |
299 | |
300 ngx_gettimeofday(&tv); | |
301 ngx_time_update(tv.tv_sec); | |
302 | |
303 action = ""; | |
304 | |
305 switch (ngx_process) { | |
306 | |
307 case NGX_PROCESS_MASTER: | |
308 case NGX_PROCESS_SINGLE: | |
309 switch (signo) { | |
310 | |
311 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
312 ngx_quit = 1; | |
313 action = ", shutting down"; | |
314 break; | |
315 | |
316 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
317 case SIGINT: | |
318 ngx_terminate = 1; | |
319 action = ", exiting"; | |
320 break; | |
321 | |
322 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
323 ngx_noaccept = 1; | |
324 action = ", stop accepting connections"; | |
325 break; | |
326 | |
327 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
328 ngx_reconfigure = 1; | |
329 action = ", reconfiguring"; | |
330 break; | |
331 | |
332 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
333 ngx_reopen = 1; | |
334 action = ", reopening logs"; | |
335 break; | |
336 | |
337 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
338 if (getppid() > 1 || ngx_new_binary > 0) { | |
339 | |
340 /* | |
341 * Ignore the signal in the new binary if its parent is | |
342 * not the init process, i.e. the old binary's process | |
343 * is still running. Or ingore the signal in the old binary's | |
344 * process if the new binary's process is already running. | |
345 */ | |
346 | |
347 action = ", ignoring"; | |
348 ignore = 1; | |
349 break; | |
350 } | |
351 | |
352 ngx_change_binary = 1; | |
353 action = ", changing binary"; | |
354 break; | |
355 | |
356 case SIGALRM: | |
357 if (!ngx_terminate) { | |
358 ngx_timer = 1; | |
359 action = ", shutting down old worker processes"; | |
360 } | |
361 | |
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 | |
212 ngx_process_get_status(void) | 425 ngx_process_get_status(void) |
213 { | 426 { |
214 int status; | 427 int status; |
215 char *process; | 428 char *process; |
216 ngx_pid_t pid; | 429 ngx_pid_t pid; |