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