Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_process_cycle.c @ 4241:6afb20bf2ad5 stable-1.0
Merging r4009, r4133, r4184, r4201, r4202, r4203, r4204, r4205:
Miscellaneous fixes:
*) Fix of names of the referer hash size directives introduced in r3940.
*) Cosmetics: replaced NGX_CONF_TAKE1 to NGX_CONF_FLAG for "sendfile"
and "chunked_transfer_encoding" directives, to be in line with all
directives taking a boolean argument. Both flags will ensure that
a directive takes one argument.
*) Improved ngx_parse_time() code readability.
*) Preallocating exact number of default MIME types entries.
*) Stylistic change in checking the boolean expression.
*) Replaced magic constants representing default values of some directives
with appropriate #define's.
*) Fixed grammar in a comment.
*) Fixed two minor bugs in "types" parsing code.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 01 Nov 2011 11:19:58 +0000 |
parents | a4755d4fd91b |
children | 59b99f217c6d |
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:
368
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:
368
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:
368
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:
368
diff
changeset
|
5 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
461 | 10 #include <nginx.h> |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
2725 | 13 static void ngx_process_init(ngx_cycle_t *cycle); |
14 static void ngx_console_init(ngx_cycle_t *cycle); | |
15 static int __stdcall ngx_console_handler(u_long type); | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
16 static ngx_int_t ngx_create_signal_events(ngx_cycle_t *cycle); |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
17 static ngx_int_t ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type); |
2725 | 18 static void ngx_reopen_worker_processes(ngx_cycle_t *cycle); |
19 static void ngx_quit_worker_processes(ngx_cycle_t *cycle, ngx_uint_t old); | |
20 static void ngx_terminate_worker_processes(ngx_cycle_t *cycle); | |
21 static ngx_uint_t ngx_reap_worker(ngx_cycle_t *cycle, HANDLE h); | |
22 static void ngx_master_process_exit(ngx_cycle_t *cycle); | |
23 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn); | |
24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); | |
25 static ngx_thread_value_t __stdcall ngx_worker_thread(void *data); | |
26 static ngx_thread_value_t __stdcall ngx_cache_manager_thread(void *data); | |
27 static void ngx_cache_manager_process_handler(void); | |
3022 | 28 static ngx_thread_value_t __stdcall ngx_cache_loader_thread(void *data); |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
29 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
30 |
2725 | 31 ngx_uint_t ngx_process; |
32 ngx_pid_t ngx_pid; | |
33 ngx_uint_t ngx_threaded; | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
34 |
2725 | 35 ngx_uint_t ngx_inherited; |
36 ngx_pid_t ngx_new_binary; | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
2725 | 38 sig_atomic_t ngx_terminate; |
39 sig_atomic_t ngx_quit; | |
40 sig_atomic_t ngx_reopen; | |
41 sig_atomic_t ngx_reconfigure; | |
42 ngx_uint_t ngx_exiting; | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
2725 | 45 HANDLE ngx_master_process_event; |
46 char ngx_master_process_event_name[NGX_PROCESS_SYNC_NAME]; | |
47 | |
48 static HANDLE ngx_stop_event; | |
49 static char ngx_stop_event_name[NGX_PROCESS_SYNC_NAME]; | |
50 static HANDLE ngx_quit_event; | |
51 static char ngx_quit_event_name[NGX_PROCESS_SYNC_NAME]; | |
52 static HANDLE ngx_reopen_event; | |
53 static char ngx_reopen_event_name[NGX_PROCESS_SYNC_NAME]; | |
54 static HANDLE ngx_reload_event; | |
55 static char ngx_reload_event_name[NGX_PROCESS_SYNC_NAME]; | |
56 | |
57 HANDLE ngx_cache_manager_mutex; | |
58 char ngx_cache_manager_mutex_name[NGX_PROCESS_SYNC_NAME]; | |
59 HANDLE ngx_cache_manager_event; | |
461 | 60 |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
61 |
509 | 62 void |
63 ngx_master_process_cycle(ngx_cycle_t *cycle) | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 { |
2725 | 65 u_long nev, ev, timeout; |
66 ngx_err_t err; | |
67 ngx_int_t n; | |
68 ngx_msec_t timer; | |
69 ngx_uint_t live; | |
70 HANDLE events[MAXIMUM_WAIT_OBJECTS]; | |
71 | |
72 ngx_process_init(cycle); | |
73 | |
74 ngx_sprintf((u_char *) ngx_master_process_event_name, | |
75 "ngx_master_%s%Z", ngx_unique); | |
76 | |
77 if (ngx_process == NGX_PROCESS_WORKER) { | |
78 ngx_worker_process_cycle(cycle, ngx_master_process_event_name); | |
79 return; | |
80 } | |
81 | |
82 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "master started"); | |
83 | |
84 ngx_console_init(cycle); | |
85 | |
86 SetEnvironmentVariable("ngx_unique", ngx_unique); | |
87 | |
88 ngx_master_process_event = CreateEvent(NULL, 1, 0, | |
89 ngx_master_process_event_name); | |
90 if (ngx_master_process_event == NULL) { | |
91 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
92 "CreateEvent(\"%s\") failed", | |
93 ngx_master_process_event_name); | |
94 exit(2); | |
95 } | |
96 | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
97 if (ngx_create_signal_events(cycle) != NGX_OK) { |
2725 | 98 exit(2); |
99 } | |
100 | |
101 ngx_sprintf((u_char *) ngx_cache_manager_mutex_name, | |
102 "ngx_cache_manager_mutex_%s%Z", ngx_unique); | |
103 | |
104 ngx_cache_manager_mutex = CreateMutex(NULL, 0, | |
105 ngx_cache_manager_mutex_name); | |
106 if (ngx_cache_manager_mutex == NULL) { | |
107 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
108 "CreateMutex(\"%s\") failed", ngx_cache_manager_mutex_name); | |
109 exit(2); | |
110 } | |
111 | |
112 | |
113 events[0] = ngx_stop_event; | |
114 events[1] = ngx_quit_event; | |
115 events[2] = ngx_reopen_event; | |
116 events[3] = ngx_reload_event; | |
117 | |
118 ngx_close_listening_sockets(cycle); | |
119 | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
120 if (ngx_start_worker_processes(cycle, NGX_PROCESS_RESPAWN) == 0) { |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
121 exit(2); |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
122 } |
2725 | 123 |
124 timer = 0; | |
125 timeout = INFINITE; | |
126 | |
127 for ( ;; ) { | |
128 | |
129 nev = 4; | |
130 for (n = 0; n < ngx_last_process; n++) { | |
131 if (ngx_processes[n].handle) { | |
132 events[nev++] = ngx_processes[n].handle; | |
133 } | |
134 } | |
135 | |
136 if (timer) { | |
137 timeout = timer > ngx_current_msec ? timer - ngx_current_msec : 0; | |
138 } | |
139 | |
140 ev = WaitForMultipleObjects(nev, events, 0, timeout); | |
141 | |
142 err = ngx_errno; | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
143 ngx_time_update(); |
2725 | 144 |
145 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
146 "master WaitForMultipleObjects: %ul", ev); | |
147 | |
148 if (ev == WAIT_OBJECT_0) { | |
149 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
324
0ab66f4b6c4d
nginx-0.0.3-2004-04-22-00:13:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
150 |
2725 | 151 if (ResetEvent(ngx_stop_event) == 0) { |
152 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
153 "ResetEvent(\"%s\") failed", ngx_stop_event_name); | |
154 } | |
155 | |
156 if (timer == 0) { | |
157 timer = ngx_current_msec + 5000; | |
158 } | |
159 | |
160 ngx_terminate = 1; | |
161 ngx_quit_worker_processes(cycle, 0); | |
162 | |
163 continue; | |
164 } | |
165 | |
166 if (ev == WAIT_OBJECT_0 + 1) { | |
167 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "shutting down"); | |
168 | |
169 if (ResetEvent(ngx_quit_event) == 0) { | |
170 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
171 "ResetEvent(\"%s\") failed", ngx_quit_event_name); | |
172 } | |
173 | |
174 ngx_quit = 1; | |
175 ngx_quit_worker_processes(cycle, 0); | |
176 | |
177 continue; | |
178 } | |
179 | |
180 if (ev == WAIT_OBJECT_0 + 2) { | |
181 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); | |
182 | |
183 if (ResetEvent(ngx_reopen_event) == 0) { | |
184 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
185 "ResetEvent(\"%s\") failed", | |
186 ngx_reopen_event_name); | |
187 } | |
188 | |
189 ngx_reopen_files(cycle, -1); | |
190 ngx_reopen_worker_processes(cycle); | |
191 | |
192 continue; | |
193 } | |
194 | |
195 if (ev == WAIT_OBJECT_0 + 3) { | |
196 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring"); | |
197 | |
198 if (ResetEvent(ngx_reload_event) == 0) { | |
199 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
200 "ResetEvent(\"%s\") failed", | |
201 ngx_reload_event_name); | |
202 } | |
203 | |
2823 | 204 cycle = ngx_init_cycle(cycle); |
205 if (cycle == NULL) { | |
206 cycle = (ngx_cycle_t *) ngx_cycle; | |
207 continue; | |
208 } | |
209 | |
210 ngx_cycle = cycle; | |
211 | |
2928 | 212 ngx_close_listening_sockets(cycle); |
213 | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
214 if (ngx_start_worker_processes(cycle, NGX_PROCESS_JUST_RESPAWN)) { |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
215 ngx_quit_worker_processes(cycle, 1); |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
216 } |
2725 | 217 |
218 continue; | |
219 } | |
220 | |
221 if (ev > WAIT_OBJECT_0 + 3 && ev < WAIT_OBJECT_0 + nev) { | |
222 | |
223 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "reap worker"); | |
224 | |
225 live = ngx_reap_worker(cycle, events[ev]); | |
226 | |
227 if (!live && (ngx_terminate || ngx_quit)) { | |
228 ngx_master_process_exit(cycle); | |
229 } | |
230 | |
231 continue; | |
232 } | |
233 | |
234 if (ev == WAIT_TIMEOUT) { | |
235 ngx_terminate_worker_processes(cycle); | |
236 | |
237 ngx_master_process_exit(cycle); | |
238 } | |
239 | |
240 if (ev == WAIT_FAILED) { | |
241 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
242 "WaitForMultipleObjects() failed"); | |
243 | |
244 continue; | |
245 } | |
246 | |
247 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
248 "WaitForMultipleObjects() returned unexpected value %ul", ev); | |
249 } | |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
250 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
251 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
252 |
2725 | 253 static void |
254 ngx_process_init(ngx_cycle_t *cycle) | |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
255 { |
461 | 256 ngx_err_t err; |
257 ngx_core_conf_t *ccf; | |
282
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
258 |
461 | 259 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
260 | |
2627 | 261 if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle) |
262 != NGX_OK) | |
577 | 263 { |
461 | 264 /* fatal */ |
265 exit(2); | |
266 } | |
267 | |
268 err = ngx_thread_key_create(&ngx_core_tls_key); | |
269 if (err != 0) { | |
270 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
271 ngx_thread_key_create_n " failed"); | |
272 /* fatal */ | |
273 exit(2); | |
274 } | |
2725 | 275 } |
461 | 276 |
2725 | 277 |
278 static void | |
279 ngx_console_init(ngx_cycle_t *cycle) | |
280 { | |
281 ngx_core_conf_t *ccf; | |
282 | |
283 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
284 | |
285 if (ccf->daemon) { | |
286 if (FreeConsole() == 0) { | |
287 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
288 "FreeConsole() failed"); | |
289 } | |
290 | |
291 return; | |
292 } | |
293 | |
294 if (SetConsoleCtrlHandler(ngx_console_handler, 1) == 0) { | |
295 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
296 "SetConsoleCtrlHandler() failed"); | |
297 } | |
298 } | |
299 | |
300 | |
301 static int __stdcall | |
302 ngx_console_handler(u_long type) | |
303 { | |
304 char *msg; | |
305 | |
306 switch (type) { | |
307 | |
308 case CTRL_C_EVENT: | |
309 msg = "Ctrl-C pressed, exiting"; | |
310 break; | |
311 | |
312 case CTRL_BREAK_EVENT: | |
313 msg = "Ctrl-Break pressed, exiting"; | |
314 break; | |
315 | |
316 case CTRL_CLOSE_EVENT: | |
317 msg = "console closing, exiting"; | |
318 break; | |
319 | |
320 case CTRL_LOGOFF_EVENT: | |
321 msg = "user logs off, exiting"; | |
322 break; | |
323 | |
324 default: | |
325 return 0; | |
326 } | |
327 | |
328 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, msg); | |
329 | |
330 if (ngx_stop_event == NULL) { | |
331 return 1; | |
332 } | |
333 | |
334 if (SetEvent(ngx_stop_event) == 0) { | |
335 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, | |
336 "SetEvent(\"%s\") failed", ngx_stop_event_name); | |
2627 | 337 } |
338 | |
2725 | 339 return 1; |
340 } | |
341 | |
342 | |
343 static ngx_int_t | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
344 ngx_create_signal_events(ngx_cycle_t *cycle) |
2725 | 345 { |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
346 ngx_sprintf((u_char *) ngx_stop_event_name, |
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
347 "Global\\ngx_stop_%s%Z", ngx_unique); |
2725 | 348 |
349 ngx_stop_event = CreateEvent(NULL, 1, 0, ngx_stop_event_name); | |
350 if (ngx_stop_event == NULL) { | |
351 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
352 "CreateEvent(\"%s\") failed", ngx_stop_event_name); | |
353 return NGX_ERROR; | |
354 } | |
355 | |
356 | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
357 ngx_sprintf((u_char *) ngx_quit_event_name, |
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
358 "Global\\ngx_quit_%s%Z", ngx_unique); |
2725 | 359 |
360 ngx_quit_event = CreateEvent(NULL, 1, 0, ngx_quit_event_name); | |
361 if (ngx_quit_event == NULL) { | |
362 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
363 "CreateEvent(\"%s\") failed", ngx_quit_event_name); | |
364 return NGX_ERROR; | |
365 } | |
366 | |
367 | |
368 ngx_sprintf((u_char *) ngx_reopen_event_name, | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
369 "Global\\ngx_reopen_%s%Z", ngx_unique); |
2725 | 370 |
371 ngx_reopen_event = CreateEvent(NULL, 1, 0, ngx_reopen_event_name); | |
372 if (ngx_reopen_event == NULL) { | |
373 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
374 "CreateEvent(\"%s\") failed", ngx_reopen_event_name); | |
375 return NGX_ERROR; | |
376 } | |
377 | |
378 | |
379 ngx_sprintf((u_char *) ngx_reload_event_name, | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
380 "Global\\ngx_reload_%s%Z", ngx_unique); |
2725 | 381 |
382 ngx_reload_event = CreateEvent(NULL, 1, 0, ngx_reload_event_name); | |
383 if (ngx_reload_event == NULL) { | |
384 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
385 "CreateEvent(\"%s\") failed", ngx_reload_event_name); | |
386 return NGX_ERROR; | |
387 } | |
388 | |
389 return NGX_OK; | |
390 } | |
391 | |
392 | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
393 static ngx_int_t |
2725 | 394 ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type) |
395 { | |
396 ngx_int_t n; | |
397 ngx_core_conf_t *ccf; | |
398 | |
399 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes"); | |
400 | |
401 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
402 | |
403 for (n = 0; n < ccf->worker_processes; n++) { | |
404 if (ngx_spawn_process(cycle, "worker", type) == NGX_INVALID_PID) { | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
405 break; |
2725 | 406 } |
407 } | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
408 |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
409 return n; |
2627 | 410 } |
411 | |
412 | |
2725 | 413 static void |
414 ngx_reopen_worker_processes(ngx_cycle_t *cycle) | |
415 { | |
416 ngx_int_t n; | |
417 | |
418 for (n = 0; n < ngx_last_process; n++) { | |
419 | |
420 if (ngx_processes[n].handle == NULL) { | |
421 continue; | |
422 } | |
423 | |
424 if (SetEvent(ngx_processes[n].reopen) == 0) { | |
425 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
426 "SetEvent(\"%s\") failed", | |
427 ngx_processes[n].reopen_event); | |
428 } | |
429 } | |
430 } | |
431 | |
432 | |
433 static void | |
434 ngx_quit_worker_processes(ngx_cycle_t *cycle, ngx_uint_t old) | |
2627 | 435 { |
2725 | 436 ngx_int_t n; |
437 | |
438 for (n = 0; n < ngx_last_process; n++) { | |
439 | |
440 ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
2921 | 441 "process: %d %P %p e:%d j:%d", |
2725 | 442 n, |
443 ngx_processes[n].pid, | |
444 ngx_processes[n].handle, | |
445 ngx_processes[n].exiting, | |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
446 ngx_processes[n].just_spawn); |
2725 | 447 |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
448 if (old && ngx_processes[n].just_spawn) { |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
449 ngx_processes[n].just_spawn = 0; |
2725 | 450 continue; |
451 } | |
452 | |
453 if (ngx_processes[n].handle == NULL) { | |
454 continue; | |
455 } | |
456 | |
457 if (SetEvent(ngx_processes[n].quit) == 0) { | |
458 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
459 "SetEvent(\"%s\") failed", | |
460 ngx_processes[n].quit_event); | |
461 } | |
462 | |
463 ngx_processes[n].exiting = 1; | |
464 } | |
465 } | |
466 | |
467 | |
468 static void | |
469 ngx_terminate_worker_processes(ngx_cycle_t *cycle) | |
470 { | |
471 ngx_int_t n; | |
472 | |
473 for (n = 0; n < ngx_last_process; n++) { | |
474 | |
475 if (ngx_processes[n].handle == NULL) { | |
476 continue; | |
477 } | |
478 | |
479 if (TerminateProcess(ngx_processes[n].handle, 0) == 0) { | |
480 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
481 "TerminateProcess(\"%p\") failed", | |
482 ngx_processes[n].handle); | |
483 } | |
484 | |
485 ngx_processes[n].exiting = 1; | |
2627 | 486 |
2725 | 487 ngx_close_handle(ngx_processes[n].reopen); |
488 ngx_close_handle(ngx_processes[n].quit); | |
489 ngx_close_handle(ngx_processes[n].term); | |
490 ngx_close_handle(ngx_processes[n].handle); | |
491 } | |
492 } | |
493 | |
494 | |
495 static ngx_uint_t | |
496 ngx_reap_worker(ngx_cycle_t *cycle, HANDLE h) | |
497 { | |
498 u_long code; | |
499 ngx_int_t n; | |
500 | |
501 for (n = 0; n < ngx_last_process; n++) { | |
502 | |
503 if (ngx_processes[n].handle != h) { | |
504 continue; | |
505 } | |
506 | |
507 if (GetExitCodeProcess(h, &code) == 0) { | |
2908
234a8248812c
log GetExitCodeProcess()'s errno
Igor Sysoev <igor@sysoev.ru>
parents:
2823
diff
changeset
|
508 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
2725 | 509 "GetExitCodeProcess(%P) failed", |
510 ngx_processes[n].pid); | |
511 } | |
512 | |
513 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, | |
514 "%s process %P exited with code %Xul", | |
515 ngx_processes[n].name, ngx_processes[n].pid, code); | |
516 | |
517 ngx_close_handle(ngx_processes[n].reopen); | |
518 ngx_close_handle(ngx_processes[n].quit); | |
519 ngx_close_handle(ngx_processes[n].term); | |
520 ngx_close_handle(h); | |
2627 | 521 |
2725 | 522 ngx_processes[n].handle = NULL; |
523 ngx_processes[n].term = NULL; | |
524 ngx_processes[n].quit = NULL; | |
525 ngx_processes[n].reopen = NULL; | |
526 | |
527 if (!ngx_processes[n].exiting && !ngx_terminate && !ngx_quit) { | |
528 | |
529 if (ngx_spawn_process(cycle, ngx_processes[n].name, n) | |
530 == NGX_INVALID_PID) | |
531 { | |
532 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
533 "can not respawn %s", ngx_processes[n].name); | |
534 | |
535 if (n == ngx_last_process - 1) { | |
536 ngx_last_process--; | |
537 } | |
538 } | |
539 } | |
2627 | 540 |
2725 | 541 goto found; |
542 } | |
543 | |
544 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unknown process handle %p", h); | |
545 | |
546 found: | |
547 | |
548 for (n = 0; n < ngx_last_process; n++) { | |
549 | |
550 ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
2921 | 551 "process: %d %P %p e:%d j:%d", |
2725 | 552 n, |
553 ngx_processes[n].pid, | |
554 ngx_processes[n].handle, | |
555 ngx_processes[n].exiting, | |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
556 ngx_processes[n].just_spawn); |
2725 | 557 |
558 if (ngx_processes[n].handle) { | |
559 return 1; | |
560 } | |
2627 | 561 } |
562 | |
563 return 0; | |
564 } | |
565 | |
566 | |
567 static void | |
2725 | 568 ngx_master_process_exit(ngx_cycle_t *cycle) |
569 { | |
570 ngx_uint_t i; | |
571 | |
572 ngx_delete_pidfile(cycle); | |
573 | |
574 ngx_close_handle(ngx_cache_manager_mutex); | |
575 ngx_close_handle(ngx_stop_event); | |
576 ngx_close_handle(ngx_quit_event); | |
577 ngx_close_handle(ngx_reopen_event); | |
578 ngx_close_handle(ngx_reload_event); | |
579 ngx_close_handle(ngx_master_process_event); | |
580 | |
581 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit"); | |
582 | |
583 for (i = 0; ngx_modules[i]; i++) { | |
584 if (ngx_modules[i]->exit_master) { | |
585 ngx_modules[i]->exit_master(cycle); | |
586 } | |
587 } | |
588 | |
589 ngx_destroy_pool(cycle->pool); | |
590 | |
591 exit(0); | |
592 } | |
593 | |
594 | |
595 static void | |
596 ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn) | |
2627 | 597 { |
2725 | 598 char wtevn[NGX_PROCESS_SYNC_NAME]; |
599 char wqevn[NGX_PROCESS_SYNC_NAME]; | |
600 char wroevn[NGX_PROCESS_SYNC_NAME]; | |
601 HANDLE mev, events[3]; | |
602 u_long nev, ev; | |
603 ngx_err_t err; | |
3352
5c43621c580a
a cache manager thread handle was overwritten by a cache loader thread handle,
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
604 ngx_tid_t wtid, cmtid, cltid; |
2725 | 605 ngx_log_t *log; |
606 | |
607 log = cycle->log; | |
608 | |
609 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "worker started"); | |
610 | |
611 ngx_sprintf((u_char *) wtevn, "ngx_worker_term_%ul%Z", ngx_pid); | |
612 events[0] = CreateEvent(NULL, 1, 0, wtevn); | |
613 if (events[0] == NULL) { | |
614 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
615 "CreateEvent(\"%s\") failed", wtevn); | |
616 goto failed; | |
617 } | |
618 | |
619 ngx_sprintf((u_char *) wqevn, "ngx_worker_quit_%ul%Z", ngx_pid); | |
620 events[1] = CreateEvent(NULL, 1, 0, wqevn); | |
621 if (events[1] == NULL) { | |
622 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
623 "CreateEvent(\"%s\") failed", wqevn); | |
624 goto failed; | |
625 } | |
626 | |
627 ngx_sprintf((u_char *) wroevn, "ngx_worker_reopen_%ul%Z", ngx_pid); | |
628 events[2] = CreateEvent(NULL, 1, 0, wroevn); | |
629 if (events[2] == NULL) { | |
630 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
631 "CreateEvent(\"%s\") failed", wroevn); | |
632 goto failed; | |
633 } | |
634 | |
635 mev = OpenEvent(EVENT_MODIFY_STATE, 0, mevn); | |
636 if (mev == NULL) { | |
637 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
638 "OpenEvent(\"%s\") failed", mevn); | |
639 goto failed; | |
640 } | |
641 | |
642 if (SetEvent(mev) == 0) { | |
643 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
644 "SetEvent(\"%s\") failed", mevn); | |
645 goto failed; | |
646 } | |
647 | |
648 | |
649 ngx_sprintf((u_char *) ngx_cache_manager_mutex_name, | |
650 "ngx_cache_manager_mutex_%s%Z", ngx_unique); | |
651 | |
652 ngx_cache_manager_mutex = OpenMutex(SYNCHRONIZE, 0, | |
653 ngx_cache_manager_mutex_name); | |
654 if (ngx_cache_manager_mutex == NULL) { | |
655 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
656 "OpenMutex(\"%s\") failed", ngx_cache_manager_mutex_name); | |
657 goto failed; | |
658 } | |
659 | |
660 ngx_cache_manager_event = CreateEvent(NULL, 1, 0, NULL); | |
661 if (ngx_cache_manager_event == NULL) { | |
662 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
663 "CreateEvent(\"ngx_cache_manager_event\") failed"); | |
664 goto failed; | |
665 } | |
666 | |
667 | |
668 if (ngx_create_thread(&wtid, ngx_worker_thread, NULL, log) != 0) { | |
669 goto failed; | |
670 } | |
671 | |
672 if (ngx_create_thread(&cmtid, ngx_cache_manager_thread, NULL, log) != 0) { | |
673 goto failed; | |
674 } | |
675 | |
3352
5c43621c580a
a cache manager thread handle was overwritten by a cache loader thread handle,
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
676 if (ngx_create_thread(&cltid, ngx_cache_loader_thread, NULL, log) != 0) { |
3022 | 677 goto failed; |
678 } | |
679 | |
2725 | 680 for ( ;; ) { |
681 ev = WaitForMultipleObjects(3, events, 0, INFINITE); | |
682 | |
683 err = ngx_errno; | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
684 ngx_time_update(); |
461 | 685 |
2725 | 686 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, |
687 "worker WaitForMultipleObjects: %ul", ev); | |
688 | |
689 if (ev == WAIT_OBJECT_0) { | |
690 ngx_terminate = 1; | |
691 ngx_log_error(NGX_LOG_NOTICE, log, 0, "exiting"); | |
692 | |
693 if (ResetEvent(events[0]) == 0) { | |
694 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
695 "ResetEvent(\"%s\") failed", wtevn); | |
696 } | |
697 | |
698 break; | |
699 } | |
700 | |
701 if (ev == WAIT_OBJECT_0 + 1) { | |
702 ngx_quit = 1; | |
703 ngx_log_error(NGX_LOG_NOTICE, log, 0, "gracefully shutting down"); | |
704 break; | |
705 } | |
706 | |
707 if (ev == WAIT_OBJECT_0 + 2) { | |
708 ngx_reopen = 1; | |
709 ngx_log_error(NGX_LOG_NOTICE, log, 0, "reopening logs"); | |
710 | |
711 if (ResetEvent(events[2]) == 0) { | |
712 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
713 "ResetEvent(\"%s\") failed", wroevn); | |
714 } | |
715 | |
716 continue; | |
717 } | |
718 | |
719 if (ev == WAIT_FAILED) { | |
720 ngx_log_error(NGX_LOG_ALERT, log, err, | |
721 "WaitForMultipleObjects() failed"); | |
722 | |
723 goto failed; | |
724 } | |
725 } | |
726 | |
727 /* wait threads */ | |
461 | 728 |
2725 | 729 if (SetEvent(ngx_cache_manager_event) == 0) { |
730 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
731 "SetEvent(\"ngx_cache_manager_event\") failed"); | |
732 } | |
733 | |
734 events[1] = wtid; | |
735 events[2] = cmtid; | |
736 | |
737 nev = 3; | |
738 | |
739 for ( ;; ) { | |
740 ev = WaitForMultipleObjects(nev, events, 0, INFINITE); | |
741 | |
742 err = ngx_errno; | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
743 ngx_time_update(); |
2725 | 744 |
745 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, | |
746 "worker exit WaitForMultipleObjects: %ul", ev); | |
747 | |
748 if (ev == WAIT_OBJECT_0) { | |
749 break; | |
750 } | |
751 | |
752 if (ev == WAIT_OBJECT_0 + 1) { | |
753 if (nev == 2) { | |
754 break; | |
755 } | |
756 | |
757 events[1] = events[2]; | |
758 nev = 2; | |
759 continue; | |
760 } | |
761 | |
762 if (ev == WAIT_OBJECT_0 + 2) { | |
763 nev = 2; | |
764 continue; | |
765 } | |
766 | |
767 if (ev == WAIT_FAILED) { | |
768 ngx_log_error(NGX_LOG_ALERT, log, err, | |
769 "WaitForMultipleObjects() failed"); | |
770 break; | |
771 } | |
461 | 772 } |
773 | |
2725 | 774 ngx_close_handle(ngx_cache_manager_event); |
775 ngx_close_handle(events[0]); | |
776 ngx_close_handle(events[1]); | |
777 ngx_close_handle(events[2]); | |
778 ngx_close_handle(mev); | |
779 | |
780 ngx_worker_process_exit(cycle); | |
781 | |
782 failed: | |
783 | |
784 exit(2); | |
785 } | |
786 | |
787 | |
788 static ngx_thread_value_t __stdcall | |
789 ngx_worker_thread(void *data) | |
790 { | |
791 ngx_int_t n; | |
792 ngx_uint_t i; | |
793 ngx_cycle_t *cycle; | |
794 ngx_connection_t *c; | |
795 | |
796 cycle = (ngx_cycle_t *) ngx_cycle; | |
797 | |
798 for (n = 0; ngx_modules[n]; n++) { | |
799 if (ngx_modules[n]->init_process) { | |
800 if (ngx_modules[n]->init_process(cycle) == NGX_ERROR) { | |
801 /* fatal */ | |
802 exit(2); | |
803 } | |
804 } | |
805 } | |
806 | |
807 while (!ngx_quit) { | |
808 | |
809 if (ngx_exiting) { | |
810 | |
811 c = cycle->connections; | |
812 | |
813 for (i = 0; i < cycle->connection_n; i++) { | |
814 | |
815 /* THREAD: lock */ | |
816 | |
817 if (c[i].fd != -1 && c[i].idle) { | |
818 c[i].close = 1; | |
819 c[i].read->handler(c[i].read); | |
820 } | |
821 } | |
822 | |
823 if (ngx_event_timer_rbtree.root | |
824 == ngx_event_timer_rbtree.sentinel) | |
825 { | |
826 break; | |
827 } | |
828 } | |
829 | |
830 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "worker cycle"); | |
831 | |
832 ngx_process_events_and_timers(cycle); | |
833 | |
834 if (ngx_terminate) { | |
835 return 0; | |
836 } | |
837 | |
838 if (ngx_quit) { | |
839 ngx_quit = 0; | |
840 | |
841 if (!ngx_exiting) { | |
842 ngx_close_listening_sockets(cycle); | |
843 ngx_exiting = 1; | |
844 } | |
845 } | |
846 | |
847 if (ngx_reopen) { | |
848 ngx_reopen = 0; | |
849 ngx_reopen_files(cycle, -1); | |
850 } | |
851 } | |
852 | |
853 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
854 | |
855 return 0; | |
856 } | |
857 | |
858 | |
859 static void | |
860 ngx_worker_process_exit(ngx_cycle_t *cycle) | |
861 { | |
862 ngx_uint_t i; | |
863 ngx_connection_t *c; | |
864 | |
865 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit"); | |
866 | |
867 for (i = 0; ngx_modules[i]; i++) { | |
868 if (ngx_modules[i]->exit_process) { | |
869 ngx_modules[i]->exit_process(cycle); | |
870 } | |
871 } | |
872 | |
873 if (ngx_exiting) { | |
874 c = cycle->connections; | |
875 for (i = 0; i < cycle->connection_n; i++) { | |
876 if (c[i].fd != -1 | |
877 && c[i].read | |
878 && !c[i].read->accept | |
879 && !c[i].read->channel | |
880 && !c[i].read->resolver) | |
881 { | |
882 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
883 "open socket #%d left in connection %ui", | |
884 c[i].fd, i); | |
885 } | |
886 } | |
461 | 887 } |
888 | |
2725 | 889 ngx_destroy_pool(cycle->pool); |
890 | |
891 exit(0); | |
892 } | |
893 | |
894 | |
895 static ngx_thread_value_t __stdcall | |
896 ngx_cache_manager_thread(void *data) | |
897 { | |
898 u_long ev; | |
899 HANDLE events[2]; | |
900 ngx_err_t err; | |
901 ngx_cycle_t *cycle; | |
902 | |
903 cycle = (ngx_cycle_t *) ngx_cycle; | |
904 | |
905 events[0] = ngx_cache_manager_event; | |
906 events[1] = ngx_cache_manager_mutex; | |
907 | |
908 for ( ;; ) { | |
909 ev = WaitForMultipleObjects(2, events, 0, INFINITE); | |
910 | |
911 err = ngx_errno; | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
912 ngx_time_update(); |
2725 | 913 |
914 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
915 "cache manager WaitForMultipleObjects: %ul", ev); | |
916 | |
917 if (ev == WAIT_FAILED) { | |
918 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
919 "WaitForMultipleObjects() failed"); | |
920 } | |
921 | |
922 /* | |
923 * ev == WAIT_OBJECT_0 | |
924 * ev == WAIT_OBJECT_0 + 1 | |
925 * ev == WAIT_ABANDONED_0 + 1 | |
926 */ | |
927 | |
928 if (ngx_terminate || ngx_quit) { | |
929 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
930 return 0; | |
931 } | |
932 | |
3021 | 933 break; |
2725 | 934 } |
935 | |
936 for ( ;; ) { | |
937 | |
938 if (ngx_terminate || ngx_quit) { | |
939 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
940 break; | |
941 } | |
942 | |
943 ngx_cache_manager_process_handler(); | |
944 } | |
945 | |
946 if (ReleaseMutex(ngx_cache_manager_mutex) == 0) { | |
947 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
948 "ReleaseMutex() failed"); | |
949 } | |
950 | |
951 return 0; | |
952 } | |
953 | |
954 | |
955 static void | |
956 ngx_cache_manager_process_handler(void) | |
957 { | |
958 u_long ev; | |
959 time_t next, n; | |
960 ngx_uint_t i; | |
961 ngx_path_t **path; | |
962 | |
963 next = 60 * 60; | |
964 | |
965 path = ngx_cycle->pathes.elts; | |
966 for (i = 0; i < ngx_cycle->pathes.nelts; i++) { | |
967 | |
968 if (path[i]->manager) { | |
969 n = path[i]->manager(path[i]->data); | |
970 | |
971 next = (n <= next) ? n : next; | |
972 | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
973 ngx_time_update(); |
2725 | 974 } |
975 } | |
976 | |
977 if (next == 0) { | |
978 next = 1; | |
979 } | |
980 | |
981 ev = WaitForSingleObject(ngx_cache_manager_event, (u_long) next * 1000); | |
982 | |
983 if (ev != WAIT_TIMEOUT) { | |
984 | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
985 ngx_time_update(); |
2725 | 986 |
987 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, | |
988 "cache manager WaitForSingleObject: %ul", ev); | |
989 } | |
990 } | |
991 | |
992 | |
3022 | 993 static ngx_thread_value_t __stdcall |
994 ngx_cache_loader_thread(void *data) | |
995 { | |
996 ngx_uint_t i; | |
997 ngx_path_t **path; | |
998 ngx_cycle_t *cycle; | |
999 | |
1000 ngx_msleep(60000); | |
1001 | |
1002 cycle = (ngx_cycle_t *) ngx_cycle; | |
1003 | |
1004 path = cycle->pathes.elts; | |
1005 for (i = 0; i < cycle->pathes.nelts; i++) { | |
1006 | |
1007 if (ngx_terminate || ngx_quit) { | |
1008 break; | |
1009 } | |
1010 | |
1011 if (path[i]->loader) { | |
1012 path[i]->loader(path[i]->data); | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
1013 ngx_time_update(); |
3022 | 1014 } |
1015 } | |
1016 | |
1017 return 0; | |
1018 } | |
1019 | |
1020 | |
2725 | 1021 void |
1022 ngx_single_process_cycle(ngx_cycle_t *cycle) | |
1023 { | |
1024 ngx_int_t i; | |
1025 ngx_tid_t tid; | |
1026 | |
1027 for (i = 0; ngx_modules[i]; i++) { | |
1028 if (ngx_modules[i]->init_process) { | |
1029 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { | |
1030 /* fatal */ | |
1031 exit(2); | |
1032 } | |
1033 } | |
1034 } | |
1035 | |
1036 ngx_process_init(cycle); | |
1037 | |
1038 ngx_console_init(cycle); | |
1039 | |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
1040 if (ngx_create_signal_events(cycle) != NGX_OK) { |
461 | 1041 exit(2); |
1042 } | |
1043 | |
2725 | 1044 if (ngx_create_thread(&tid, ngx_worker_thread, NULL, cycle->log) != 0) { |
461 | 1045 /* fatal */ |
1046 exit(2); | |
1047 } | |
1048 | |
2725 | 1049 /* STUB */ |
1050 WaitForSingleObject(ngx_stop_event, INFINITE); | |
461 | 1051 } |
1052 | |
1053 | |
2725 | 1054 ngx_int_t |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1055 ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid) |
461 | 1056 { |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1057 HANDLE ev; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1058 ngx_int_t rc; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1059 char evn[NGX_PROCESS_SYNC_NAME]; |
461 | 1060 |
3751
a4755d4fd91b
add "Global\" prefix for signal events
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
1061 ngx_sprintf((u_char *) evn, "Global\\ngx_%s_%ul%Z", sig, pid); |
2725 | 1062 |
1063 ev = OpenEvent(EVENT_MODIFY_STATE, 0, evn); | |
1064 if (ev == NULL) { | |
1065 ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, | |
1066 "OpenEvent(\"%s\") failed", evn); | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1067 return 1; |
2725 | 1068 } |
461 | 1069 |
2725 | 1070 if (SetEvent(ev) == 0) { |
1071 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
1072 "SetEvent(\"%s\") failed", evn); | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1073 rc = 1; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1074 |
2725 | 1075 } else { |
1076 rc = 0; | |
1077 } | |
1078 | |
1079 ngx_close_handle(ev); | |
1080 | |
1081 return rc; | |
1082 } | |
461 | 1083 |
1084 | |
2725 | 1085 void |
1086 ngx_close_handle(HANDLE h) | |
1087 { | |
1088 if (CloseHandle(h) == 0) { | |
1089 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
1090 "CloseHandle(%p) failed", h); | |
461 | 1091 } |
1092 } |