comparison src/os/unix/ngx_process_cycle.c @ 665:0b460e61bdcd default tip

Merge with nginx 1.0.0.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:22:17 +0400
parents 7ea1bba9a4f6
children
comparison
equal deleted inserted replaced
572:06419a2298a9 665:0b460e61bdcd
84 { 84 {
85 char *title; 85 char *title;
86 u_char *p; 86 u_char *p;
87 size_t size; 87 size_t size;
88 ngx_int_t i; 88 ngx_int_t i;
89 ngx_uint_t n; 89 ngx_uint_t n, sigio;
90 sigset_t set; 90 sigset_t set;
91 struct itimerval itv; 91 struct itimerval itv;
92 ngx_uint_t live; 92 ngx_uint_t live;
93 ngx_msec_t delay; 93 ngx_msec_t delay;
94 ngx_listening_t *ls; 94 ngx_listening_t *ls;
137 NGX_PROCESS_RESPAWN); 137 NGX_PROCESS_RESPAWN);
138 ngx_start_cache_manager_processes(cycle, 0); 138 ngx_start_cache_manager_processes(cycle, 0);
139 139
140 ngx_new_binary = 0; 140 ngx_new_binary = 0;
141 delay = 0; 141 delay = 0;
142 sigio = 0;
142 live = 1; 143 live = 1;
143 144
144 for ( ;; ) { 145 for ( ;; ) {
145 if (delay) { 146 if (delay) {
146 if (ngx_sigalrm) { 147 if (ngx_sigalrm) {
148 sigio = 0;
147 delay *= 2; 149 delay *= 2;
148 ngx_sigalrm = 0; 150 ngx_sigalrm = 0;
149 } 151 }
150 152
151 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 153 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
164 166
165 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend"); 167 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend");
166 168
167 sigsuspend(&set); 169 sigsuspend(&set);
168 170
169 ngx_time_update(0, 0); 171 ngx_time_update();
170 172
171 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up"); 173 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
174 "wake up, sigio %i", sigio);
172 175
173 if (ngx_reap) { 176 if (ngx_reap) {
174 ngx_reap = 0; 177 ngx_reap = 0;
175 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap children"); 178 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap children");
176 179
183 186
184 if (ngx_terminate) { 187 if (ngx_terminate) {
185 if (delay == 0) { 188 if (delay == 0) {
186 delay = 50; 189 delay = 50;
187 } 190 }
191
192 if (sigio) {
193 sigio--;
194 continue;
195 }
196
197 sigio = ccf->worker_processes + 2 /* cache processes */;
188 198
189 if (delay > 1000) { 199 if (delay > 1000) {
190 ngx_signal_worker_processes(cycle, SIGKILL); 200 ngx_signal_worker_processes(cycle, SIGKILL);
191 } else { 201 } else {
192 ngx_signal_worker_processes(cycle, 202 ngx_signal_worker_processes(cycle,
278 288
279 void 289 void
280 ngx_single_process_cycle(ngx_cycle_t *cycle) 290 ngx_single_process_cycle(ngx_cycle_t *cycle)
281 { 291 {
282 ngx_uint_t i; 292 ngx_uint_t i;
293
294 if (ngx_set_environment(cycle, NULL) == NULL) {
295 /* fatal */
296 exit(2);
297 }
283 298
284 for (i = 0; ngx_modules[i]; i++) { 299 for (i = 0; ngx_modules[i]; i++) {
285 if (ngx_modules[i]->init_process) { 300 if (ngx_modules[i]->init_process) {
286 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { 301 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
287 /* fatal */ 302 /* fatal */
673 if (ngx_modules[i]->exit_master) { 688 if (ngx_modules[i]->exit_master) {
674 ngx_modules[i]->exit_master(cycle); 689 ngx_modules[i]->exit_master(cycle);
675 } 690 }
676 } 691 }
677 692
693 ngx_close_listening_sockets(cycle);
694
678 /* 695 /*
679 * Copy ngx_cycle->log related data to the special static exit cycle, 696 * Copy ngx_cycle->log related data to the special static exit cycle,
680 * log, and log file structures enough to allow a signal handler to log. 697 * log, and log file structures enough to allow a signal handler to log.
681 * The handler may be called when standard ngx_cycle->log allocated from 698 * The handler may be called when standard ngx_cycle->log allocated from
682 * ngx_cycle->pool is already destroyed. 699 * ngx_cycle->pool is already destroyed.
699 static void 716 static void
700 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) 717 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
701 { 718 {
702 ngx_uint_t i; 719 ngx_uint_t i;
703 ngx_connection_t *c; 720 ngx_connection_t *c;
721
722 ngx_process = NGX_PROCESS_WORKER;
704 723
705 ngx_worker_process_init(cycle, 1); 724 ngx_worker_process_init(cycle, 1);
706 725
707 ngx_setproctitle("worker process"); 726 ngx_setproctitle("worker process");
708 727
815 ngx_uint_t i; 834 ngx_uint_t i;
816 struct rlimit rlmt; 835 struct rlimit rlmt;
817 ngx_core_conf_t *ccf; 836 ngx_core_conf_t *ccf;
818 ngx_listening_t *ls; 837 ngx_listening_t *ls;
819 838
820 ngx_process = NGX_PROCESS_WORKER;
821
822 if (ngx_set_environment(cycle, NULL) == NULL) { 839 if (ngx_set_environment(cycle, NULL) == NULL) {
823 /* fatal */ 840 /* fatal */
824 exit(2); 841 exit(2);
825 } 842 }
826 843
842 "setrlimit(RLIMIT_NOFILE, %i) failed", 859 "setrlimit(RLIMIT_NOFILE, %i) failed",
843 ccf->rlimit_nofile); 860 ccf->rlimit_nofile);
844 } 861 }
845 } 862 }
846 863
847 if (ccf->rlimit_core != NGX_CONF_UNSET_SIZE) { 864 if (ccf->rlimit_core != NGX_CONF_UNSET) {
848 rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; 865 rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
849 rlmt.rlim_max = (rlim_t) ccf->rlimit_core; 866 rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
850 867
851 if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { 868 if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
852 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 869 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
853 "setrlimit(RLIMIT_CORE, %i) failed", 870 "setrlimit(RLIMIT_CORE, %O) failed",
854 ccf->rlimit_core); 871 ccf->rlimit_core);
855 } 872 }
856 } 873 }
857 874
858 #ifdef RLIMIT_SIGPENDING 875 #ifdef RLIMIT_SIGPENDING
1275 void *ident[4]; 1292 void *ident[4];
1276 ngx_event_t ev; 1293 ngx_event_t ev;
1277 1294
1278 cycle->connection_n = 512; 1295 cycle->connection_n = 512;
1279 1296
1297 ngx_process = NGX_PROCESS_HELPER;
1298
1280 ngx_worker_process_init(cycle, 0); 1299 ngx_worker_process_init(cycle, 0);
1281 1300
1282 ngx_close_listening_sockets(cycle); 1301 ngx_close_listening_sockets(cycle);
1283 1302
1284 ngx_memzero(&ev, sizeof(ngx_event_t)); 1303 ngx_memzero(&ev, sizeof(ngx_event_t));
1326 if (path[i]->manager) { 1345 if (path[i]->manager) {
1327 n = path[i]->manager(path[i]->data); 1346 n = path[i]->manager(path[i]->data);
1328 1347
1329 next = (n <= next) ? n : next; 1348 next = (n <= next) ? n : next;
1330 1349
1331 ngx_time_update(0, 0); 1350 ngx_time_update();
1332 } 1351 }
1333 } 1352 }
1334 1353
1335 if (next == 0) { 1354 if (next == 0) {
1336 next = 1; 1355 next = 1;
1356 break; 1375 break;
1357 } 1376 }
1358 1377
1359 if (path[i]->loader) { 1378 if (path[i]->loader) {
1360 path[i]->loader(path[i]->data); 1379 path[i]->loader(path[i]->data);
1361 ngx_time_update(0, 0); 1380 ngx_time_update();
1362 } 1381 }
1363 } 1382 }
1364 1383
1365 exit(0); 1384 exit(0);
1366 } 1385 }