comparison src/os/unix/ngx_process_cycle.c @ 301:744965ec6275

nginx-0.0.3-2004-03-31-19:26:46 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 31 Mar 2004 15:26:46 +0000
parents 502b03d9d2a3
children 1526e7686b20
comparison
equal deleted inserted replaced
300:502b03d9d2a3 301:744965ec6275
63 ngx_new_binary = 0; 63 ngx_new_binary = 0;
64 delay = 0; 64 delay = 0;
65 signo = 0; 65 signo = 0;
66 live = 0; 66 live = 0;
67 67
68 ngx_accept_mutex = mmap(NULL, sizeof(ngx_atomic_t), PROT_READ|PROT_WRITE,
69 MAP_ANON|MAP_SHARED, -1, 0);
70
71 if (ngx_accept_mutex == NULL) {
72 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
73 "mmap(MAP_ANON|MAP_SHARED) failed");
74 /* fatal */
75 exit(2);
76 }
77
68 for ( ;; ) { 78 for ( ;; ) {
69 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); 79 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
70 80
71 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, 81 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
72 ngx_core_module); 82 ngx_core_module);
83
84 if (ccf->worker_processes == NGX_CONF_UNSET) {
85 ccf->worker_processes = 1;
86 }
73 87
74 if (ngx_process == NGX_PROCESS_MASTER) { 88 if (ngx_process == NGX_PROCESS_MASTER) {
75 for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) { 89 for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) {
76 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, 90 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
77 "worker process", NGX_PROCESS_RESPAWN); 91 "worker process", NGX_PROCESS_RESPAWN);
148 162
149 } else { /* NGX_PROCESS_SINGLE */ 163 } else { /* NGX_PROCESS_SINGLE */
150 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 164 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
151 "worker cycle"); 165 "worker cycle");
152 166
153 ngx_process_events(cycle->log); 167 ngx_process_events(cycle);
154 live = 0; 168 live = 0;
155 } 169 }
156 170
157 if (ngx_reap) { 171 if (ngx_reap) {
158 ngx_reap = 0; 172 ngx_reap = 0;
359 #endif 373 #endif
360 374
361 ngx_process = NGX_PROCESS_WORKER; 375 ngx_process = NGX_PROCESS_WORKER;
362 ngx_last_process = 0; 376 ngx_last_process = 0;
363 377
378 if (ngx_accept_mutex) {
379 ngx_accept_token = 1;
380 }
381
364 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); 382 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
365 383
366 if (ccf->group != (gid_t) NGX_CONF_UNSET) { 384 if (ccf->group != (gid_t) NGX_CONF_UNSET) {
367 if (setuid(ccf->group) == -1) { 385 if (setuid(ccf->group) == -1) {
368 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 386 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
440 #endif 458 #endif
441 459
442 for ( ;; ) { 460 for ( ;; ) {
443 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); 461 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
444 462
445 ngx_process_events(cycle->log); 463 ngx_process_events(cycle);
446 464
447 if (ngx_terminate) { 465 if (ngx_terminate) {
448 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting"); 466 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting");
449 exit(0); 467 exit(0);
450 } 468 }
471 exit(0); 489 exit(0);
472 } 490 }
473 491
474 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); 492 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
475 493
476 ngx_process_events(cycle->log); 494 ngx_process_events(cycle);
477 495
478 if (ngx_reopen) { 496 if (ngx_reopen) {
479 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs"); 497 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs");
480 ngx_reopen_files(cycle, -1); 498 ngx_reopen_files(cycle, -1);
481 ngx_reopen = 0; 499 ngx_reopen = 0;