comparison src/core/nginx.c @ 236:86e473b5641e

nginx-0.0.1-2004-01-22-09:47:28 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 22 Jan 2004 06:47:28 +0000
parents cd71b95716b4
children 8d5cce3ae221
comparison
equal deleted inserted replaced
235:6bd5d25b6744 236:86e473b5641e
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <nginx.h> 5 #include <nginx.h>
6 6
7 7
8 typedef struct { 8 typedef struct {
9 int daemon; 9 ngx_flag_t daemon;
10 int master; 10 ngx_flag_t master;
11 uid_t user; 11 ngx_flag_t worker_reopen;
12 gid_t group; 12 uid_t user;
13 ngx_str_t pid; 13 gid_t group;
14 ngx_str_t newpid; 14 ngx_str_t pid;
15 ngx_str_t newpid;
15 } ngx_core_conf_t; 16 } ngx_core_conf_t;
16 17
17 18
18 typedef struct { 19 typedef struct {
19 ngx_file_t pid; 20 ngx_file_t pid;
52 { ngx_string("master_process"), 53 { ngx_string("master_process"),
53 NGX_MAIN_CONF|NGX_CONF_TAKE1, 54 NGX_MAIN_CONF|NGX_CONF_TAKE1,
54 ngx_conf_set_core_flag_slot, 55 ngx_conf_set_core_flag_slot,
55 0, 56 0,
56 offsetof(ngx_core_conf_t, master), 57 offsetof(ngx_core_conf_t, master),
58 NULL },
59
60 { ngx_string("worker_reopen"),
61 NGX_MAIN_CONF|NGX_CONF_TAKE1,
62 ngx_conf_set_core_flag_slot,
63 0,
64 offsetof(ngx_core_conf_t, worker_reopen),
57 NULL }, 65 NULL },
58 66
59 ngx_null_command 67 ngx_null_command
60 }; 68 };
61 69
219 227
220 /* TODO: broken single process */ 228 /* TODO: broken single process */
221 229
222 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) 230 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
223 { 231 {
224 int signo; 232 int signo;
225 char *name; 233 char *name;
226 sigset_t set, wset; 234 sigset_t set, wset;
227 struct timeval tv; 235 struct timeval tv;
228 ngx_uint_t i, live, sent; 236 ngx_uint_t i, live, sent;
229 ngx_msec_t delay; 237 ngx_msec_t delay;
238 ngx_core_conf_t *ccf;
230 239
231 delay = 125; 240 delay = 125;
232 241
233 sigemptyset(&set); 242 sigemptyset(&set);
234 sigaddset(&set, SIGCHLD); 243 sigaddset(&set, SIGCHLD);
271 } 280 }
272 } 281 }
273 } 282 }
274 } 283 }
275 284
285 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
286 ngx_core_module);
287
276 /* a cycle with the same configuration because a new one is invalid */ 288 /* a cycle with the same configuration because a new one is invalid */
277 289
278 for ( ;; ) { 290 for ( ;; ) {
279 291
280 /* an event loop */ 292 /* an event loop */
338 } else { /* NGX_PROCESS_SINGLE */ 350 } else { /* NGX_PROCESS_SINGLE */
339 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 351 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
340 "worker cycle"); 352 "worker cycle");
341 353
342 ngx_process_events(cycle->log); 354 ngx_process_events(cycle->log);
355 live = 0;
343 } 356 }
344 357
345 if (ngx_reap) { 358 if (ngx_reap) {
359 ngx_reap = 0;
346 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 360 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
361
347 "reap childs"); 362 "reap childs");
348 363
349 live = 0; 364 live = 0;
350 for (i = 0; i < ngx_last_process; i++) { 365 for (i = 0; i < ngx_last_process; i++) {
351 366
436 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, 451 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
437 "reconfiguring"); 452 "reconfiguring");
438 } 453 }
439 454
440 if (ngx_reopen) { 455 if (ngx_reopen) {
441 /* STUB */ 456 if (ngx_process == NGX_PROCESS_MASTER) {
442 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); 457 if (ccf->worker_reopen > 0) {
458 signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
459 ngx_reopen = 0;
460 } else {
461 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
462 }
463
464 } else { /* NGX_PROCESS_SINGLE */
465 ngx_reopen = 0;
466 }
443 467
444 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, 468 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
445 "reopening logs"); 469 "reopening logs");
446 ngx_reopen_files(cycle); 470 ngx_reopen_files(cycle);
447 } 471 }
466 for (i = 0; i < ngx_last_process; i++) { 490 for (i = 0; i < ngx_last_process; i++) {
467 491
468 if (ngx_processes[i].signal == 0) { 492 if (ngx_processes[i].signal == 0) {
469 continue; 493 continue;
470 } 494 }
471
472 sent = 1;
473 495
474 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, 496 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
475 "kill (" PID_T_FMT ", %d)" , 497 "kill (" PID_T_FMT ", %d)" ,
476 ngx_processes[i].pid, 498 ngx_processes[i].pid,
477 ngx_processes[i].signal); 499 ngx_processes[i].signal);
487 } 509 }
488 510
489 if (ngx_processes[i].signal 511 if (ngx_processes[i].signal
490 != ngx_signal_value(NGX_REOPEN_SIGNAL)) 512 != ngx_signal_value(NGX_REOPEN_SIGNAL))
491 { 513 {
514 sent = 1;
492 ngx_processes[i].exiting = 1; 515 ngx_processes[i].exiting = 1;
493 } 516 }
494 } 517 }
495 518
496 if (ngx_reap) { 519 if (ngx_reopen || ngx_reconfigure) {
497 ngx_reap = 0;
498 }
499
500 /* STUB */
501 if (ngx_reopen) {
502 break;
503 }
504
505 if (ngx_reconfigure) {
506 break; 520 break;
507 } 521 }
508 } 522 }
509 523
510 if (ngx_reopen) { 524 if (ngx_reopen) {
511 ngx_reopen = 0; 525 ngx_reopen = 0;
512 526
513 } else if (ngx_noaccept) { 527 } else if (ngx_noaccept) {
514 ngx_noaccept = 0; 528 ngx_noaccept = 0;
529 ngx_reconfigure = 0;
515 530
516 } else { 531 } else {
517 cycle = ngx_init_cycle(cycle); 532 cycle = ngx_init_cycle(cycle);
518 if (cycle == NULL) { 533 if (cycle == NULL) {
519 cycle = (ngx_cycle_t *) ngx_cycle; 534 cycle = (ngx_cycle_t *) ngx_cycle;
520 continue; 535 continue;
521 } 536 }
522 537
523 ngx_cycle = cycle; 538 ngx_cycle = cycle;
539 ngx_reconfigure = 0;
524 } 540 }
525 541
526 ngx_reconfigure = 0;
527 break; 542 break;
528 } 543 }
529 } 544 }
530 } 545 }
531 546
750 * 765 *
751 * ccf->pid = NULL; 766 * ccf->pid = NULL;
752 */ 767 */
753 ccf->daemon = NGX_CONF_UNSET; 768 ccf->daemon = NGX_CONF_UNSET;
754 ccf->master = NGX_CONF_UNSET; 769 ccf->master = NGX_CONF_UNSET;
770 ccf->worker_reopen = NGX_CONF_UNSET;
755 ccf->user = (uid_t) NGX_CONF_UNSET; 771 ccf->user = (uid_t) NGX_CONF_UNSET;
756 ccf->group = (gid_t) NGX_CONF_UNSET; 772 ccf->group = (gid_t) NGX_CONF_UNSET;
757 773
758 ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; 774 ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
759 775