Mercurial > hg > nginx-mail
comparison src/os/unix/ngx_process_cycle.c @ 503:c8cfb6c462ef NGINX_0_7_44
nginx 0.7.44
*) Feature: the ngx_http_proxy_module preliminary cache support.
*) Feature: the --with-pcre option in the configure.
*) Feature: the "try_files" directive is now allowed on the server
block level.
*) Bugfix: the "try_files" directive handled incorrectly a query string
in a fallback parameter.
*) Bugfix: the "try_files" directive might test incorrectly directories.
*) Bugfix: if there is the single server for given address:port pair,
then captures in regular expressions in a "server_name" directive
did not work.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 23 Mar 2009 00:00:00 +0300 |
parents | fc5ebf0e5f98 |
children | 56baf312c1b5 |
comparison
equal
deleted
inserted
replaced
502:51cb914e6d3a | 503:c8cfb6c462ef |
---|---|
10 #include <ngx_channel.h> | 10 #include <ngx_channel.h> |
11 | 11 |
12 | 12 |
13 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, | 13 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, |
14 ngx_int_t type); | 14 ngx_int_t type); |
15 static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type); | 15 static void ngx_start_cleaner_process(ngx_cycle_t *cycle, ngx_int_t type); |
16 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); | 16 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); |
17 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); | 17 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); |
18 static void ngx_master_process_exit(ngx_cycle_t *cycle); | 18 static void ngx_master_process_exit(ngx_cycle_t *cycle); |
19 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 19 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
20 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); | 20 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); |
22 static void ngx_channel_handler(ngx_event_t *ev); | 22 static void ngx_channel_handler(ngx_event_t *ev); |
23 #if (NGX_THREADS) | 23 #if (NGX_THREADS) |
24 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); | 24 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); |
25 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); | 25 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); |
26 #endif | 26 #endif |
27 #if 0 | 27 static void ngx_cleaner_process_cycle(ngx_cycle_t *cycle, void *data); |
28 static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data); | 28 static void ngx_cleaner_process_handler(ngx_event_t *ev); |
29 #endif | |
30 | 29 |
31 | 30 |
32 ngx_uint_t ngx_process; | 31 ngx_uint_t ngx_process; |
33 ngx_pid_t ngx_pid; | 32 ngx_pid_t ngx_pid; |
34 ngx_uint_t ngx_threaded; | 33 ngx_uint_t ngx_threaded; |
121 | 120 |
122 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 121 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
123 | 122 |
124 ngx_start_worker_processes(cycle, ccf->worker_processes, | 123 ngx_start_worker_processes(cycle, ccf->worker_processes, |
125 NGX_PROCESS_RESPAWN); | 124 NGX_PROCESS_RESPAWN); |
126 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); | 125 ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); |
127 | 126 |
128 ngx_new_binary = 0; | 127 ngx_new_binary = 0; |
129 delay = 0; | 128 delay = 0; |
130 live = 1; | 129 live = 1; |
131 | 130 |
202 ngx_reconfigure = 0; | 201 ngx_reconfigure = 0; |
203 | 202 |
204 if (ngx_new_binary) { | 203 if (ngx_new_binary) { |
205 ngx_start_worker_processes(cycle, ccf->worker_processes, | 204 ngx_start_worker_processes(cycle, ccf->worker_processes, |
206 NGX_PROCESS_RESPAWN); | 205 NGX_PROCESS_RESPAWN); |
207 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); | 206 ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); |
208 ngx_noaccepting = 0; | 207 ngx_noaccepting = 0; |
209 | 208 |
210 continue; | 209 continue; |
211 } | 210 } |
212 | 211 |
221 ngx_cycle = cycle; | 220 ngx_cycle = cycle; |
222 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, | 221 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, |
223 ngx_core_module); | 222 ngx_core_module); |
224 ngx_start_worker_processes(cycle, ccf->worker_processes, | 223 ngx_start_worker_processes(cycle, ccf->worker_processes, |
225 NGX_PROCESS_JUST_RESPAWN); | 224 NGX_PROCESS_JUST_RESPAWN); |
226 ngx_start_garbage_collector(cycle, NGX_PROCESS_JUST_RESPAWN); | 225 ngx_start_cleaner_process(cycle, NGX_PROCESS_JUST_RESPAWN); |
227 live = 1; | 226 live = 1; |
228 ngx_signal_worker_processes(cycle, | 227 ngx_signal_worker_processes(cycle, |
229 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | 228 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); |
230 } | 229 } |
231 | 230 |
232 if (ngx_restart) { | 231 if (ngx_restart) { |
233 ngx_restart = 0; | 232 ngx_restart = 0; |
234 ngx_start_worker_processes(cycle, ccf->worker_processes, | 233 ngx_start_worker_processes(cycle, ccf->worker_processes, |
235 NGX_PROCESS_RESPAWN); | 234 NGX_PROCESS_RESPAWN); |
236 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); | 235 ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); |
237 live = 1; | 236 live = 1; |
238 } | 237 } |
239 | 238 |
240 if (ngx_reopen) { | 239 if (ngx_reopen) { |
241 ngx_reopen = 0; | 240 ngx_reopen = 0; |
359 } | 358 } |
360 } | 359 } |
361 | 360 |
362 | 361 |
363 static void | 362 static void |
364 ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type) | 363 ngx_start_cleaner_process(ngx_cycle_t *cycle, ngx_int_t type) |
365 { | 364 { |
366 #if 0 | 365 ngx_int_t i; |
367 ngx_int_t i; | 366 ngx_uint_t n; |
368 ngx_channel_t ch; | 367 ngx_path_t **path; |
369 | 368 ngx_channel_t ch; |
370 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start garbage collector"); | 369 |
370 path = ngx_cycle->pathes.elts; | |
371 for (n = 0; n < ngx_cycle->pathes.nelts; n++) { | |
372 if (path[n]->cleaner) { | |
373 goto start; | |
374 } | |
375 } | |
376 | |
377 return; | |
378 | |
379 start: | |
371 | 380 |
372 ch.command = NGX_CMD_OPEN_CHANNEL; | 381 ch.command = NGX_CMD_OPEN_CHANNEL; |
373 | 382 |
374 ngx_spawn_process(cycle, ngx_garbage_collector_cycle, NULL, | 383 ngx_spawn_process(cycle, ngx_cleaner_process_cycle, NULL, |
375 "garbage collector", type); | 384 "cleaner process", type); |
376 | 385 |
377 ch.pid = ngx_processes[ngx_process_slot].pid; | 386 ch.pid = ngx_processes[ngx_process_slot].pid; |
378 ch.slot = ngx_process_slot; | 387 ch.slot = ngx_process_slot; |
379 ch.fd = ngx_processes[ngx_process_slot].channel[0]; | 388 ch.fd = ngx_processes[ngx_process_slot].channel[0]; |
380 | 389 |
396 /* TODO: NGX_AGAIN */ | 405 /* TODO: NGX_AGAIN */ |
397 | 406 |
398 ngx_write_channel(ngx_processes[i].channel[0], | 407 ngx_write_channel(ngx_processes[i].channel[0], |
399 &ch, sizeof(ngx_channel_t), cycle->log); | 408 &ch, sizeof(ngx_channel_t), cycle->log); |
400 } | 409 } |
401 #endif | |
402 } | 410 } |
403 | 411 |
404 | 412 |
405 static void | 413 static void |
406 ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo) | 414 ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo) |
1252 } | 1260 } |
1253 | 1261 |
1254 #endif | 1262 #endif |
1255 | 1263 |
1256 | 1264 |
1257 #if 0 | |
1258 | |
1259 static void | 1265 static void |
1260 ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data) | 1266 ngx_cleaner_process_cycle(ngx_cycle_t *cycle, void *data) |
1261 { | 1267 { |
1262 ngx_uint_t i; | 1268 void *ident[4]; |
1263 ngx_gc_t ctx; | 1269 ngx_event_t ev; |
1264 ngx_path_t **path; | 1270 |
1265 ngx_event_t *ev; | 1271 cycle->connection_n = 512; |
1266 | 1272 |
1267 ngx_worker_process_init(cycle, 0); | 1273 ngx_worker_process_init(cycle, 0); |
1268 | 1274 |
1269 ev = &cycle->read_events0[ngx_channel]; | 1275 ngx_close_listening_sockets(cycle); |
1270 | 1276 |
1271 ngx_accept_mutex = NULL; | 1277 ngx_memzero(&ev, sizeof(ngx_event_t)); |
1272 | 1278 ev.handler = ngx_cleaner_process_handler; |
1273 ngx_setproctitle("garbage collector"); | 1279 ev.data = ident; |
1274 | 1280 ev.log = cycle->log; |
1275 #if 0 | 1281 ident[3] = (void *) -1; |
1276 ngx_add_timer(ev, 60 * 1000); | 1282 |
1277 #endif | 1283 ngx_use_accept_mutex = 0; |
1284 | |
1285 ngx_setproctitle("cleaner process"); | |
1286 | |
1287 ngx_add_timer(&ev, 0); | |
1278 | 1288 |
1279 for ( ;; ) { | 1289 for ( ;; ) { |
1280 | 1290 |
1281 if (ngx_terminate || ngx_quit) { | 1291 if (ngx_terminate || ngx_quit) { |
1282 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | 1292 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); |
1287 ngx_reopen = 0; | 1297 ngx_reopen = 0; |
1288 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); | 1298 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); |
1289 ngx_reopen_files(cycle, -1); | 1299 ngx_reopen_files(cycle, -1); |
1290 } | 1300 } |
1291 | 1301 |
1292 path = cycle->pathes.elts; | |
1293 for (i = 0; i < cycle->pathes.nelts; i++) { | |
1294 ctx.path = path[i]; | |
1295 ctx.log = cycle->log; | |
1296 ctx.handler = path[i]->cleaner; | |
1297 | |
1298 ngx_collect_garbage(&ctx, &path[i]->name, 0); | |
1299 } | |
1300 | |
1301 ngx_add_timer(ev, 60 * 60 * 1000); | |
1302 | |
1303 ngx_process_events_and_timers(cycle); | 1302 ngx_process_events_and_timers(cycle); |
1304 } | 1303 } |
1305 } | 1304 } |
1306 | 1305 |
1307 #endif | 1306 |
1307 static void | |
1308 ngx_cleaner_process_handler(ngx_event_t *ev) | |
1309 { | |
1310 time_t next, n; | |
1311 ngx_uint_t i; | |
1312 ngx_path_t **path; | |
1313 | |
1314 next = 60 * 60; | |
1315 | |
1316 path = ngx_cycle->pathes.elts; | |
1317 for (i = 0; i < ngx_cycle->pathes.nelts; i++) { | |
1318 | |
1319 if (path[i]->cleaner) { | |
1320 n = path[i]->cleaner(path[i]->data); | |
1321 | |
1322 next = (n <= next) ? n : next; | |
1323 | |
1324 ngx_time_update(0, 0); | |
1325 } | |
1326 } | |
1327 | |
1328 if (next == 0) { | |
1329 next = 1; | |
1330 } | |
1331 | |
1332 ngx_add_timer(ev, next * 1000); | |
1333 } |