0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_event.h>
|
|
10 #include <ngx_channel.h>
|
|
11
|
|
12
|
|
13 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
|
50
|
14 ngx_int_t type);
|
16
|
15 static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type);
|
0
|
16 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
|
|
17 static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle);
|
2
|
18 static void ngx_master_exit(ngx_cycle_t *cycle);
|
0
|
19 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
|
22
|
20 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority);
|
0
|
21 static void ngx_channel_handler(ngx_event_t *ev);
|
|
22 #if (NGX_THREADS)
|
|
23 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
|
112
|
24 static ngx_thread_value_t ngx_worker_thread_cycle(void *data);
|
0
|
25 #endif
|
50
|
26 #if 0
|
16
|
27 static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data);
|
50
|
28 #endif
|
0
|
29
|
|
30
|
|
31 ngx_uint_t ngx_process;
|
|
32 ngx_pid_t ngx_pid;
|
|
33 ngx_uint_t ngx_threaded;
|
|
34
|
|
35 sig_atomic_t ngx_reap;
|
|
36 sig_atomic_t ngx_sigio;
|
|
37 sig_atomic_t ngx_terminate;
|
|
38 sig_atomic_t ngx_quit;
|
26
|
39 sig_atomic_t ngx_debug_quit;
|
0
|
40 ngx_uint_t ngx_exiting;
|
|
41 sig_atomic_t ngx_reconfigure;
|
|
42 sig_atomic_t ngx_reopen;
|
|
43
|
|
44 sig_atomic_t ngx_change_binary;
|
|
45 ngx_pid_t ngx_new_binary;
|
|
46 ngx_uint_t ngx_inherited;
|
|
47 ngx_uint_t ngx_daemonized;
|
|
48
|
|
49 sig_atomic_t ngx_noaccept;
|
|
50 ngx_uint_t ngx_noaccepting;
|
|
51 ngx_uint_t ngx_restart;
|
|
52
|
|
53
|
|
54 #if (NGX_THREADS)
|
|
55 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
|
|
56 ngx_int_t ngx_threads_n;
|
|
57 #endif
|
|
58
|
|
59
|
|
60 u_char master_process[] = "master process";
|
|
61
|
|
62
|
50
|
63 void
|
|
64 ngx_master_process_cycle(ngx_cycle_t *cycle)
|
0
|
65 {
|
|
66 char *title;
|
|
67 u_char *p;
|
|
68 size_t size;
|
|
69 ngx_int_t i;
|
80
|
70 ngx_uint_t n;
|
0
|
71 sigset_t set;
|
|
72 struct itimerval itv;
|
|
73 ngx_uint_t live;
|
|
74 ngx_msec_t delay;
|
80
|
75 ngx_listening_t *ls;
|
0
|
76 ngx_core_conf_t *ccf;
|
|
77
|
|
78 sigemptyset(&set);
|
|
79 sigaddset(&set, SIGCHLD);
|
|
80 sigaddset(&set, SIGALRM);
|
|
81 sigaddset(&set, SIGIO);
|
|
82 sigaddset(&set, SIGINT);
|
|
83 sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
|
|
84 sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
|
|
85 sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL));
|
|
86 sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL));
|
|
87 sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
|
88 sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
|
|
89
|
|
90 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
|
|
91 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
92 "sigprocmask() failed");
|
|
93 }
|
|
94
|
|
95 sigemptyset(&set);
|
|
96
|
|
97
|
|
98 size = sizeof(master_process);
|
|
99
|
2
|
100 for (i = 0; i < ngx_argc; i++) {
|
|
101 size += ngx_strlen(ngx_argv[i]) + 1;
|
0
|
102 }
|
|
103
|
|
104 title = ngx_palloc(cycle->pool, size);
|
|
105
|
|
106 p = ngx_cpymem(title, master_process, sizeof(master_process) - 1);
|
2
|
107 for (i = 0; i < ngx_argc; i++) {
|
0
|
108 *p++ = ' ';
|
2
|
109 p = ngx_cpystrn(p, (u_char *) ngx_argv[i], size);
|
0
|
110 }
|
|
111
|
|
112 ngx_setproctitle(title);
|
|
113
|
|
114
|
|
115 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
|
116
|
|
117 ngx_start_worker_processes(cycle, ccf->worker_processes,
|
|
118 NGX_PROCESS_RESPAWN);
|
16
|
119 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN);
|
0
|
120
|
|
121 ngx_new_binary = 0;
|
|
122 delay = 0;
|
|
123 live = 1;
|
|
124
|
|
125 for ( ;; ) {
|
|
126 if (delay) {
|
|
127 delay *= 2;
|
|
128
|
|
129 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
130 "temination cycle: %d", delay);
|
|
131
|
|
132 itv.it_interval.tv_sec = 0;
|
|
133 itv.it_interval.tv_usec = 0;
|
|
134 itv.it_value.tv_sec = delay / 1000;
|
|
135 itv.it_value.tv_usec = (delay % 1000 ) * 1000;
|
|
136
|
|
137 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
|
|
138 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
139 "setitimer() failed");
|
|
140 }
|
|
141 }
|
|
142
|
|
143 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend");
|
|
144
|
|
145 sigsuspend(&set);
|
|
146
|
112
|
147 ngx_time_update(0, 0);
|
0
|
148
|
|
149 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up");
|
|
150
|
|
151 if (ngx_reap) {
|
|
152 ngx_reap = 0;
|
|
153 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap childs");
|
|
154
|
|
155 live = ngx_reap_childs(cycle);
|
|
156 }
|
|
157
|
|
158 if (!live && (ngx_terminate || ngx_quit)) {
|
2
|
159 ngx_master_exit(cycle);
|
0
|
160 }
|
|
161
|
|
162 if (ngx_terminate) {
|
|
163 if (delay == 0) {
|
|
164 delay = 50;
|
|
165 }
|
|
166
|
|
167 if (delay > 1000) {
|
|
168 ngx_signal_worker_processes(cycle, SIGKILL);
|
|
169 } else {
|
|
170 ngx_signal_worker_processes(cycle,
|
|
171 ngx_signal_value(NGX_TERMINATE_SIGNAL));
|
|
172 }
|
|
173
|
|
174 continue;
|
|
175 }
|
|
176
|
|
177 if (ngx_quit) {
|
|
178 ngx_signal_worker_processes(cycle,
|
|
179 ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
80
|
180
|
|
181 ls = cycle->listening.elts;
|
|
182 for (n = 0; n < cycle->listening.nelts; n++) {
|
|
183 if (ngx_close_socket(ls[n].fd) == -1) {
|
|
184 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
|
|
185 ngx_close_socket_n " %V failed",
|
|
186 &ls[n].addr_text);
|
|
187 }
|
|
188 }
|
|
189 cycle->listening.nelts = 0;
|
|
190
|
0
|
191 continue;
|
|
192 }
|
|
193
|
|
194 if (ngx_reconfigure) {
|
|
195 ngx_reconfigure = 0;
|
|
196
|
|
197 if (ngx_new_binary) {
|
|
198 ngx_start_worker_processes(cycle, ccf->worker_processes,
|
|
199 NGX_PROCESS_RESPAWN);
|
16
|
200 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN);
|
0
|
201 ngx_noaccepting = 0;
|
|
202
|
|
203 continue;
|
|
204 }
|
|
205
|
26
|
206 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring");
|
0
|
207
|
|
208 cycle = ngx_init_cycle(cycle);
|
|
209 if (cycle == NULL) {
|
|
210 cycle = (ngx_cycle_t *) ngx_cycle;
|
|
211 continue;
|
|
212 }
|
|
213
|
|
214 ngx_cycle = cycle;
|
|
215 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
|
|
216 ngx_core_module);
|
|
217 ngx_start_worker_processes(cycle, ccf->worker_processes,
|
|
218 NGX_PROCESS_JUST_RESPAWN);
|
16
|
219 ngx_start_garbage_collector(cycle, NGX_PROCESS_JUST_RESPAWN);
|
0
|
220 live = 1;
|
|
221 ngx_signal_worker_processes(cycle,
|
|
222 ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
|
223 }
|
|
224
|
|
225 if (ngx_restart) {
|
|
226 ngx_restart = 0;
|
|
227 ngx_start_worker_processes(cycle, ccf->worker_processes,
|
|
228 NGX_PROCESS_RESPAWN);
|
16
|
229 ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN);
|
0
|
230 live = 1;
|
|
231 }
|
|
232
|
|
233 if (ngx_reopen) {
|
|
234 ngx_reopen = 0;
|
26
|
235 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
|
0
|
236 ngx_reopen_files(cycle, ccf->user);
|
|
237 ngx_signal_worker_processes(cycle,
|
|
238 ngx_signal_value(NGX_REOPEN_SIGNAL));
|
|
239 }
|
|
240
|
|
241 if (ngx_change_binary) {
|
|
242 ngx_change_binary = 0;
|
26
|
243 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "changing binary");
|
2
|
244 ngx_new_binary = ngx_exec_new_binary(cycle, ngx_argv);
|
0
|
245 }
|
|
246
|
|
247 if (ngx_noaccept) {
|
|
248 ngx_noaccept = 0;
|
|
249 ngx_noaccepting = 1;
|
|
250 ngx_signal_worker_processes(cycle,
|
|
251 ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
|
|
252 }
|
|
253 }
|
|
254 }
|
|
255
|
|
256
|
50
|
257 void
|
|
258 ngx_single_process_cycle(ngx_cycle_t *cycle)
|
0
|
259 {
|
|
260 ngx_uint_t i;
|
|
261
|
|
262 ngx_init_temp_number();
|
|
263
|
|
264 for (i = 0; ngx_modules[i]; i++) {
|
|
265 if (ngx_modules[i]->init_process) {
|
|
266 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
|
|
267 /* fatal */
|
|
268 exit(2);
|
|
269 }
|
|
270 }
|
|
271 }
|
|
272
|
|
273 for ( ;; ) {
|
|
274 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
|
|
275
|
112
|
276 ngx_process_events_and_timers(cycle);
|
0
|
277
|
|
278 if (ngx_terminate || ngx_quit) {
|
2
|
279 ngx_master_exit(cycle);
|
0
|
280 }
|
|
281
|
|
282 if (ngx_reconfigure) {
|
|
283 ngx_reconfigure = 0;
|
26
|
284 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring");
|
0
|
285
|
|
286 cycle = ngx_init_cycle(cycle);
|
|
287 if (cycle == NULL) {
|
|
288 cycle = (ngx_cycle_t *) ngx_cycle;
|
|
289 continue;
|
|
290 }
|
|
291
|
|
292 ngx_cycle = cycle;
|
|
293 }
|
|
294
|
|
295 if (ngx_reopen) {
|
|
296 ngx_reopen = 0;
|
26
|
297 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
|
0
|
298 ngx_reopen_files(cycle, (ngx_uid_t) -1);
|
|
299 }
|
|
300 }
|
|
301 }
|
|
302
|
|
303
|
50
|
304 static void
|
|
305 ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
|
0
|
306 {
|
106
|
307 ngx_int_t i;
|
|
308 ngx_channel_t ch;
|
0
|
309
|
26
|
310 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes");
|
0
|
311
|
|
312 ch.command = NGX_CMD_OPEN_CHANNEL;
|
|
313
|
|
314 while (n--) {
|
|
315 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
|
|
316 "worker process", type);
|
|
317
|
|
318 ch.pid = ngx_processes[ngx_process_slot].pid;
|
|
319 ch.slot = ngx_process_slot;
|
|
320 ch.fd = ngx_processes[ngx_process_slot].channel[0];
|
|
321
|
|
322 for (i = 0; i < ngx_last_process; i++) {
|
|
323
|
|
324 if (i == ngx_process_slot
|
|
325 || ngx_processes[i].pid == -1
|
|
326 || ngx_processes[i].channel[0] == -1)
|
|
327 {
|
|
328 continue;
|
|
329 }
|
|
330
|
|
331 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
10
|
332 "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d",
|
|
333 ch.slot, ch.pid, ch.fd,
|
|
334 i, ngx_processes[i].pid,
|
|
335 ngx_processes[i].channel[0]);
|
0
|
336
|
|
337 /* TODO: NGX_AGAIN */
|
|
338
|
|
339 ngx_write_channel(ngx_processes[i].channel[0],
|
|
340 &ch, sizeof(ngx_channel_t), cycle->log);
|
|
341 }
|
|
342 }
|
|
343 }
|
|
344
|
|
345
|
50
|
346 static void
|
|
347 ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
|
16
|
348 {
|
50
|
349 #if 0
|
|
350 ngx_int_t i;
|
|
351 ngx_channel_t ch;
|
16
|
352
|
26
|
353 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start garbage collector");
|
16
|
354
|
|
355 ch.command = NGX_CMD_OPEN_CHANNEL;
|
|
356
|
|
357 ngx_spawn_process(cycle, ngx_garbage_collector_cycle, NULL,
|
|
358 "garbage collector", type);
|
|
359
|
|
360 ch.pid = ngx_processes[ngx_process_slot].pid;
|
|
361 ch.slot = ngx_process_slot;
|
|
362 ch.fd = ngx_processes[ngx_process_slot].channel[0];
|
|
363
|
|
364 for (i = 0; i < ngx_last_process; i++) {
|
|
365
|
|
366 if (i == ngx_process_slot
|
|
367 || ngx_processes[i].pid == -1
|
|
368 || ngx_processes[i].channel[0] == -1)
|
|
369 {
|
|
370 continue;
|
|
371 }
|
|
372
|
|
373 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
|
374 "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d",
|
|
375 ch.slot, ch.pid, ch.fd,
|
|
376 i, ngx_processes[i].pid,
|
|
377 ngx_processes[i].channel[0]);
|
|
378
|
|
379 /* TODO: NGX_AGAIN */
|
|
380
|
|
381 ngx_write_channel(ngx_processes[i].channel[0],
|
|
382 &ch, sizeof(ngx_channel_t), cycle->log);
|
|
383 }
|
50
|
384 #endif
|
16
|
385 }
|
|
386
|
|
387
|
50
|
388 static void
|
|
389 ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
|
0
|
390 {
|
|
391 ngx_int_t i;
|
|
392 ngx_err_t err;
|
|
393 ngx_channel_t ch;
|
|
394
|
|
395 switch (signo) {
|
|
396
|
|
397 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL):
|
|
398 ch.command = NGX_CMD_QUIT;
|
|
399 break;
|
|
400
|
|
401 case ngx_signal_value(NGX_TERMINATE_SIGNAL):
|
|
402 ch.command = NGX_CMD_TERMINATE;
|
|
403 break;
|
|
404
|
|
405 case ngx_signal_value(NGX_REOPEN_SIGNAL):
|
|
406 ch.command = NGX_CMD_REOPEN;
|
|
407 break;
|
|
408
|
|
409 default:
|
|
410 ch.command = 0;
|
|
411 }
|
|
412
|
|
413 ch.fd = -1;
|
|
414
|
|
415
|
|
416 for (i = 0; i < ngx_last_process; i++) {
|
|
417
|
|
418 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
10
|
419 "child: %d %P e:%d t:%d d:%d r:%d j:%d",
|
0
|
420 i,
|
|
421 ngx_processes[i].pid,
|
|
422 ngx_processes[i].exiting,
|
|
423 ngx_processes[i].exited,
|
|
424 ngx_processes[i].detached,
|
|
425 ngx_processes[i].respawn,
|
|
426 ngx_processes[i].just_respawn);
|
|
427
|
|
428 if (ngx_processes[i].detached || ngx_processes[i].pid == -1) {
|
|
429 continue;
|
|
430 }
|
|
431
|
|
432 if (ngx_processes[i].just_respawn) {
|
|
433 ngx_processes[i].just_respawn = 0;
|
|
434 continue;
|
|
435 }
|
|
436
|
|
437 if (ngx_processes[i].exiting
|
|
438 && signo == ngx_signal_value(NGX_SHUTDOWN_SIGNAL))
|
|
439 {
|
|
440 continue;
|
|
441 }
|
|
442
|
|
443 if (ch.command) {
|
|
444 if (ngx_write_channel(ngx_processes[i].channel[0],
|
|
445 &ch, sizeof(ngx_channel_t), cycle->log) == NGX_OK)
|
|
446 {
|
|
447 if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
|
448 ngx_processes[i].exiting = 1;
|
|
449 }
|
|
450
|
|
451 continue;
|
|
452 }
|
|
453 }
|
|
454
|
|
455 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
10
|
456 "kill (%P, %d)" , ngx_processes[i].pid, signo);
|
0
|
457
|
|
458 if (kill(ngx_processes[i].pid, signo) == -1) {
|
|
459 err = ngx_errno;
|
|
460 ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
|
10
|
461 "kill(%P, %d) failed",
|
0
|
462 ngx_processes[i].pid, signo);
|
|
463
|
|
464 if (err == NGX_ESRCH) {
|
|
465 ngx_processes[i].exited = 1;
|
|
466 ngx_processes[i].exiting = 0;
|
|
467 ngx_reap = 1;
|
|
468 }
|
|
469
|
|
470 continue;
|
|
471 }
|
|
472
|
|
473 if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
|
|
474 ngx_processes[i].exiting = 1;
|
|
475 }
|
|
476 }
|
|
477 }
|
|
478
|
|
479
|
50
|
480 static ngx_uint_t
|
|
481 ngx_reap_childs(ngx_cycle_t *cycle)
|
0
|
482 {
|
92
|
483 ngx_int_t i, n;
|
|
484 ngx_uint_t live;
|
|
485 ngx_channel_t ch;
|
|
486 ngx_core_conf_t *ccf;
|
0
|
487
|
|
488 ch.command = NGX_CMD_CLOSE_CHANNEL;
|
|
489 ch.fd = -1;
|
|
490
|
|
491 live = 0;
|
|
492 for (i = 0; i < ngx_last_process; i++) {
|
|
493
|
|
494 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
10
|
495 "child: %d %P e:%d t:%d d:%d r:%d j:%d",
|
0
|
496 i,
|
|
497 ngx_processes[i].pid,
|
|
498 ngx_processes[i].exiting,
|
|
499 ngx_processes[i].exited,
|
|
500 ngx_processes[i].detached,
|
|
501 ngx_processes[i].respawn,
|
|
502 ngx_processes[i].just_respawn);
|
|
503
|
|
504 if (ngx_processes[i].pid == -1) {
|
|
505 continue;
|
|
506 }
|
|
507
|
|
508 if (ngx_processes[i].exited) {
|
|
509
|
|
510 if (!ngx_processes[i].detached) {
|
|
511 ngx_close_channel(ngx_processes[i].channel, cycle->log);
|
|
512
|
|
513 ngx_processes[i].channel[0] = -1;
|
|
514 ngx_processes[i].channel[1] = -1;
|
|
515
|
|
516 ch.pid = ngx_processes[i].pid;
|
|
517 ch.slot = i;
|
|
518
|
|
519 for (n = 0; n < ngx_last_process; n++) {
|
|
520 if (ngx_processes[n].exited
|
|
521 || ngx_processes[n].pid == -1
|
|
522 || ngx_processes[n].channel[0] == -1)
|
|
523 {
|
|
524 continue;
|
|
525 }
|
|
526
|
|
527 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
10
|
528 "pass close channel s:%i pid:%P to:%P",
|
|
529 ch.slot, ch.pid, ngx_processes[n].pid);
|
0
|
530
|
|
531 /* TODO: NGX_AGAIN */
|
|
532
|
|
533 ngx_write_channel(ngx_processes[n].channel[0],
|
|
534 &ch, sizeof(ngx_channel_t), cycle->log);
|
|
535 }
|
|
536 }
|
|
537
|
|
538 if (ngx_processes[i].respawn
|
|
539 && !ngx_processes[i].exiting
|
|
540 && !ngx_terminate
|
|
541 && !ngx_quit)
|
|
542 {
|
|
543 if (ngx_spawn_process(cycle, ngx_processes[i].proc,
|
|
544 ngx_processes[i].data,
|
|
545 ngx_processes[i].name, i)
|
92
|
546 == NGX_INVALID_PID)
|
0
|
547 {
|
|
548 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
|
549 "can not respawn %s", ngx_processes[i].name);
|
|
550 continue;
|
|
551 }
|
|
552
|
22
|
553
|
|
554 ch.command = NGX_CMD_OPEN_CHANNEL;
|
|
555 ch.pid = ngx_processes[ngx_process_slot].pid;
|
|
556 ch.slot = ngx_process_slot;
|
|
557 ch.fd = ngx_processes[ngx_process_slot].channel[0];
|
|
558
|
|
559 for (n = 0; n < ngx_last_process; n++) {
|
|
560
|
|
561 if (n == ngx_process_slot
|
|
562 || ngx_processes[n].pid == -1
|
|
563 || ngx_processes[n].channel[0] == -1)
|
|
564 {
|
|
565 continue;
|
|
566 }
|
|
567
|
|
568 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
|
569 "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d",
|
|
570 ch.slot, ch.pid, ch.fd,
|
|
571 n, ngx_processes[n].pid,
|
|
572 ngx_processes[n].channel[0]);
|
|
573
|
|
574 /* TODO: NGX_AGAIN */
|
|
575
|
|
576 ngx_write_channel(ngx_processes[n].channel[0],
|
|
577 &ch, sizeof(ngx_channel_t), cycle->log);
|
|
578 }
|
|
579
|
0
|
580 live = 1;
|
|
581
|
|
582 continue;
|
|
583 }
|
|
584
|
|
585 if (ngx_processes[i].pid == ngx_new_binary) {
|
92
|
586
|
|
587 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
|
|
588 ngx_core_module);
|
|
589
|
|
590 if (ngx_rename_file((char *) ccf->oldpid.data,
|
|
591 (char *) ccf->pid.data)
|
|
592 != NGX_OK)
|
|
593 {
|
|
594 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
595 ngx_rename_file_n " %s back to %s failed "
|
|
596 "after the new binary process \"%s\" exited",
|
|
597 ccf->oldpid.data, ccf->pid.data, ngx_argv[0]);
|
|
598 }
|
|
599
|
0
|
600 ngx_new_binary = 0;
|
|
601 if (ngx_noaccepting) {
|
|
602 ngx_restart = 1;
|
|
603 ngx_noaccepting = 0;
|
|
604 }
|
|
605 }
|
|
606
|
|
607 if (i == ngx_last_process - 1) {
|
|
608 ngx_last_process--;
|
|
609
|
|
610 } else {
|
|
611 ngx_processes[i].pid = -1;
|
|
612 }
|
|
613
|
|
614 } else if (ngx_processes[i].exiting || !ngx_processes[i].detached) {
|
|
615 live = 1;
|
|
616 }
|
|
617 }
|
|
618
|
|
619 return live;
|
|
620 }
|
|
621
|
|
622
|
50
|
623 static void
|
|
624 ngx_master_exit(ngx_cycle_t *cycle)
|
0
|
625 {
|
|
626 ngx_delete_pidfile(cycle);
|
|
627
|
26
|
628 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit");
|
0
|
629
|
54
|
630 /*
|
|
631 * we do not destroy cycle->pool here because a signal handler
|
|
632 * that uses cycle->log can be called at this point
|
|
633 */
|
|
634
|
|
635 #if 0
|
0
|
636 ngx_destroy_pool(cycle->pool);
|
54
|
637 #endif
|
0
|
638
|
|
639 exit(0);
|
|
640 }
|
|
641
|
|
642
|
50
|
643 static void
|
|
644 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
|
0
|
645 {
|
112
|
646 ngx_uint_t i;
|
|
647 ngx_connection_t *c;
|
50
|
648 #if (NGX_THREADS)
|
18
|
649 ngx_int_t n;
|
|
650 ngx_err_t err;
|
|
651 ngx_core_conf_t *ccf;
|
50
|
652 #endif
|
18
|
653
|
22
|
654 ngx_worker_process_init(cycle, 1);
|
0
|
655
|
|
656 ngx_setproctitle("worker process");
|
|
657
|
|
658 #if (NGX_THREADS)
|
|
659
|
18
|
660 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
|
661
|
0
|
662 if (ngx_threads_n) {
|
|
663 if (ngx_init_threads(ngx_threads_n,
|
|
664 ccf->thread_stack_size, cycle) == NGX_ERROR)
|
|
665 {
|
|
666 /* fatal */
|
|
667 exit(2);
|
|
668 }
|
|
669
|
|
670 err = ngx_thread_key_create(&ngx_core_tls_key);
|
|
671 if (err != 0) {
|
|
672 ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
|
|
673 ngx_thread_key_create_n " failed");
|
|
674 /* fatal */
|
|
675 exit(2);
|
|
676 }
|
|
677
|
|
678 for (n = 0; n < ngx_threads_n; n++) {
|
|
679
|
50
|
680 ngx_threads[n].cv = ngx_cond_init(cycle->log);
|
|
681
|
|
682 if (ngx_threads[n].cv == NULL) {
|
0
|
683 /* fatal */
|
|
684 exit(2);
|
|
685 }
|
|
686
|
|
687 if (ngx_create_thread((ngx_tid_t *) &ngx_threads[n].tid,
|
|
688 ngx_worker_thread_cycle,
|
|
689 (void *) &ngx_threads[n], cycle->log) != 0)
|
|
690 {
|
|
691 /* fatal */
|
|
692 exit(2);
|
|
693 }
|
|
694 }
|
|
695 }
|
|
696
|
|
697 #endif
|
|
698
|
|
699 for ( ;; ) {
|
|
700 if (ngx_exiting
|
108
|
701 && ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
|
0
|
702 {
|
26
|
703 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
|
0
|
704
|
|
705
|
|
706 #if (NGX_THREADS)
|
|
707 ngx_terminate = 1;
|
|
708
|
|
709 ngx_wakeup_worker_threads(cycle);
|
|
710 #endif
|
|
711
|
26
|
712 if (ngx_debug_quit) {
|
|
713 ngx_debug_point();
|
|
714 }
|
|
715
|
0
|
716 /*
|
|
717 * we do not destroy cycle->pool here because a signal handler
|
|
718 * that uses cycle->log can be called at this point
|
|
719 */
|
54
|
720
|
|
721 #if 0
|
|
722 ngx_destroy_pool(cycle->pool);
|
|
723 #endif
|
0
|
724 exit(0);
|
|
725 }
|
|
726
|
|
727 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
|
|
728
|
112
|
729 ngx_process_events_and_timers(cycle);
|
0
|
730
|
|
731 if (ngx_terminate) {
|
26
|
732 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
|
0
|
733
|
|
734 #if (NGX_THREADS)
|
|
735 ngx_wakeup_worker_threads(cycle);
|
|
736 #endif
|
|
737
|
112
|
738 c = cycle->connections;
|
|
739 for (i = 0; i < cycle->connection_n; i++) {
|
|
740 if (c[i].fd != -1
|
|
741 && c[i].read
|
|
742 && !c[i].read->accept
|
|
743 && !c[i].read->channel)
|
|
744 {
|
|
745 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
|
746 "open socket #%d left in %ui connection, "
|
|
747 "aborting",
|
|
748 c[i].fd, i);
|
|
749 ngx_abort();
|
|
750 }
|
|
751 }
|
|
752
|
0
|
753 /*
|
|
754 * we do not destroy cycle->pool here because a signal handler
|
|
755 * that uses cycle->log can be called at this point
|
|
756 */
|
54
|
757
|
|
758 #if 0
|
|
759 ngx_destroy_pool(cycle->pool);
|
|
760 #endif
|
|
761
|
0
|
762 exit(0);
|
|
763 }
|
|
764
|
|
765 if (ngx_quit) {
|
|
766 ngx_quit = 0;
|
26
|
767 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
|
0
|
768 "gracefully shutting down");
|
|
769 ngx_setproctitle("worker process is shutting down");
|
|
770
|
|
771 if (!ngx_exiting) {
|
|
772 ngx_close_listening_sockets(cycle);
|
|
773 ngx_exiting = 1;
|
|
774 }
|
|
775 }
|
|
776
|
|
777 if (ngx_reopen) {
|
|
778 ngx_reopen = 0;
|
26
|
779 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
|
0
|
780 ngx_reopen_files(cycle, -1);
|
|
781 }
|
|
782 }
|
|
783 }
|
|
784
|
|
785
|
50
|
786 static void
|
|
787 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
|
16
|
788 {
|
|
789 sigset_t set;
|
|
790 ngx_int_t n;
|
|
791 ngx_uint_t i;
|
92
|
792 struct rlimit rlmt;
|
16
|
793 ngx_core_conf_t *ccf;
|
|
794 ngx_listening_t *ls;
|
|
795
|
|
796 ngx_process = NGX_PROCESS_WORKER;
|
|
797
|
|
798 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
|
799
|
|
800 if (geteuid() == 0) {
|
22
|
801 if (priority && ccf->priority != 0) {
|
|
802 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
|
|
803 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
804 "setpriority(%d) failed", ccf->priority);
|
|
805 }
|
|
806 }
|
|
807
|
92
|
808 if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
|
|
809 rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
|
|
810 rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
|
|
811
|
|
812 if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
|
|
813 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
814 "setrlimit(RLIMIT_NOFILE, %i) failed",
|
|
815 ccf->rlimit_nofile);
|
|
816 }
|
|
817 }
|
|
818
|
|
819 #ifdef RLIMIT_SIGPENDING
|
|
820 if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
|
|
821 rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
|
|
822 rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
|
|
823
|
|
824 if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
|
|
825 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
826 "setrlimit(RLIMIT_SIGPENDING, %i) failed",
|
|
827 ccf->rlimit_sigpending);
|
|
828 }
|
|
829 }
|
|
830 #endif
|
|
831
|
16
|
832 if (setgid(ccf->group) == -1) {
|
|
833 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
834 "setgid(%d) failed", ccf->group);
|
|
835 /* fatal */
|
|
836 exit(2);
|
|
837 }
|
|
838
|
22
|
839 if (initgroups(ccf->username, ccf->group) == -1) {
|
|
840 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
841 "initgroups(%s, %d) failed",
|
|
842 ccf->username, ccf->group);
|
|
843 }
|
|
844
|
16
|
845 if (setuid(ccf->user) == -1) {
|
|
846 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
847 "setuid(%d) failed", ccf->user);
|
|
848 /* fatal */
|
|
849 exit(2);
|
|
850 }
|
|
851 }
|
|
852
|
|
853 #if (NGX_HAVE_PR_SET_DUMPABLE)
|
|
854
|
|
855 /* allow coredump after setuid() in Linux 2.4.x */
|
|
856
|
|
857 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
|
|
858 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
859 "prctl(PR_SET_DUMPABLE) failed");
|
|
860 }
|
|
861
|
|
862 #endif
|
|
863
|
70
|
864 if (ccf->working_directory.len) {
|
72
|
865 if (chdir((char *) ccf->working_directory.data) == -1) {
|
70
|
866 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
867 "chdir(\"%s\") failed", ccf->working_directory.data);
|
|
868 /* fatal */
|
|
869 exit(2);
|
|
870 }
|
|
871 }
|
|
872
|
16
|
873 sigemptyset(&set);
|
|
874
|
|
875 if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
|
|
876 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
877 "sigprocmask() failed");
|
|
878 }
|
|
879
|
|
880 ngx_init_temp_number();
|
|
881
|
|
882 /*
|
|
883 * disable deleting previous events for the listening sockets because
|
|
884 * in the worker processes there are no events at all at this point
|
|
885 */
|
|
886 ls = cycle->listening.elts;
|
|
887 for (i = 0; i < cycle->listening.nelts; i++) {
|
92
|
888 ls[i].previous = NULL;
|
16
|
889 }
|
|
890
|
|
891 for (i = 0; ngx_modules[i]; i++) {
|
|
892 if (ngx_modules[i]->init_process) {
|
|
893 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
|
|
894 /* fatal */
|
|
895 exit(2);
|
|
896 }
|
|
897 }
|
|
898 }
|
|
899
|
|
900 for (n = 0; n < ngx_last_process; n++) {
|
|
901
|
|
902 if (ngx_processes[n].pid == -1) {
|
|
903 continue;
|
|
904 }
|
|
905
|
|
906 if (n == ngx_process_slot) {
|
|
907 continue;
|
|
908 }
|
|
909
|
|
910 if (ngx_processes[n].channel[1] == -1) {
|
|
911 continue;
|
|
912 }
|
|
913
|
|
914 if (close(ngx_processes[n].channel[1]) == -1) {
|
|
915 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
916 "close() channel failed");
|
|
917 }
|
|
918 }
|
|
919
|
|
920 if (close(ngx_processes[ngx_process_slot].channel[0]) == -1) {
|
|
921 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
922 "close() channel failed");
|
|
923 }
|
|
924
|
|
925 #if 0
|
|
926 ngx_last_process = 0;
|
|
927 #endif
|
|
928
|
|
929 if (ngx_add_channel_event(cycle, ngx_channel, NGX_READ_EVENT,
|
84
|
930 ngx_channel_handler) == NGX_ERROR)
|
16
|
931 {
|
|
932 /* fatal */
|
|
933 exit(2);
|
|
934 }
|
|
935 }
|
|
936
|
|
937
|
50
|
938 static void
|
|
939 ngx_channel_handler(ngx_event_t *ev)
|
0
|
940 {
|
|
941 ngx_int_t n;
|
92
|
942 ngx_socket_t fd;
|
0
|
943 ngx_channel_t ch;
|
|
944 ngx_connection_t *c;
|
|
945
|
16
|
946 if (ev->timedout) {
|
|
947 ev->timedout = 0;
|
|
948 return;
|
|
949 }
|
|
950
|
0
|
951 c = ev->data;
|
|
952
|
|
953 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel handler");
|
|
954
|
|
955 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
|
|
956
|
10
|
957 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
|
0
|
958
|
10
|
959 if (n == NGX_ERROR) {
|
92
|
960
|
|
961 ngx_free_connection(c);
|
|
962
|
|
963 fd = c->fd;
|
|
964 c->fd = (ngx_socket_t) -1;
|
|
965
|
|
966 if (close(fd) == -1) {
|
10
|
967 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
|
|
968 "close() channel failed");
|
|
969 }
|
|
970
|
|
971 return;
|
|
972 }
|
|
973
|
|
974 if (n == NGX_AGAIN) {
|
0
|
975 return;
|
|
976 }
|
|
977
|
|
978 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
|
|
979 "channel command: %d", ch.command);
|
|
980
|
|
981 switch (ch.command) {
|
|
982
|
|
983 case NGX_CMD_QUIT:
|
|
984 ngx_quit = 1;
|
|
985 break;
|
|
986
|
|
987 case NGX_CMD_TERMINATE:
|
|
988 ngx_terminate = 1;
|
|
989 break;
|
|
990
|
|
991 case NGX_CMD_REOPEN:
|
|
992 ngx_reopen = 1;
|
|
993 break;
|
|
994
|
|
995 case NGX_CMD_OPEN_CHANNEL:
|
|
996
|
|
997 ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
|
10
|
998 "get channel s:%i pid:%P fd:%d", ch.slot, ch.pid, ch.fd);
|
0
|
999
|
|
1000 ngx_processes[ch.slot].pid = ch.pid;
|
|
1001 ngx_processes[ch.slot].channel[0] = ch.fd;
|
|
1002 break;
|
|
1003
|
|
1004 case NGX_CMD_CLOSE_CHANNEL:
|
|
1005
|
|
1006 ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
|
10
|
1007 "close channel s:%i pid:%P our:%P fd:%d",
|
0
|
1008 ch.slot, ch.pid, ngx_processes[ch.slot].pid,
|
|
1009 ngx_processes[ch.slot].channel[0]);
|
|
1010
|
|
1011 if (close(ngx_processes[ch.slot].channel[0]) == -1) {
|
16
|
1012 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
|
|
1013 "close() channel failed");
|
0
|
1014 }
|
|
1015
|
|
1016 ngx_processes[ch.slot].channel[0] = -1;
|
|
1017 break;
|
|
1018 }
|
|
1019 }
|
|
1020
|
|
1021
|
|
1022 #if (NGX_THREADS)
|
|
1023
|
50
|
1024 static void
|
|
1025 ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
|
0
|
1026 {
|
|
1027 ngx_int_t i;
|
|
1028 ngx_uint_t live;
|
|
1029
|
|
1030 for ( ;; ) {
|
|
1031
|
|
1032 live = 0;
|
|
1033
|
|
1034 for (i = 0; i < ngx_threads_n; i++) {
|
|
1035 if (ngx_threads[i].state < NGX_THREAD_EXIT) {
|
18
|
1036 if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) {
|
|
1037 ngx_threads[i].state = NGX_THREAD_DONE;
|
0
|
1038
|
|
1039 } else {
|
|
1040 live = 1;
|
|
1041 }
|
|
1042 }
|
|
1043
|
|
1044 if (ngx_threads[i].state == NGX_THREAD_EXIT) {
|
|
1045 ngx_thread_join(ngx_threads[i].tid, NULL);
|
|
1046 ngx_threads[i].state = NGX_THREAD_DONE;
|
|
1047 }
|
|
1048 }
|
|
1049
|
|
1050 if (live == 0) {
|
|
1051 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
|
1052 "all worker threads are joined");
|
|
1053
|
|
1054 /* STUB */
|
|
1055 ngx_done_events(cycle);
|
|
1056 ngx_mutex_destroy(ngx_event_timer_mutex);
|
|
1057 ngx_mutex_destroy(ngx_posted_events_mutex);
|
|
1058
|
|
1059 return;
|
|
1060 }
|
|
1061
|
|
1062 ngx_sched_yield();
|
|
1063 }
|
|
1064 }
|
|
1065
|
|
1066
|
112
|
1067 static ngx_thread_value_t
|
50
|
1068 ngx_worker_thread_cycle(void *data)
|
0
|
1069 {
|
|
1070 ngx_thread_t *thr = data;
|
|
1071
|
|
1072 sigset_t set;
|
|
1073 ngx_err_t err;
|
|
1074 ngx_core_tls_t *tls;
|
|
1075 ngx_cycle_t *cycle;
|
|
1076
|
|
1077 cycle = (ngx_cycle_t *) ngx_cycle;
|
|
1078
|
|
1079 sigemptyset(&set);
|
|
1080 sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
|
|
1081 sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
|
|
1082 sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
|
|
1083
|
|
1084 err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL);
|
|
1085 if (err) {
|
|
1086 ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
|
|
1087 ngx_thread_sigmask_n " failed");
|
112
|
1088 return (ngx_thread_value_t) 1;
|
0
|
1089 }
|
|
1090
|
|
1091 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
10
|
1092 "thread " NGX_TID_T_FMT " started", ngx_thread_self());
|
0
|
1093
|
|
1094 ngx_setthrtitle("worker thread");
|
|
1095
|
50
|
1096 tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log);
|
|
1097 if (tls == NULL) {
|
112
|
1098 return (ngx_thread_value_t) 1;
|
0
|
1099 }
|
|
1100
|
|
1101 err = ngx_thread_set_tls(ngx_core_tls_key, tls);
|
|
1102 if (err != 0) {
|
|
1103 ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
|
|
1104 ngx_thread_set_tls_n " failed");
|
112
|
1105 return (ngx_thread_value_t) 1;
|
0
|
1106 }
|
|
1107
|
112
|
1108 ngx_mutex_lock(ngx_posted_events_mutex);
|
0
|
1109
|
|
1110 for ( ;; ) {
|
|
1111 thr->state = NGX_THREAD_FREE;
|
|
1112
|
|
1113 if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) {
|
112
|
1114 return (ngx_thread_value_t) 1;
|
0
|
1115 }
|
|
1116
|
|
1117 if (ngx_terminate) {
|
|
1118 thr->state = NGX_THREAD_EXIT;
|
|
1119
|
|
1120 ngx_mutex_unlock(ngx_posted_events_mutex);
|
|
1121
|
|
1122 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
|
10
|
1123 "thread " NGX_TID_T_FMT " is done",
|
|
1124 ngx_thread_self());
|
0
|
1125
|
112
|
1126 return (ngx_thread_value_t) 0;
|
0
|
1127 }
|
|
1128
|
|
1129 thr->state = NGX_THREAD_BUSY;
|
|
1130
|
|
1131 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
|
112
|
1132 return (ngx_thread_value_t) 1;
|
0
|
1133 }
|
|
1134
|
|
1135 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
|
112
|
1136 return (ngx_thread_value_t) 1;
|
0
|
1137 }
|
|
1138
|
|
1139 if (ngx_process_changes) {
|
|
1140 if (ngx_process_changes(cycle, 1) == NGX_ERROR) {
|
112
|
1141 return (ngx_thread_value_t) 1;
|
0
|
1142 }
|
|
1143 }
|
|
1144 }
|
|
1145 }
|
|
1146
|
|
1147 #endif
|
16
|
1148
|
|
1149
|
50
|
1150 #if 0
|
|
1151
|
|
1152 static void
|
|
1153 ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
|
16
|
1154 {
|
|
1155 ngx_uint_t i;
|
|
1156 ngx_gc_t ctx;
|
|
1157 ngx_path_t **path;
|
|
1158 ngx_event_t *ev;
|
|
1159
|
22
|
1160 ngx_worker_process_init(cycle, 0);
|
16
|
1161
|
92
|
1162 ev = &cycle->read_events0[ngx_channel];
|
16
|
1163
|
|
1164 ngx_accept_mutex = NULL;
|
|
1165
|
|
1166 ngx_setproctitle("garbage collector");
|
|
1167
|
|
1168 #if 0
|
|
1169 ngx_add_timer(ev, 60 * 1000);
|
|
1170 #endif
|
|
1171
|
|
1172 for ( ;; ) {
|
|
1173
|
|
1174 if (ngx_terminate || ngx_quit) {
|
26
|
1175 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
|
16
|
1176 exit(0);
|
|
1177 }
|
|
1178
|
|
1179 if (ngx_reopen) {
|
|
1180 ngx_reopen = 0;
|
26
|
1181 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
|
16
|
1182 ngx_reopen_files(cycle, -1);
|
|
1183 }
|
|
1184
|
|
1185 path = cycle->pathes.elts;
|
|
1186 for (i = 0; i < cycle->pathes.nelts; i++) {
|
|
1187 ctx.path = path[i];
|
|
1188 ctx.log = cycle->log;
|
28
|
1189 ctx.handler = path[i]->cleaner;
|
16
|
1190
|
|
1191 ngx_collect_garbage(&ctx, &path[i]->name, 0);
|
|
1192 }
|
|
1193
|
|
1194 ngx_add_timer(ev, 60 * 60 * 1000);
|
|
1195
|
112
|
1196 ngx_process_events_and_timers(cycle);
|
16
|
1197 }
|
|
1198 }
|
50
|
1199
|
|
1200 #endif
|