Mercurial > hg > nginx
annotate src/os/unix/ngx_process.c @ 1937:c46432b9dbb7
fix case when errors are not cached,
and a file was not used often enough to keep open
and it has been removed before it was kept open
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 13 Mar 2008 12:59:25 +0000 |
parents | cbe0292e53b3 |
children | 957085b56da3 |
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; | |
16 void (*handler)(int signo); | |
17 } ngx_signal_t; | |
18 | |
19 | |
20 | |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
21 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); |
539 | 22 static void ngx_signal_handler(int signo); |
23 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
|
24 |
452 | 25 |
26 int ngx_argc; | |
27 char **ngx_argv; | |
28 char **ngx_os_argv; | |
29 | |
30 ngx_int_t ngx_process_slot; | |
31 ngx_socket_t ngx_channel; | |
32 ngx_int_t ngx_last_process; | |
33 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
|
34 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
539 | 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 }; | |
73 | |
74 | |
515 | 75 ngx_pid_t |
76 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, | |
77 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
|
78 { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
83 if (respawn >= 0) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
84 s = respawn; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
85 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
86 } else { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
87 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
|
88 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
|
89 break; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
90 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
91 } |
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 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
|
94 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
|
95 "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
|
96 NGX_MAX_PROCESSES); |
543 | 97 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
|
98 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
99 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
100 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
101 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
102 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
|
103 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
104 /* 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
|
105 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
106 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
|
107 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
108 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
|
109 "socketpair() failed while spawning \"%s\"", name); |
543 | 110 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
|
111 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
112 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
113 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
|
114 "channel %d:%d", |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
115 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
|
116 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
|
117 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
122 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 123 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
|
124 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
125 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
130 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 131 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
|
132 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
133 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
134 on = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
135 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
|
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 "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
|
138 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 139 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
|
140 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
141 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
142 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
|
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 "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
|
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 |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
149 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
|
150 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
|
151 "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
|
152 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
153 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 154 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
|
155 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
156 |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
157 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
|
158 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
|
159 "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
|
160 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
161 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 162 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
|
163 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
164 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
165 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
|
166 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
167 } else { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
168 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
|
169 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
|
170 } |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
171 |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
172 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
|
173 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 pid = fork(); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
177 switch (pid) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
178 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
179 case -1: |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
180 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
|
181 "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
|
182 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 183 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
|
184 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 case 0: |
249
2a0540287298
nginx-0.0.2-2004-02-03-19:43:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
186 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
|
187 proc(cycle, data); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 break; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 default: |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
191 break; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
477 | 194 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
|
195 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
196 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
|
197 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
|
198 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
199 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
|
200 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
201 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
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].proc = proc; |
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].data = data; |
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].name = name; |
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].exiting = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
207 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
208 switch (respawn) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
209 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
215 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
221 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
227 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
228 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
229 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
|
230 ngx_last_process++; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
231 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
233 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
234 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
235 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
236 |
515 | 237 ngx_pid_t |
238 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
|
239 { |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
240 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
|
241 NGX_PROCESS_DETACHED); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 |
515 | 245 static void |
246 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
|
247 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
248 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
|
249 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
250 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
|
251 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
|
252 "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
|
253 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
|
254 } |
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 exit(1); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
257 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
258 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
259 |
539 | 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 | |
515 | 281 void |
539 | 282 ngx_signal_handler(int signo) |
283 { | |
284 char *action; | |
285 ngx_int_t ignore; | |
286 ngx_err_t err; | |
287 ngx_signal_t *sig; | |
288 | |
289 ignore = 0; | |
290 | |
291 err = ngx_errno; | |
292 | |
293 for (sig = signals; sig->signo != 0; sig++) { | |
294 if (sig->signo == signo) { | |
295 break; | |
296 } | |
297 } | |
298 | |
563 | 299 ngx_time_update(0, 0); |
539 | 300 |
301 action = ""; | |
302 | |
303 switch (ngx_process) { | |
304 | |
305 case NGX_PROCESS_MASTER: | |
306 case NGX_PROCESS_SINGLE: | |
307 switch (signo) { | |
308 | |
309 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
310 ngx_quit = 1; | |
311 action = ", shutting down"; | |
312 break; | |
313 | |
314 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
315 case SIGINT: | |
316 ngx_terminate = 1; | |
317 action = ", exiting"; | |
318 break; | |
319 | |
320 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
321 ngx_noaccept = 1; | |
322 action = ", stop accepting connections"; | |
323 break; | |
324 | |
325 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
326 ngx_reconfigure = 1; | |
327 action = ", reconfiguring"; | |
328 break; | |
329 | |
330 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
331 ngx_reopen = 1; | |
332 action = ", reopening logs"; | |
333 break; | |
334 | |
335 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
336 if (getppid() > 1 || ngx_new_binary > 0) { | |
337 | |
338 /* | |
339 * Ignore the signal in the new binary if its parent is | |
340 * not the init process, i.e. the old binary's process | |
698 | 341 * is still running. Or ignore the signal in the old binary's |
539 | 342 * process if the new binary's process is already running. |
343 */ | |
344 | |
345 action = ", ignoring"; | |
346 ignore = 1; | |
347 break; | |
348 } | |
349 | |
350 ngx_change_binary = 1; | |
351 action = ", changing binary"; | |
352 break; | |
353 | |
354 case SIGALRM: | |
355 break; | |
356 | |
357 case SIGIO: | |
358 ngx_sigio = 1; | |
359 break; | |
360 | |
361 case SIGCHLD: | |
362 ngx_reap = 1; | |
363 break; | |
364 } | |
365 | |
366 break; | |
367 | |
368 case NGX_PROCESS_WORKER: | |
369 switch (signo) { | |
370 | |
371 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
372 ngx_debug_quit = 1; | |
373 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
374 ngx_quit = 1; | |
375 action = ", shutting down"; | |
376 break; | |
377 | |
378 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
379 case SIGINT: | |
380 ngx_terminate = 1; | |
381 action = ", exiting"; | |
382 break; | |
383 | |
384 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
385 ngx_reopen = 1; | |
386 action = ", reopening logs"; | |
387 break; | |
388 | |
389 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
390 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
391 case SIGIO: | |
392 action = ", ignoring"; | |
393 break; | |
394 } | |
395 | |
396 break; | |
397 } | |
398 | |
399 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, | |
400 "signal %d (%s) received%s", signo, sig->signame, action); | |
401 | |
402 if (ignore) { | |
403 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0, | |
404 "the changing binary signal is ignored: " | |
405 "you should shutdown or terminate " | |
406 "before either old or new binary's process"); | |
407 } | |
408 | |
409 if (signo == SIGCHLD) { | |
410 ngx_process_get_status(); | |
411 } | |
412 | |
413 ngx_set_errno(err); | |
414 } | |
415 | |
416 | |
417 static void | |
515 | 418 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
|
419 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
420 int status; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
421 char *process; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 ngx_uint_t one; |
477 | 426 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
427 one = 0; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
428 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
429 for ( ;; ) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
430 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
|
431 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
432 if (pid == 0) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
433 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
434 } |
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 if (pid == -1) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
437 err = ngx_errno; |
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 (err == NGX_EINTR) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
440 continue; |
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 (err == NGX_ECHILD && one) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
444 return; |
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 |
943
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
447 #if (NGX_SOLARIS || NGX_FREEBSD) |
452 | 448 |
449 /* | |
450 * 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
|
451 * 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
|
452 * |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
453 * 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
|
454 * erroneously call the signal handler for exited process |
452 | 455 * despite waitpid() may be already called for this process |
456 */ | |
457 | |
458 if (err == NGX_ECHILD) { | |
459 ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, errno, | |
460 "waitpid() failed"); | |
563 | 461 return; |
452 | 462 } |
463 | |
464 #endif | |
465 | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 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
|
467 "waitpid() failed"); |
452 | 468 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
469 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
470 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
471 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
472 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
473 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
|
474 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
475 /* |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
476 * 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
|
477 * held it |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
478 */ |
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 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
|
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 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
484 one = 1; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
485 process = "unknown process"; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
486 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 break; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
493 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
494 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
495 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
496 if (WTERMSIG(status)) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
497 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
461 | 498 "%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
|
499 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
|
500 WCOREDUMP(status) ? " (core dumped)" : ""); |
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 } else { |
477 | 503 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
461 | 504 "%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
|
505 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
|
506 } |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
507 |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
508 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
|
509 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
461 | 510 "%s %P exited with fatal code %d and could not respawn", |
511 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
|
512 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
|
513 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
514 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
515 } |
461 | 516 |
517 | |
515 | 518 void |
519 ngx_debug_point(void) | |
461 | 520 { |
521 ngx_core_conf_t *ccf; | |
522 | |
523 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | |
524 ngx_core_module); | |
525 | |
526 switch (ccf->debug_points) { | |
527 | |
528 case NGX_DEBUG_POINTS_STOP: | |
529 raise(SIGSTOP); | |
530 break; | |
531 | |
532 case NGX_DEBUG_POINTS_ABORT: | |
563 | 533 ngx_abort(); |
461 | 534 } |
535 } |