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