Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_process_cycle.c @ 3225:f649453396f5
listen default_server parameter
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 21 Oct 2009 19:18:50 +0000 |
parents | f9d97311c652 |
children | 5c43621c580a |
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); | |
16 static ngx_int_t ngx_create_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 | |
97 if (ngx_create_events(cycle) != NGX_OK) { | |
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; | |
143 ngx_time_update(0, 0); | |
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 | |
344 ngx_create_events(ngx_cycle_t *cycle) | |
345 { | |
346 ngx_sprintf((u_char *) ngx_stop_event_name, "ngx_stop_%s%Z", ngx_unique); | |
347 | |
348 ngx_stop_event = CreateEvent(NULL, 1, 0, ngx_stop_event_name); | |
349 if (ngx_stop_event == NULL) { | |
350 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
351 "CreateEvent(\"%s\") failed", ngx_stop_event_name); | |
352 return NGX_ERROR; | |
353 } | |
354 | |
355 | |
356 ngx_sprintf((u_char *) ngx_quit_event_name, "ngx_quit_%s%Z", ngx_unique); | |
357 | |
358 ngx_quit_event = CreateEvent(NULL, 1, 0, ngx_quit_event_name); | |
359 if (ngx_quit_event == NULL) { | |
360 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
361 "CreateEvent(\"%s\") failed", ngx_quit_event_name); | |
362 return NGX_ERROR; | |
363 } | |
364 | |
365 | |
366 ngx_sprintf((u_char *) ngx_reopen_event_name, | |
367 "ngx_reopen_%s%Z", ngx_unique); | |
368 | |
369 ngx_reopen_event = CreateEvent(NULL, 1, 0, ngx_reopen_event_name); | |
370 if (ngx_reopen_event == NULL) { | |
371 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
372 "CreateEvent(\"%s\") failed", ngx_reopen_event_name); | |
373 return NGX_ERROR; | |
374 } | |
375 | |
376 | |
377 ngx_sprintf((u_char *) ngx_reload_event_name, | |
378 "ngx_reload_%s%Z", ngx_unique); | |
379 | |
380 ngx_reload_event = CreateEvent(NULL, 1, 0, ngx_reload_event_name); | |
381 if (ngx_reload_event == NULL) { | |
382 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
383 "CreateEvent(\"%s\") failed", ngx_reload_event_name); | |
384 return NGX_ERROR; | |
385 } | |
386 | |
387 return NGX_OK; | |
388 } | |
389 | |
390 | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
391 static ngx_int_t |
2725 | 392 ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type) |
393 { | |
394 ngx_int_t n; | |
395 ngx_core_conf_t *ccf; | |
396 | |
397 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes"); | |
398 | |
399 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
400 | |
401 for (n = 0; n < ccf->worker_processes; n++) { | |
402 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
|
403 break; |
2725 | 404 } |
405 } | |
2922
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
406 |
f0604d0b28a6
*) exit if no workers could not be started
Igor Sysoev <igor@sysoev.ru>
parents:
2921
diff
changeset
|
407 return n; |
2627 | 408 } |
409 | |
410 | |
2725 | 411 static void |
412 ngx_reopen_worker_processes(ngx_cycle_t *cycle) | |
413 { | |
414 ngx_int_t n; | |
415 | |
416 for (n = 0; n < ngx_last_process; n++) { | |
417 | |
418 if (ngx_processes[n].handle == NULL) { | |
419 continue; | |
420 } | |
421 | |
422 if (SetEvent(ngx_processes[n].reopen) == 0) { | |
423 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
424 "SetEvent(\"%s\") failed", | |
425 ngx_processes[n].reopen_event); | |
426 } | |
427 } | |
428 } | |
429 | |
430 | |
431 static void | |
432 ngx_quit_worker_processes(ngx_cycle_t *cycle, ngx_uint_t old) | |
2627 | 433 { |
2725 | 434 ngx_int_t n; |
435 | |
436 for (n = 0; n < ngx_last_process; n++) { | |
437 | |
438 ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
2921 | 439 "process: %d %P %p e:%d j:%d", |
2725 | 440 n, |
441 ngx_processes[n].pid, | |
442 ngx_processes[n].handle, | |
443 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
|
444 ngx_processes[n].just_spawn); |
2725 | 445 |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
446 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
|
447 ngx_processes[n].just_spawn = 0; |
2725 | 448 continue; |
449 } | |
450 | |
451 if (ngx_processes[n].handle == NULL) { | |
452 continue; | |
453 } | |
454 | |
455 if (SetEvent(ngx_processes[n].quit) == 0) { | |
456 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
457 "SetEvent(\"%s\") failed", | |
458 ngx_processes[n].quit_event); | |
459 } | |
460 | |
461 ngx_processes[n].exiting = 1; | |
462 } | |
463 } | |
464 | |
465 | |
466 static void | |
467 ngx_terminate_worker_processes(ngx_cycle_t *cycle) | |
468 { | |
469 ngx_int_t n; | |
470 | |
471 for (n = 0; n < ngx_last_process; n++) { | |
472 | |
473 if (ngx_processes[n].handle == NULL) { | |
474 continue; | |
475 } | |
476 | |
477 if (TerminateProcess(ngx_processes[n].handle, 0) == 0) { | |
478 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
479 "TerminateProcess(\"%p\") failed", | |
480 ngx_processes[n].handle); | |
481 } | |
482 | |
483 ngx_processes[n].exiting = 1; | |
2627 | 484 |
2725 | 485 ngx_close_handle(ngx_processes[n].reopen); |
486 ngx_close_handle(ngx_processes[n].quit); | |
487 ngx_close_handle(ngx_processes[n].term); | |
488 ngx_close_handle(ngx_processes[n].handle); | |
489 } | |
490 } | |
491 | |
492 | |
493 static ngx_uint_t | |
494 ngx_reap_worker(ngx_cycle_t *cycle, HANDLE h) | |
495 { | |
496 u_long code; | |
497 ngx_int_t n; | |
498 | |
499 for (n = 0; n < ngx_last_process; n++) { | |
500 | |
501 if (ngx_processes[n].handle != h) { | |
502 continue; | |
503 } | |
504 | |
505 if (GetExitCodeProcess(h, &code) == 0) { | |
2908
234a8248812c
log GetExitCodeProcess()'s errno
Igor Sysoev <igor@sysoev.ru>
parents:
2823
diff
changeset
|
506 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
2725 | 507 "GetExitCodeProcess(%P) failed", |
508 ngx_processes[n].pid); | |
509 } | |
510 | |
511 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, | |
512 "%s process %P exited with code %Xul", | |
513 ngx_processes[n].name, ngx_processes[n].pid, code); | |
514 | |
515 ngx_close_handle(ngx_processes[n].reopen); | |
516 ngx_close_handle(ngx_processes[n].quit); | |
517 ngx_close_handle(ngx_processes[n].term); | |
518 ngx_close_handle(h); | |
2627 | 519 |
2725 | 520 ngx_processes[n].handle = NULL; |
521 ngx_processes[n].term = NULL; | |
522 ngx_processes[n].quit = NULL; | |
523 ngx_processes[n].reopen = NULL; | |
524 | |
525 if (!ngx_processes[n].exiting && !ngx_terminate && !ngx_quit) { | |
526 | |
527 if (ngx_spawn_process(cycle, ngx_processes[n].name, n) | |
528 == NGX_INVALID_PID) | |
529 { | |
530 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
531 "can not respawn %s", ngx_processes[n].name); | |
532 | |
533 if (n == ngx_last_process - 1) { | |
534 ngx_last_process--; | |
535 } | |
536 } | |
537 } | |
2627 | 538 |
2725 | 539 goto found; |
540 } | |
541 | |
542 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unknown process handle %p", h); | |
543 | |
544 found: | |
545 | |
546 for (n = 0; n < ngx_last_process; n++) { | |
547 | |
548 ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
2921 | 549 "process: %d %P %p e:%d j:%d", |
2725 | 550 n, |
551 ngx_processes[n].pid, | |
552 ngx_processes[n].handle, | |
553 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
|
554 ngx_processes[n].just_spawn); |
2725 | 555 |
556 if (ngx_processes[n].handle) { | |
557 return 1; | |
558 } | |
2627 | 559 } |
560 | |
561 return 0; | |
562 } | |
563 | |
564 | |
565 static void | |
2725 | 566 ngx_master_process_exit(ngx_cycle_t *cycle) |
567 { | |
568 ngx_uint_t i; | |
569 | |
570 ngx_delete_pidfile(cycle); | |
571 | |
572 ngx_close_handle(ngx_cache_manager_mutex); | |
573 ngx_close_handle(ngx_stop_event); | |
574 ngx_close_handle(ngx_quit_event); | |
575 ngx_close_handle(ngx_reopen_event); | |
576 ngx_close_handle(ngx_reload_event); | |
577 ngx_close_handle(ngx_master_process_event); | |
578 | |
579 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit"); | |
580 | |
581 for (i = 0; ngx_modules[i]; i++) { | |
582 if (ngx_modules[i]->exit_master) { | |
583 ngx_modules[i]->exit_master(cycle); | |
584 } | |
585 } | |
586 | |
587 ngx_destroy_pool(cycle->pool); | |
588 | |
589 exit(0); | |
590 } | |
591 | |
592 | |
593 static void | |
594 ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn) | |
2627 | 595 { |
2725 | 596 char wtevn[NGX_PROCESS_SYNC_NAME]; |
597 char wqevn[NGX_PROCESS_SYNC_NAME]; | |
598 char wroevn[NGX_PROCESS_SYNC_NAME]; | |
599 HANDLE mev, events[3]; | |
600 u_long nev, ev; | |
601 ngx_err_t err; | |
602 ngx_tid_t wtid, cmtid; | |
603 ngx_log_t *log; | |
604 | |
605 log = cycle->log; | |
606 | |
607 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "worker started"); | |
608 | |
609 ngx_sprintf((u_char *) wtevn, "ngx_worker_term_%ul%Z", ngx_pid); | |
610 events[0] = CreateEvent(NULL, 1, 0, wtevn); | |
611 if (events[0] == NULL) { | |
612 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
613 "CreateEvent(\"%s\") failed", wtevn); | |
614 goto failed; | |
615 } | |
616 | |
617 ngx_sprintf((u_char *) wqevn, "ngx_worker_quit_%ul%Z", ngx_pid); | |
618 events[1] = CreateEvent(NULL, 1, 0, wqevn); | |
619 if (events[1] == NULL) { | |
620 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
621 "CreateEvent(\"%s\") failed", wqevn); | |
622 goto failed; | |
623 } | |
624 | |
625 ngx_sprintf((u_char *) wroevn, "ngx_worker_reopen_%ul%Z", ngx_pid); | |
626 events[2] = CreateEvent(NULL, 1, 0, wroevn); | |
627 if (events[2] == NULL) { | |
628 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
629 "CreateEvent(\"%s\") failed", wroevn); | |
630 goto failed; | |
631 } | |
632 | |
633 mev = OpenEvent(EVENT_MODIFY_STATE, 0, mevn); | |
634 if (mev == NULL) { | |
635 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
636 "OpenEvent(\"%s\") failed", mevn); | |
637 goto failed; | |
638 } | |
639 | |
640 if (SetEvent(mev) == 0) { | |
641 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
642 "SetEvent(\"%s\") failed", mevn); | |
643 goto failed; | |
644 } | |
645 | |
646 | |
647 ngx_sprintf((u_char *) ngx_cache_manager_mutex_name, | |
648 "ngx_cache_manager_mutex_%s%Z", ngx_unique); | |
649 | |
650 ngx_cache_manager_mutex = OpenMutex(SYNCHRONIZE, 0, | |
651 ngx_cache_manager_mutex_name); | |
652 if (ngx_cache_manager_mutex == NULL) { | |
653 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
654 "OpenMutex(\"%s\") failed", ngx_cache_manager_mutex_name); | |
655 goto failed; | |
656 } | |
657 | |
658 ngx_cache_manager_event = CreateEvent(NULL, 1, 0, NULL); | |
659 if (ngx_cache_manager_event == NULL) { | |
660 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
661 "CreateEvent(\"ngx_cache_manager_event\") failed"); | |
662 goto failed; | |
663 } | |
664 | |
665 | |
666 if (ngx_create_thread(&wtid, ngx_worker_thread, NULL, log) != 0) { | |
667 goto failed; | |
668 } | |
669 | |
670 if (ngx_create_thread(&cmtid, ngx_cache_manager_thread, NULL, log) != 0) { | |
671 goto failed; | |
672 } | |
673 | |
3022 | 674 if (ngx_create_thread(&cmtid, ngx_cache_loader_thread, NULL, log) != 0) { |
675 goto failed; | |
676 } | |
677 | |
2725 | 678 for ( ;; ) { |
679 ev = WaitForMultipleObjects(3, events, 0, INFINITE); | |
680 | |
681 err = ngx_errno; | |
682 ngx_time_update(0, 0); | |
461 | 683 |
2725 | 684 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, |
685 "worker WaitForMultipleObjects: %ul", ev); | |
686 | |
687 if (ev == WAIT_OBJECT_0) { | |
688 ngx_terminate = 1; | |
689 ngx_log_error(NGX_LOG_NOTICE, log, 0, "exiting"); | |
690 | |
691 if (ResetEvent(events[0]) == 0) { | |
692 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
693 "ResetEvent(\"%s\") failed", wtevn); | |
694 } | |
695 | |
696 break; | |
697 } | |
698 | |
699 if (ev == WAIT_OBJECT_0 + 1) { | |
700 ngx_quit = 1; | |
701 ngx_log_error(NGX_LOG_NOTICE, log, 0, "gracefully shutting down"); | |
702 break; | |
703 } | |
704 | |
705 if (ev == WAIT_OBJECT_0 + 2) { | |
706 ngx_reopen = 1; | |
707 ngx_log_error(NGX_LOG_NOTICE, log, 0, "reopening logs"); | |
708 | |
709 if (ResetEvent(events[2]) == 0) { | |
710 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
711 "ResetEvent(\"%s\") failed", wroevn); | |
712 } | |
713 | |
714 continue; | |
715 } | |
716 | |
717 if (ev == WAIT_FAILED) { | |
718 ngx_log_error(NGX_LOG_ALERT, log, err, | |
719 "WaitForMultipleObjects() failed"); | |
720 | |
721 goto failed; | |
722 } | |
723 } | |
724 | |
725 /* wait threads */ | |
461 | 726 |
2725 | 727 if (SetEvent(ngx_cache_manager_event) == 0) { |
728 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
729 "SetEvent(\"ngx_cache_manager_event\") failed"); | |
730 } | |
731 | |
732 events[1] = wtid; | |
733 events[2] = cmtid; | |
734 | |
735 nev = 3; | |
736 | |
737 for ( ;; ) { | |
738 ev = WaitForMultipleObjects(nev, events, 0, INFINITE); | |
739 | |
740 err = ngx_errno; | |
741 ngx_time_update(0, 0); | |
742 | |
743 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, | |
744 "worker exit WaitForMultipleObjects: %ul", ev); | |
745 | |
746 if (ev == WAIT_OBJECT_0) { | |
747 break; | |
748 } | |
749 | |
750 if (ev == WAIT_OBJECT_0 + 1) { | |
751 if (nev == 2) { | |
752 break; | |
753 } | |
754 | |
755 events[1] = events[2]; | |
756 nev = 2; | |
757 continue; | |
758 } | |
759 | |
760 if (ev == WAIT_OBJECT_0 + 2) { | |
761 nev = 2; | |
762 continue; | |
763 } | |
764 | |
765 if (ev == WAIT_FAILED) { | |
766 ngx_log_error(NGX_LOG_ALERT, log, err, | |
767 "WaitForMultipleObjects() failed"); | |
768 break; | |
769 } | |
461 | 770 } |
771 | |
2725 | 772 ngx_close_handle(ngx_cache_manager_event); |
773 ngx_close_handle(events[0]); | |
774 ngx_close_handle(events[1]); | |
775 ngx_close_handle(events[2]); | |
776 ngx_close_handle(mev); | |
777 | |
778 ngx_worker_process_exit(cycle); | |
779 | |
780 failed: | |
781 | |
782 exit(2); | |
783 } | |
784 | |
785 | |
786 static ngx_thread_value_t __stdcall | |
787 ngx_worker_thread(void *data) | |
788 { | |
789 ngx_int_t n; | |
790 ngx_uint_t i; | |
791 ngx_cycle_t *cycle; | |
792 ngx_connection_t *c; | |
793 | |
794 cycle = (ngx_cycle_t *) ngx_cycle; | |
795 | |
796 for (n = 0; ngx_modules[n]; n++) { | |
797 if (ngx_modules[n]->init_process) { | |
798 if (ngx_modules[n]->init_process(cycle) == NGX_ERROR) { | |
799 /* fatal */ | |
800 exit(2); | |
801 } | |
802 } | |
803 } | |
804 | |
805 while (!ngx_quit) { | |
806 | |
807 if (ngx_exiting) { | |
808 | |
809 c = cycle->connections; | |
810 | |
811 for (i = 0; i < cycle->connection_n; i++) { | |
812 | |
813 /* THREAD: lock */ | |
814 | |
815 if (c[i].fd != -1 && c[i].idle) { | |
816 c[i].close = 1; | |
817 c[i].read->handler(c[i].read); | |
818 } | |
819 } | |
820 | |
821 if (ngx_event_timer_rbtree.root | |
822 == ngx_event_timer_rbtree.sentinel) | |
823 { | |
824 break; | |
825 } | |
826 } | |
827 | |
828 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "worker cycle"); | |
829 | |
830 ngx_process_events_and_timers(cycle); | |
831 | |
832 if (ngx_terminate) { | |
833 return 0; | |
834 } | |
835 | |
836 if (ngx_quit) { | |
837 ngx_quit = 0; | |
838 | |
839 if (!ngx_exiting) { | |
840 ngx_close_listening_sockets(cycle); | |
841 ngx_exiting = 1; | |
842 } | |
843 } | |
844 | |
845 if (ngx_reopen) { | |
846 ngx_reopen = 0; | |
847 ngx_reopen_files(cycle, -1); | |
848 } | |
849 } | |
850 | |
851 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
852 | |
853 return 0; | |
854 } | |
855 | |
856 | |
857 static void | |
858 ngx_worker_process_exit(ngx_cycle_t *cycle) | |
859 { | |
860 ngx_uint_t i; | |
861 ngx_connection_t *c; | |
862 | |
863 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit"); | |
864 | |
865 for (i = 0; ngx_modules[i]; i++) { | |
866 if (ngx_modules[i]->exit_process) { | |
867 ngx_modules[i]->exit_process(cycle); | |
868 } | |
869 } | |
870 | |
871 if (ngx_exiting) { | |
872 c = cycle->connections; | |
873 for (i = 0; i < cycle->connection_n; i++) { | |
874 if (c[i].fd != -1 | |
875 && c[i].read | |
876 && !c[i].read->accept | |
877 && !c[i].read->channel | |
878 && !c[i].read->resolver) | |
879 { | |
880 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
881 "open socket #%d left in connection %ui", | |
882 c[i].fd, i); | |
883 } | |
884 } | |
461 | 885 } |
886 | |
2725 | 887 ngx_destroy_pool(cycle->pool); |
888 | |
889 exit(0); | |
890 } | |
891 | |
892 | |
893 static ngx_thread_value_t __stdcall | |
894 ngx_cache_manager_thread(void *data) | |
895 { | |
896 u_long ev; | |
897 HANDLE events[2]; | |
898 ngx_err_t err; | |
899 ngx_cycle_t *cycle; | |
900 | |
901 cycle = (ngx_cycle_t *) ngx_cycle; | |
902 | |
903 events[0] = ngx_cache_manager_event; | |
904 events[1] = ngx_cache_manager_mutex; | |
905 | |
906 for ( ;; ) { | |
907 ev = WaitForMultipleObjects(2, events, 0, INFINITE); | |
908 | |
909 err = ngx_errno; | |
910 ngx_time_update(0, 0); | |
911 | |
912 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
913 "cache manager WaitForMultipleObjects: %ul", ev); | |
914 | |
915 if (ev == WAIT_FAILED) { | |
916 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
917 "WaitForMultipleObjects() failed"); | |
918 } | |
919 | |
920 /* | |
921 * ev == WAIT_OBJECT_0 | |
922 * ev == WAIT_OBJECT_0 + 1 | |
923 * ev == WAIT_ABANDONED_0 + 1 | |
924 */ | |
925 | |
926 if (ngx_terminate || ngx_quit) { | |
927 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
928 return 0; | |
929 } | |
930 | |
3021 | 931 break; |
2725 | 932 } |
933 | |
934 for ( ;; ) { | |
935 | |
936 if (ngx_terminate || ngx_quit) { | |
937 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | |
938 break; | |
939 } | |
940 | |
941 ngx_cache_manager_process_handler(); | |
942 } | |
943 | |
944 if (ReleaseMutex(ngx_cache_manager_mutex) == 0) { | |
945 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
946 "ReleaseMutex() failed"); | |
947 } | |
948 | |
949 return 0; | |
950 } | |
951 | |
952 | |
953 static void | |
954 ngx_cache_manager_process_handler(void) | |
955 { | |
956 u_long ev; | |
957 time_t next, n; | |
958 ngx_uint_t i; | |
959 ngx_path_t **path; | |
960 | |
961 next = 60 * 60; | |
962 | |
963 path = ngx_cycle->pathes.elts; | |
964 for (i = 0; i < ngx_cycle->pathes.nelts; i++) { | |
965 | |
966 if (path[i]->manager) { | |
967 n = path[i]->manager(path[i]->data); | |
968 | |
969 next = (n <= next) ? n : next; | |
970 | |
971 ngx_time_update(0, 0); | |
972 } | |
973 } | |
974 | |
975 if (next == 0) { | |
976 next = 1; | |
977 } | |
978 | |
979 ev = WaitForSingleObject(ngx_cache_manager_event, (u_long) next * 1000); | |
980 | |
981 if (ev != WAIT_TIMEOUT) { | |
982 | |
983 ngx_time_update(0, 0); | |
984 | |
985 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, | |
986 "cache manager WaitForSingleObject: %ul", ev); | |
987 } | |
988 } | |
989 | |
990 | |
3022 | 991 static ngx_thread_value_t __stdcall |
992 ngx_cache_loader_thread(void *data) | |
993 { | |
994 ngx_uint_t i; | |
995 ngx_path_t **path; | |
996 ngx_cycle_t *cycle; | |
997 | |
998 ngx_msleep(60000); | |
999 | |
1000 cycle = (ngx_cycle_t *) ngx_cycle; | |
1001 | |
1002 path = cycle->pathes.elts; | |
1003 for (i = 0; i < cycle->pathes.nelts; i++) { | |
1004 | |
1005 if (ngx_terminate || ngx_quit) { | |
1006 break; | |
1007 } | |
1008 | |
1009 if (path[i]->loader) { | |
1010 path[i]->loader(path[i]->data); | |
1011 ngx_time_update(0, 0); | |
1012 } | |
1013 } | |
1014 | |
1015 return 0; | |
1016 } | |
1017 | |
1018 | |
2725 | 1019 void |
1020 ngx_single_process_cycle(ngx_cycle_t *cycle) | |
1021 { | |
1022 ngx_int_t i; | |
1023 ngx_tid_t tid; | |
1024 | |
1025 for (i = 0; ngx_modules[i]; i++) { | |
1026 if (ngx_modules[i]->init_process) { | |
1027 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { | |
1028 /* fatal */ | |
1029 exit(2); | |
1030 } | |
1031 } | |
1032 } | |
1033 | |
1034 ngx_process_init(cycle); | |
1035 | |
1036 ngx_console_init(cycle); | |
1037 | |
1038 if (ngx_create_events(cycle) != NGX_OK) { | |
461 | 1039 exit(2); |
1040 } | |
1041 | |
2725 | 1042 if (ngx_create_thread(&tid, ngx_worker_thread, NULL, cycle->log) != 0) { |
461 | 1043 /* fatal */ |
1044 exit(2); | |
1045 } | |
1046 | |
2725 | 1047 /* STUB */ |
1048 WaitForSingleObject(ngx_stop_event, INFINITE); | |
461 | 1049 } |
1050 | |
1051 | |
2725 | 1052 ngx_int_t |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1053 ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid) |
461 | 1054 { |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1055 HANDLE ev; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1056 ngx_int_t rc; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1057 char evn[NGX_PROCESS_SYNC_NAME]; |
461 | 1058 |
2725 | 1059 ngx_sprintf((u_char *) evn, "ngx_%s_%ul%Z", sig, pid); |
1060 | |
1061 ev = OpenEvent(EVENT_MODIFY_STATE, 0, evn); | |
1062 if (ev == NULL) { | |
1063 ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, | |
1064 "OpenEvent(\"%s\") failed", evn); | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1065 return 1; |
2725 | 1066 } |
461 | 1067 |
2725 | 1068 if (SetEvent(ev) == 0) { |
1069 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
1070 "SetEvent(\"%s\") failed", evn); | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1071 rc = 1; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1072 |
2725 | 1073 } else { |
1074 rc = 0; | |
1075 } | |
1076 | |
1077 ngx_close_handle(ev); | |
1078 | |
1079 return rc; | |
1080 } | |
461 | 1081 |
1082 | |
2725 | 1083 void |
1084 ngx_close_handle(HANDLE h) | |
1085 { | |
1086 if (CloseHandle(h) == 0) { | |
1087 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
1088 "CloseHandle(%p) failed", h); | |
461 | 1089 } |
1090 } |