Mercurial > hg > nginx
annotate src/os/unix/ngx_process.c @ 3892:12d8d2f30205
use MurmurHash2 for split_clients, because
its distribution is much better than CRC32's one
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 15 Apr 2011 10:59:57 +0000 |
parents | e294f37401c0 |
children | 5364d2e711cc |
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 { |
3681 | 14 int signo; |
15 char *signame; | |
16 char *name; | |
17 void (*handler)(int signo); | |
539 | 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 |
3045 | 76 { SIGSYS, "SIGSYS, SIG_IGN", "", SIG_IGN }, |
77 | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
78 { SIGPIPE, "SIGPIPE, SIG_IGN", "", SIG_IGN }, |
539 | 79 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
80 { 0, NULL, "", NULL } |
539 | 81 }; |
82 | |
83 | |
515 | 84 ngx_pid_t |
85 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, | |
86 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
|
87 { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
92 if (respawn >= 0) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
93 s = respawn; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
94 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
95 } else { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
96 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
|
97 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
|
98 break; |
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 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
101 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
102 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
|
103 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
|
104 "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
|
105 NGX_MAX_PROCESSES); |
543 | 106 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
|
107 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
108 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
109 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
110 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
111 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
|
112 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
113 /* 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
|
114 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
115 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
|
116 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
117 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
|
118 "socketpair() failed while spawning \"%s\"", name); |
543 | 119 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
|
120 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
121 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
122 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
|
123 "channel %d:%d", |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
124 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
|
125 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
|
126 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
131 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 132 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
|
133 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
134 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
139 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 140 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
|
141 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
142 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
143 on = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
144 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
|
145 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
|
146 "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
|
147 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 148 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
|
149 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
150 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
151 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
|
152 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
|
153 "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
|
154 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 155 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
|
156 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
157 |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
158 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
|
159 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
|
160 "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
|
161 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
162 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 163 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
|
164 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
165 |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
166 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
|
167 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
|
168 "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
|
169 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
170 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 171 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
|
172 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
173 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
174 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
|
175 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
176 } else { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
177 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
|
178 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
|
179 } |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
180 |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
181 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
|
182 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 pid = fork(); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
186 switch (pid) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
187 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
188 case -1: |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
189 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
|
190 "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
|
191 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 192 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
|
193 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 case 0: |
249
2a0540287298
nginx-0.0.2-2004-02-03-19:43:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
195 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
|
196 proc(cycle, data); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 break; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 default: |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
200 break; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 |
477 | 203 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
|
204 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
205 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
|
206 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
|
207 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
208 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
|
209 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
210 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
354
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].proc = proc; |
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].data = data; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
214 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
|
215 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
|
216 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
217 switch (respawn) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
218 |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
219 case NGX_PROCESS_NORESPAWN: |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
220 ngx_processes[s].respawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
221 ngx_processes[s].just_spawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
222 ngx_processes[s].detached = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
223 break; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
224 |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
225 case NGX_PROCESS_JUST_SPAWN: |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
226 ngx_processes[s].respawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
227 ngx_processes[s].just_spawn = 1; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
228 ngx_processes[s].detached = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
229 break; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
230 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
231 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
|
232 ngx_processes[s].respawn = 1; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
233 ngx_processes[s].just_spawn = 0; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
234 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
|
235 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
236 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
237 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
|
238 ngx_processes[s].respawn = 1; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
239 ngx_processes[s].just_spawn = 1; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
240 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
|
241 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
242 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
243 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
|
244 ngx_processes[s].respawn = 0; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
245 ngx_processes[s].just_spawn = 0; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
246 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
|
247 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
248 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
249 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
250 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
|
251 ngx_last_process++; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
252 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
253 |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
254 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
255 } |
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 |
515 | 258 ngx_pid_t |
259 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
|
260 { |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
261 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
|
262 NGX_PROCESS_DETACHED); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
263 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 |
515 | 266 static void |
267 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
|
268 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
269 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
|
270 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
271 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
|
272 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
|
273 "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
|
274 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
|
275 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
276 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
277 exit(1); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
278 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
279 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
280 |
539 | 281 ngx_int_t |
282 ngx_init_signals(ngx_log_t *log) | |
283 { | |
284 ngx_signal_t *sig; | |
285 struct sigaction sa; | |
286 | |
287 for (sig = signals; sig->signo != 0; sig++) { | |
288 ngx_memzero(&sa, sizeof(struct sigaction)); | |
289 sa.sa_handler = sig->handler; | |
290 sigemptyset(&sa.sa_mask); | |
291 if (sigaction(sig->signo, &sa, NULL) == -1) { | |
292 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
293 "sigaction(%s) failed", sig->signame); | |
294 return NGX_ERROR; | |
295 } | |
296 } | |
297 | |
298 return NGX_OK; | |
299 } | |
300 | |
301 | |
515 | 302 void |
539 | 303 ngx_signal_handler(int signo) |
304 { | |
305 char *action; | |
306 ngx_int_t ignore; | |
307 ngx_err_t err; | |
308 ngx_signal_t *sig; | |
309 | |
310 ignore = 0; | |
311 | |
312 err = ngx_errno; | |
313 | |
314 for (sig = signals; sig->signo != 0; sig++) { | |
315 if (sig->signo == signo) { | |
316 break; | |
317 } | |
318 } | |
319 | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
320 ngx_time_sigsafe_update(); |
539 | 321 |
322 action = ""; | |
323 | |
324 switch (ngx_process) { | |
325 | |
326 case NGX_PROCESS_MASTER: | |
327 case NGX_PROCESS_SINGLE: | |
328 switch (signo) { | |
329 | |
330 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
331 ngx_quit = 1; | |
332 action = ", shutting down"; | |
333 break; | |
334 | |
335 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
336 case SIGINT: | |
337 ngx_terminate = 1; | |
338 action = ", exiting"; | |
339 break; | |
340 | |
341 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
342 ngx_noaccept = 1; | |
343 action = ", stop accepting connections"; | |
344 break; | |
345 | |
346 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
347 ngx_reconfigure = 1; | |
348 action = ", reconfiguring"; | |
349 break; | |
350 | |
351 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
352 ngx_reopen = 1; | |
353 action = ", reopening logs"; | |
354 break; | |
355 | |
356 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
357 if (getppid() > 1 || ngx_new_binary > 0) { | |
358 | |
359 /* | |
360 * Ignore the signal in the new binary if its parent is | |
361 * not the init process, i.e. the old binary's process | |
698 | 362 * is still running. Or ignore the signal in the old binary's |
539 | 363 * process if the new binary's process is already running. |
364 */ | |
365 | |
366 action = ", ignoring"; | |
367 ignore = 1; | |
368 break; | |
369 } | |
370 | |
371 ngx_change_binary = 1; | |
372 action = ", changing binary"; | |
373 break; | |
374 | |
375 case SIGALRM: | |
3048
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3045
diff
changeset
|
376 ngx_sigalrm = 1; |
539 | 377 break; |
378 | |
379 case SIGIO: | |
380 ngx_sigio = 1; | |
381 break; | |
382 | |
383 case SIGCHLD: | |
384 ngx_reap = 1; | |
385 break; | |
386 } | |
387 | |
388 break; | |
389 | |
390 case NGX_PROCESS_WORKER: | |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3048
diff
changeset
|
391 case NGX_PROCESS_HELPER: |
539 | 392 switch (signo) { |
393 | |
394 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
395 ngx_debug_quit = 1; | |
396 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
397 ngx_quit = 1; | |
398 action = ", shutting down"; | |
399 break; | |
400 | |
401 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
402 case SIGINT: | |
403 ngx_terminate = 1; | |
404 action = ", exiting"; | |
405 break; | |
406 | |
407 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
408 ngx_reopen = 1; | |
409 action = ", reopening logs"; | |
410 break; | |
411 | |
412 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
413 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
414 case SIGIO: | |
415 action = ", ignoring"; | |
416 break; | |
417 } | |
418 | |
419 break; | |
420 } | |
421 | |
422 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, | |
423 "signal %d (%s) received%s", signo, sig->signame, action); | |
424 | |
425 if (ignore) { | |
426 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0, | |
427 "the changing binary signal is ignored: " | |
428 "you should shutdown or terminate " | |
429 "before either old or new binary's process"); | |
430 } | |
431 | |
432 if (signo == SIGCHLD) { | |
433 ngx_process_get_status(); | |
434 } | |
435 | |
436 ngx_set_errno(err); | |
437 } | |
438 | |
439 | |
440 static void | |
515 | 441 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
|
442 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
443 int status; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
444 char *process; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 ngx_uint_t one; |
477 | 449 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
450 one = 0; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
451 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
452 for ( ;; ) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
453 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
|
454 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
455 if (pid == 0) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
456 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
457 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
458 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
459 if (pid == -1) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
460 err = ngx_errno; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
461 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
462 if (err == NGX_EINTR) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
463 continue; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
464 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
465 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 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
|
467 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
468 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
469 |
943
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
470 #if (NGX_SOLARIS || NGX_FREEBSD) |
452 | 471 |
472 /* | |
473 * 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
|
474 * 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
|
475 * |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
476 * 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
|
477 * erroneously call the signal handler for exited process |
1963 | 478 * despite waitpid() may be already called for this process. |
452 | 479 */ |
480 | |
481 if (err == NGX_ECHILD) { | |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
482 ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, err, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
483 "waitpid() failed"); |
563 | 484 return; |
452 | 485 } |
486 | |
487 #endif | |
488 | |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
489 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
490 "waitpid() failed"); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
491 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
492 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
493 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
494 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
495 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
|
496 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
497 /* |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
498 * 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
|
499 * held it |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
500 */ |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
501 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
502 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
|
503 } |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
504 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
505 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
506 one = 1; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
507 process = "unknown process"; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
508 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 break; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
515 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
516 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
517 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
518 if (WTERMSIG(status)) { |
2494 | 519 #ifdef WCOREDUMP |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
520 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
461 | 521 "%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
|
522 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
|
523 WCOREDUMP(status) ? " (core dumped)" : ""); |
2494 | 524 #else |
525 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, | |
526 "%s %P exited on signal %d", | |
527 process, pid, WTERMSIG(status)); | |
528 #endif | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
529 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
530 } else { |
477 | 531 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
461 | 532 "%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
|
533 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
|
534 } |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
535 |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
536 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
|
537 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
1963 | 538 "%s %P exited with fatal code %d " |
539 "and can not be respawn", | |
540 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
|
541 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
|
542 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
544 } |
461 | 545 |
546 | |
515 | 547 void |
548 ngx_debug_point(void) | |
461 | 549 { |
550 ngx_core_conf_t *ccf; | |
551 | |
552 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | |
553 ngx_core_module); | |
554 | |
555 switch (ccf->debug_points) { | |
556 | |
557 case NGX_DEBUG_POINTS_STOP: | |
558 raise(SIGSTOP); | |
559 break; | |
560 | |
561 case NGX_DEBUG_POINTS_ABORT: | |
563 | 562 ngx_abort(); |
461 | 563 } |
564 } | |
2738
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 ngx_int_t |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
568 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
|
569 { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
570 ngx_signal_t *sig; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
571 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
572 for (sig = signals; sig->signo != 0; sig++) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
573 if (ngx_strcmp(name, sig->name) == 0) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
574 if (kill(pid, sig->signo) != -1) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
575 return 0; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
576 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
577 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
578 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
|
579 "kill(%P, %d) failed", pid, sig->signo); |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
580 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
581 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
582 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
583 return 1; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
584 } |