Mercurial > hg > nginx
annotate src/os/unix/ngx_process_cycle.c @ 3892:12d8d2f30205
use MurmurHash2 for split_clients, because
its distribution is much better than CRC32's one
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 15 Apr 2011 10:59:57 +0000 |
parents | 6843e7c492b7 |
children | 59b99f217c6d |
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); |
3018 | 15 static void ngx_start_cache_manager_processes(ngx_cycle_t *cycle, |
16 ngx_uint_t respawn); | |
17 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch); | |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
18 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); |
1565 | 19 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); |
573 | 20 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
|
21 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
473 | 22 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); |
573 | 23 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
|
24 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
|
25 #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
|
26 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); |
563 | 27 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
|
28 #endif |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
29 static void ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
30 static void ngx_cache_manager_process_handler(ngx_event_t *ev); |
3018 | 31 static void ngx_cache_loader_process_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
|
32 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 |
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_process; |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 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
|
36 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
|
37 |
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_reap; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
39 sig_atomic_t ngx_sigio; |
3048
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3047
diff
changeset
|
40 sig_atomic_t ngx_sigalrm; |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 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
|
42 sig_atomic_t ngx_quit; |
477 | 43 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
|
44 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
|
45 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
|
46 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
|
47 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
58 #if (NGX_THREADS) |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
59 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
|
60 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
|
61 #endif |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
62 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
63 |
577 | 64 u_long cpu_affinity; |
65 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
|
66 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
67 |
3018 | 68 static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = { |
69 ngx_cache_manager_process_handler, "cache manager process", 0 | |
70 }; | |
71 | |
72 static ngx_cache_manager_ctx_t ngx_cache_loader_ctx = { | |
73 ngx_cache_loader_process_handler, "cache loader process", 60000 | |
74 }; | |
75 | |
76 | |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
77 static ngx_cycle_t ngx_exit_cycle; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
78 static ngx_log_t ngx_exit_log; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
79 static ngx_open_file_t ngx_exit_log_file; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
80 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
81 |
501 | 82 void |
83 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
|
84 { |
329
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
85 char *title; |
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
86 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
|
87 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
|
88 ngx_int_t i; |
3293
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
89 ngx_uint_t n, sigio; |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
90 sigset_t set; |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
91 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
|
92 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
|
93 ngx_msec_t delay; |
531 | 94 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
|
95 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
|
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 sigaddset(&set, SIGCHLD); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
99 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
|
100 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
|
101 sigaddset(&set, SIGINT); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
109 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
|
110 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
|
111 "sigprocmask() failed"); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
112 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
113 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
114 sigemptyset(&set); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
115 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
116 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
117 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
|
118 |
452 | 119 for (i = 0; i < ngx_argc; i++) { |
120 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
|
121 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
122 |
2049 | 123 title = ngx_pnalloc(cycle->pool, size); |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
124 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
125 p = ngx_cpymem(title, master_process, sizeof(master_process) - 1); |
452 | 126 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
|
127 *p++ = ' '; |
452 | 128 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
|
129 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
130 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
131 ngx_setproctitle(title); |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
132 |
317
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 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
|
135 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
136 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
|
137 NGX_PROCESS_RESPAWN); |
3018 | 138 ngx_start_cache_manager_processes(cycle, 0); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
139 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
140 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
|
141 delay = 0; |
3293
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
142 sigio = 0; |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
143 live = 1; |
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 for ( ;; ) { |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
146 if (delay) { |
3048
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3047
diff
changeset
|
147 if (ngx_sigalrm) { |
3293
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
148 sigio = 0; |
3048
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3047
diff
changeset
|
149 delay *= 2; |
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3047
diff
changeset
|
150 ngx_sigalrm = 0; |
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3047
diff
changeset
|
151 } |
317
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 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
3046 | 154 "termination cycle: %d", delay); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
155 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
161 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
|
162 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
|
163 "setitimer() failed"); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
164 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
165 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
166 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
167 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
|
168 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
169 sigsuspend(&set); |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
170 |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
171 ngx_time_update(); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
172 |
3304
6832c7f5e189
fix building without --with-debug, introduced in r3294
Igor Sysoev <igor@sysoev.ru>
parents:
3293
diff
changeset
|
173 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
3293
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
174 "wake up, sigio %i", sigio); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
175 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
176 if (ngx_reap) { |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
177 ngx_reap = 0; |
1565 | 178 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap children"); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
179 |
1565 | 180 live = ngx_reap_children(cycle); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
181 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
182 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
183 if (!live && (ngx_terminate || ngx_quit)) { |
573 | 184 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
|
185 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
186 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
187 if (ngx_terminate) { |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
188 if (delay == 0) { |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
189 delay = 50; |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
190 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
191 |
3293
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
192 if (sigio) { |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
193 sigio--; |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
194 continue; |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
195 } |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
196 |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
197 sigio = ccf->worker_processes + 2 /* cache processes */; |
8abb88374c6c
Fix a bug introduced in r2032: After a child process has read a terminate
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
198 |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
199 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
|
200 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
|
201 } else { |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
202 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
|
203 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
|
204 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
205 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
206 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
207 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
208 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
209 if (ngx_quit) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
210 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
|
211 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); |
531 | 212 |
213 ls = cycle->listening.elts; | |
214 for (n = 0; n < cycle->listening.nelts; n++) { | |
215 if (ngx_close_socket(ls[n].fd) == -1) { | |
216 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno, | |
217 ngx_close_socket_n " %V failed", | |
218 &ls[n].addr_text); | |
219 } | |
220 } | |
221 cycle->listening.nelts = 0; | |
222 | |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
223 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
224 } |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
225 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
226 if (ngx_reconfigure) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
227 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
|
228 |
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
229 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
|
230 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
|
231 NGX_PROCESS_RESPAWN); |
3018 | 232 ngx_start_cache_manager_processes(cycle, 0); |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
448
diff
changeset
|
233 ngx_noaccepting = 0; |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
448
diff
changeset
|
234 |
329
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
235 continue; |
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
236 } |
9a0ffa21f193
nginx-0.0.3-2004-04-29-00:21:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
237 |
477 | 238 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
|
239 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
240 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
|
241 if (cycle == NULL) { |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
242 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
|
243 continue; |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
244 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
245 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
246 ngx_cycle = cycle; |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 NGX_PROCESS_JUST_RESPAWN); |
3018 | 251 ngx_start_cache_manager_processes(cycle, 1); |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
252 live = 1; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
253 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
|
254 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
|
255 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
256 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
257 if (ngx_restart) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
258 ngx_restart = 0; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
259 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
|
260 NGX_PROCESS_RESPAWN); |
3018 | 261 ngx_start_cache_manager_processes(cycle, 0); |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
262 live = 1; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
263 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
265 if (ngx_reopen) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
266 ngx_reopen = 0; |
477 | 267 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
|
268 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
|
269 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
|
270 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
|
271 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
273 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
|
274 ngx_change_binary = 0; |
477 | 275 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "changing binary"); |
452 | 276 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
|
277 } |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
278 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
279 if (ngx_noaccept) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
280 ngx_noaccept = 0; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
281 ngx_noaccepting = 1; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
282 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
|
283 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
|
284 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
285 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
286 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
287 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
288 |
501 | 289 void |
290 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
|
291 { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
292 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
|
293 |
3826
6843e7c492b7
allow "env" to work in the single process mode
Igor Sysoev <igor@sysoev.ru>
parents:
3762
diff
changeset
|
294 if (ngx_set_environment(cycle, NULL) == NULL) { |
6843e7c492b7
allow "env" to work in the single process mode
Igor Sysoev <igor@sysoev.ru>
parents:
3762
diff
changeset
|
295 /* fatal */ |
6843e7c492b7
allow "env" to work in the single process mode
Igor Sysoev <igor@sysoev.ru>
parents:
3762
diff
changeset
|
296 exit(2); |
6843e7c492b7
allow "env" to work in the single process mode
Igor Sysoev <igor@sysoev.ru>
parents:
3762
diff
changeset
|
297 } |
6843e7c492b7
allow "env" to work in the single process mode
Igor Sysoev <igor@sysoev.ru>
parents:
3762
diff
changeset
|
298 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 /* fatal */ |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
303 exit(2); |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
304 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
305 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
306 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
307 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
308 for ( ;; ) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
309 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
|
310 |
563 | 311 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
|
312 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
313 if (ngx_terminate || ngx_quit) { |
571 | 314 |
315 for (i = 0; ngx_modules[i]; i++) { | |
316 if (ngx_modules[i]->exit_process) { | |
317 ngx_modules[i]->exit_process(cycle); | |
318 } | |
319 } | |
320 | |
573 | 321 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
|
322 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
323 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
324 if (ngx_reconfigure) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
325 ngx_reconfigure = 0; |
477 | 326 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
|
327 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
328 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
|
329 if (cycle == NULL) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
330 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
|
331 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
332 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
333 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
334 ngx_cycle = cycle; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
335 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
336 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
337 if (ngx_reopen) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
338 ngx_reopen = 0; |
477 | 339 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
|
340 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
|
341 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
342 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
343 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
344 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
345 |
501 | 346 static void |
347 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
|
348 { |
3018 | 349 ngx_int_t i; |
557 | 350 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
|
351 |
477 | 352 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
|
353 |
360
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
357
diff
changeset
|
354 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
|
355 |
577 | 356 for (i = 0; i < n; i++) { |
357 | |
358 cpu_affinity = ngx_get_cpu_affinity(i); | |
359 | |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
360 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
|
361 "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
|
362 |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
357
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 |
3018 | 367 ngx_pass_open_channel(cycle, &ch); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
368 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
369 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
370 |
360
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
357
diff
changeset
|
371 |
501 | 372 static void |
3018 | 373 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn) |
467 | 374 { |
3018 | 375 ngx_uint_t i, manager, loader; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
376 ngx_path_t **path; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
377 ngx_channel_t ch; |
467 | 378 |
3018 | 379 manager = 0; |
380 loader = 0; | |
381 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
382 path = ngx_cycle->pathes.elts; |
3018 | 383 for (i = 0; i < ngx_cycle->pathes.nelts; i++) { |
384 | |
385 if (path[i]->manager) { | |
386 manager = 1; | |
387 } | |
388 | |
389 if (path[i]->loader) { | |
390 loader = 1; | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
391 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
392 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
393 |
3018 | 394 if (manager == 0) { |
395 return; | |
396 } | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
397 |
3018 | 398 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle, |
399 &ngx_cache_manager_ctx, "cache manager process", | |
400 respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN); | |
467 | 401 |
402 ch.command = NGX_CMD_OPEN_CHANNEL; | |
403 ch.pid = ngx_processes[ngx_process_slot].pid; | |
404 ch.slot = ngx_process_slot; | |
405 ch.fd = ngx_processes[ngx_process_slot].channel[0]; | |
406 | |
3018 | 407 ngx_pass_open_channel(cycle, &ch); |
408 | |
409 if (loader == 0) { | |
410 return; | |
411 } | |
412 | |
413 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle, | |
414 &ngx_cache_loader_ctx, "cache loader process", | |
415 respawn ? NGX_PROCESS_JUST_SPAWN : NGX_PROCESS_NORESPAWN); | |
416 | |
417 ch.command = NGX_CMD_OPEN_CHANNEL; | |
418 ch.pid = ngx_processes[ngx_process_slot].pid; | |
419 ch.slot = ngx_process_slot; | |
420 ch.fd = ngx_processes[ngx_process_slot].channel[0]; | |
421 | |
422 ngx_pass_open_channel(cycle, &ch); | |
423 } | |
424 | |
425 | |
426 static void | |
427 ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch) | |
428 { | |
429 ngx_int_t i; | |
430 | |
467 | 431 for (i = 0; i < ngx_last_process; i++) { |
432 | |
433 if (i == ngx_process_slot | |
434 || ngx_processes[i].pid == -1 | |
435 || ngx_processes[i].channel[0] == -1) | |
436 { | |
437 continue; | |
438 } | |
439 | |
440 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
441 "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d", | |
3018 | 442 ch->slot, ch->pid, ch->fd, |
467 | 443 i, ngx_processes[i].pid, |
444 ngx_processes[i].channel[0]); | |
445 | |
446 /* TODO: NGX_AGAIN */ | |
447 | |
448 ngx_write_channel(ngx_processes[i].channel[0], | |
3018 | 449 ch, sizeof(ngx_channel_t), cycle->log); |
467 | 450 } |
451 } | |
452 | |
453 | |
501 | 454 static void |
455 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
|
456 { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
457 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
|
458 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
|
459 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
|
460 |
1581
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
461 #if (NGX_BROKEN_SCM_RIGHTS) |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
462 |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
463 ch.command = 0; |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
464 |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
465 #else |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
466 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
467 switch (signo) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
468 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
469 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
|
470 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
|
471 break; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
472 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
473 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
|
474 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
|
475 break; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
476 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
477 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
|
478 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
|
479 break; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
480 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
481 default: |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
482 ch.command = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
483 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
484 |
1581
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
485 #endif |
81774dc3db28
Cygwin can not pass SCM_RIGHTS via unix socket, use signals
Igor Sysoev <igor@sysoev.ru>
parents:
1578
diff
changeset
|
486 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
487 ch.fd = -1; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
488 |
318
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 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
|
491 |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
448
diff
changeset
|
492 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 493 "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
|
494 i, |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
448
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 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
|
499 ngx_processes[i].respawn, |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
500 ngx_processes[i].just_spawn); |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
448
diff
changeset
|
501 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
502 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
|
503 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
504 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
505 |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
506 if (ngx_processes[i].just_spawn) { |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
507 ngx_processes[i].just_spawn = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
508 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
509 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
510 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
511 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
|
512 && 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
|
513 { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
514 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
515 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
516 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
517 if (ch.command) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
518 if (ngx_write_channel(ngx_processes[i].channel[0], |
1132 | 519 &ch, sizeof(ngx_channel_t), cycle->log) |
520 == NGX_OK) | |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
521 { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
522 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
|
523 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
|
524 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
525 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
526 continue; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
527 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
528 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
529 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
530 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
461 | 531 "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
|
532 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
533 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
|
534 err = ngx_errno; |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
535 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, |
3047 | 536 "kill(%P, %d) failed", 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
|
537 |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 ngx_reap = 1; |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
542 } |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
543 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
544 continue; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
545 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
546 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
547 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
|
548 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
|
549 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
550 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
551 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
317
diff
changeset
|
552 |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
553 |
501 | 554 static ngx_uint_t |
1565 | 555 ngx_reap_children(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
|
556 { |
543 | 557 ngx_int_t i, n; |
558 ngx_uint_t live; | |
559 ngx_channel_t ch; | |
560 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
|
561 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
562 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
|
563 ch.fd = -1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
564 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
565 live = 0; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
566 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
|
567 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
568 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 569 "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
|
570 i, |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 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
|
575 ngx_processes[i].respawn, |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
576 ngx_processes[i].just_spawn); |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
577 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
578 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
|
579 continue; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
580 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
581 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
582 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
|
583 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
584 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
|
585 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
|
586 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
587 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
|
588 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
|
589 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
590 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
|
591 ch.slot = i; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
592 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
593 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
|
594 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
|
595 || 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
|
596 || 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
|
597 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
598 continue; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
599 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
600 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
601 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
461 | 602 "pass close channel s:%i pid:%P to:%P", |
603 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
|
604 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
605 /* TODO: NGX_AGAIN */ |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
606 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
607 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
|
608 &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
|
609 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
610 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
611 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
612 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
|
613 && !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
|
614 && !ngx_terminate |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
615 && !ngx_quit) |
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 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
|
618 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
|
619 ngx_processes[i].name, i) |
543 | 620 == 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
|
621 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
622 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
|
623 "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
|
624 continue; |
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 |
473 | 627 |
628 ch.command = NGX_CMD_OPEN_CHANNEL; | |
629 ch.pid = ngx_processes[ngx_process_slot].pid; | |
630 ch.slot = ngx_process_slot; | |
631 ch.fd = ngx_processes[ngx_process_slot].channel[0]; | |
632 | |
3018 | 633 ngx_pass_open_channel(cycle, &ch); |
473 | 634 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
635 live = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
636 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
637 continue; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
638 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
639 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
640 if (ngx_processes[i].pid == ngx_new_binary) { |
543 | 641 |
642 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, | |
643 ngx_core_module); | |
644 | |
645 if (ngx_rename_file((char *) ccf->oldpid.data, | |
646 (char *) ccf->pid.data) | |
647 != NGX_OK) | |
648 { | |
649 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
650 ngx_rename_file_n " %s back to %s failed " | |
651 "after the new binary process \"%s\" exited", | |
652 ccf->oldpid.data, ccf->pid.data, ngx_argv[0]); | |
653 } | |
654 | |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
655 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
|
656 if (ngx_noaccepting) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
657 ngx_restart = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
658 ngx_noaccepting = 0; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
659 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
660 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
661 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
662 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
|
663 ngx_last_process--; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
664 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
665 } else { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
666 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
|
667 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
668 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
669 } 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
|
670 live = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
671 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
672 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
673 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
674 return live; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
675 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
676 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
677 |
501 | 678 static void |
573 | 679 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
|
680 { |
571 | 681 ngx_uint_t i; |
682 | |
310
a9a9af2c7370
nginx-0.0.3-2004-04-12-10:10:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
683 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
|
684 |
477 | 685 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
|
686 |
571 | 687 for (i = 0; ngx_modules[i]; i++) { |
688 if (ngx_modules[i]->exit_master) { | |
689 ngx_modules[i]->exit_master(cycle); | |
690 } | |
691 } | |
692 | |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3048
diff
changeset
|
693 ngx_close_listening_sockets(cycle); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3048
diff
changeset
|
694 |
505 | 695 /* |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
696 * Copy ngx_cycle->log related data to the special static exit cycle, |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
697 * log, and log file structures enough to allow a signal handler to log. |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
698 * The handler may be called when standard ngx_cycle->log allocated from |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
699 * ngx_cycle->pool is already destroyed. |
505 | 700 */ |
701 | |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
702 ngx_exit_log_file.fd = ngx_cycle->log->file->fd; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
703 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
704 ngx_exit_log = *ngx_cycle->log; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
705 ngx_exit_log.file = &ngx_exit_log_file; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
706 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
707 ngx_exit_cycle.log = &ngx_exit_log; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
708 ngx_cycle = &ngx_exit_cycle; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
709 |
322
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
710 ngx_destroy_pool(cycle->pool); |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
711 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
712 exit(0); |
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 |
501 | 716 static void |
717 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
|
718 { |
1135
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
719 ngx_uint_t i; |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
720 ngx_connection_t *c; |
469 | 721 |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3304
diff
changeset
|
722 ngx_process = NGX_PROCESS_WORKER; |
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3304
diff
changeset
|
723 |
473 | 724 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
|
725 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
726 ngx_setproctitle("worker process"); |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
727 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
728 #if (NGX_THREADS) |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1581
diff
changeset
|
729 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1581
diff
changeset
|
730 ngx_int_t n; |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1581
diff
changeset
|
731 ngx_err_t err; |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1581
diff
changeset
|
732 ngx_core_conf_t *ccf; |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
733 |
469 | 734 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
735 | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
736 if (ngx_threads_n) { |
1133 | 737 if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle) |
738 == NGX_ERROR) | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
739 { |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
740 /* fatal */ |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
741 exit(2); |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
742 } |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
743 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
744 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
|
745 if (err != 0) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
746 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
|
747 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
|
748 /* fatal */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
749 exit(2); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
750 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
751 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
752 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
|
753 |
501 | 754 ngx_threads[n].cv = ngx_cond_init(cycle->log); |
755 | |
756 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
|
757 /* fatal */ |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
758 exit(2); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
759 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
760 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
761 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
|
762 ngx_worker_thread_cycle, |
1133 | 763 (void *) &ngx_threads[n], cycle->log) |
764 != 0) | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
765 { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
766 /* fatal */ |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
767 exit(2); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
768 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
769 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
770 } |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1581
diff
changeset
|
771 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
772 #endif |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
773 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
774 for ( ;; ) { |
1135
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
775 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
776 if (ngx_exiting) { |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
777 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
778 c = cycle->connections; |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
779 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
780 for (i = 0; i < cycle->connection_n; i++) { |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
781 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
782 /* THREAD: lock */ |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
783 |
1135
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
784 if (c[i].fd != -1 && c[i].idle) { |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
785 c[i].close = 1; |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
786 c[i].read->handler(c[i].read); |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
787 } |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
788 } |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
789 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
790 if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel) |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
791 { |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
792 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
793 |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
794 ngx_worker_process_exit(cycle); |
03f1133f24e8
close keep-alive connections in the shuting down processes
Igor Sysoev <igor@sysoev.ru>
parents:
1134
diff
changeset
|
795 } |
322
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
796 } |
ab2f8c9a2a45
nginx-0.0.3-2004-04-20-11:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
797 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
798 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
|
799 |
563 | 800 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
|
801 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
802 if (ngx_terminate) { |
477 | 803 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
|
804 |
573 | 805 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
|
806 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
807 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
808 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
|
809 ngx_quit = 0; |
477 | 810 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
|
811 "gracefully shutting down"); |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
812 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
|
813 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
814 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
|
815 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
|
816 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
|
817 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
818 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
819 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
820 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
|
821 ngx_reopen = 0; |
477 | 822 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
|
823 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
|
824 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
825 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
826 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
827 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
828 |
501 | 829 static void |
830 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority) | |
467 | 831 { |
1069 | 832 sigset_t set; |
833 ngx_int_t n; | |
834 ngx_uint_t i; | |
835 struct rlimit rlmt; | |
836 ngx_core_conf_t *ccf; | |
837 ngx_listening_t *ls; | |
467 | 838 |
1069 | 839 if (ngx_set_environment(cycle, NULL) == NULL) { |
840 /* fatal */ | |
841 exit(2); | |
842 } | |
843 | |
467 | 844 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
845 | |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
846 if (priority && ccf->priority != 0) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
847 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
848 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
849 "setpriority(%d) failed", ccf->priority); |
473 | 850 } |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
851 } |
473 | 852 |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
853 if (ccf->rlimit_nofile != NGX_CONF_UNSET) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
854 rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile; |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
855 rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile; |
543 | 856 |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
857 if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
858 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
859 "setrlimit(RLIMIT_NOFILE, %i) failed", |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
860 ccf->rlimit_nofile); |
543 | 861 } |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
862 } |
543 | 863 |
3762
89002ac695e5
worker_rlimit_core should be off_t
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
864 if (ccf->rlimit_core != NGX_CONF_UNSET) { |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
865 rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
866 rlmt.rlim_max = (rlim_t) ccf->rlimit_core; |
589 | 867 |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
868 if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
869 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
3762
89002ac695e5
worker_rlimit_core should be off_t
Igor Sysoev <igor@sysoev.ru>
parents:
3475
diff
changeset
|
870 "setrlimit(RLIMIT_CORE, %O) failed", |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
871 ccf->rlimit_core); |
589 | 872 } |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
873 } |
589 | 874 |
543 | 875 #ifdef RLIMIT_SIGPENDING |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
876 if (ccf->rlimit_sigpending != NGX_CONF_UNSET) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
877 rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending; |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
878 rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending; |
543 | 879 |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
880 if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) { |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
881 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
882 "setrlimit(RLIMIT_SIGPENDING, %i) failed", |
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
883 ccf->rlimit_sigpending); |
543 | 884 } |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
885 } |
543 | 886 #endif |
887 | |
1404
df2592d32e49
set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
Igor Sysoev <igor@sysoev.ru>
parents:
1135
diff
changeset
|
888 if (geteuid() == 0) { |
467 | 889 if (setgid(ccf->group) == -1) { |
890 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
891 "setgid(%d) failed", ccf->group); | |
892 /* fatal */ | |
893 exit(2); | |
894 } | |
895 | |
473 | 896 if (initgroups(ccf->username, ccf->group) == -1) { |
897 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
898 "initgroups(%s, %d) failed", | |
899 ccf->username, ccf->group); | |
900 } | |
901 | |
467 | 902 if (setuid(ccf->user) == -1) { |
903 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
904 "setuid(%d) failed", ccf->user); | |
905 /* fatal */ | |
906 exit(2); | |
907 } | |
908 } | |
909 | |
577 | 910 #if (NGX_HAVE_SCHED_SETAFFINITY) |
911 | |
912 if (cpu_affinity) { | |
913 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, | |
914 "sched_setaffinity(0x%08Xl)", cpu_affinity); | |
915 | |
916 if (sched_setaffinity(0, 32, (cpu_set_t *) &cpu_affinity) == -1) { | |
917 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
918 "sched_setaffinity(0x%08Xl) failed", cpu_affinity); | |
919 } | |
920 } | |
921 | |
922 #endif | |
923 | |
467 | 924 #if (NGX_HAVE_PR_SET_DUMPABLE) |
925 | |
926 /* allow coredump after setuid() in Linux 2.4.x */ | |
927 | |
928 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) { | |
929 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
930 "prctl(PR_SET_DUMPABLE) failed"); | |
931 } | |
932 | |
933 #endif | |
934 | |
521 | 935 if (ccf->working_directory.len) { |
523 | 936 if (chdir((char *) ccf->working_directory.data) == -1) { |
521 | 937 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
938 "chdir(\"%s\") failed", ccf->working_directory.data); | |
939 /* fatal */ | |
940 exit(2); | |
941 } | |
942 } | |
943 | |
467 | 944 sigemptyset(&set); |
945 | |
946 if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) { | |
947 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
948 "sigprocmask() failed"); | |
949 } | |
950 | |
951 /* | |
952 * disable deleting previous events for the listening sockets because | |
953 * in the worker processes there are no events at all at this point | |
577 | 954 */ |
467 | 955 ls = cycle->listening.elts; |
956 for (i = 0; i < cycle->listening.nelts; i++) { | |
543 | 957 ls[i].previous = NULL; |
467 | 958 } |
959 | |
960 for (i = 0; ngx_modules[i]; i++) { | |
961 if (ngx_modules[i]->init_process) { | |
962 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { | |
963 /* fatal */ | |
964 exit(2); | |
965 } | |
966 } | |
967 } | |
968 | |
969 for (n = 0; n < ngx_last_process; n++) { | |
970 | |
971 if (ngx_processes[n].pid == -1) { | |
972 continue; | |
973 } | |
974 | |
975 if (n == ngx_process_slot) { | |
976 continue; | |
977 } | |
978 | |
979 if (ngx_processes[n].channel[1] == -1) { | |
980 continue; | |
981 } | |
982 | |
983 if (close(ngx_processes[n].channel[1]) == -1) { | |
984 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
985 "close() channel failed"); | |
986 } | |
987 } | |
988 | |
989 if (close(ngx_processes[ngx_process_slot].channel[0]) == -1) { | |
990 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
991 "close() channel failed"); | |
992 } | |
993 | |
994 #if 0 | |
995 ngx_last_process = 0; | |
996 #endif | |
997 | |
998 if (ngx_add_channel_event(cycle, ngx_channel, NGX_READ_EVENT, | |
1133 | 999 ngx_channel_handler) |
1000 == NGX_ERROR) | |
467 | 1001 { |
1002 /* fatal */ | |
1003 exit(2); | |
1004 } | |
1005 } | |
1006 | |
1007 | |
501 | 1008 static void |
573 | 1009 ngx_worker_process_exit(ngx_cycle_t *cycle) |
1010 { | |
1011 ngx_uint_t i; | |
1012 ngx_connection_t *c; | |
1013 | |
1014 #if (NGX_THREADS) | |
1015 ngx_terminate = 1; | |
1016 | |
1017 ngx_wakeup_worker_threads(cycle); | |
1018 #endif | |
1019 | |
1020 for (i = 0; ngx_modules[i]; i++) { | |
1021 if (ngx_modules[i]->exit_process) { | |
1022 ngx_modules[i]->exit_process(cycle); | |
1023 } | |
1024 } | |
1025 | |
1905
0cafbfd8112e
left open sockets were not really tested
Igor Sysoev <igor@sysoev.ru>
parents:
1900
diff
changeset
|
1026 if (ngx_exiting) { |
587 | 1027 c = cycle->connections; |
1028 for (i = 0; i < cycle->connection_n; i++) { | |
1029 if (c[i].fd != -1 | |
1030 && c[i].read | |
1031 && !c[i].read->accept | |
1905
0cafbfd8112e
left open sockets were not really tested
Igor Sysoev <igor@sysoev.ru>
parents:
1900
diff
changeset
|
1032 && !c[i].read->channel |
0cafbfd8112e
left open sockets were not really tested
Igor Sysoev <igor@sysoev.ru>
parents:
1900
diff
changeset
|
1033 && !c[i].read->resolver) |
587 | 1034 { |
1035 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
3026
f4b5c787fe33
fix debug point for left open sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3019
diff
changeset
|
1036 "open socket #%d left in connection %ui", |
f4b5c787fe33
fix debug point for left open sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3019
diff
changeset
|
1037 c[i].fd, i); |
f4b5c787fe33
fix debug point for left open sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3019
diff
changeset
|
1038 ngx_debug_quit = 1; |
587 | 1039 } |
573 | 1040 } |
1041 | |
587 | 1042 if (ngx_debug_quit) { |
3026
f4b5c787fe33
fix debug point for left open sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3019
diff
changeset
|
1043 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "aborting"); |
587 | 1044 ngx_debug_point(); |
1045 } | |
573 | 1046 } |
1047 | |
1048 /* | |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1049 * Copy ngx_cycle->log related data to the special static exit cycle, |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1050 * log, and log file structures enough to allow a signal handler to log. |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1051 * The handler may be called when standard ngx_cycle->log allocated from |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1052 * ngx_cycle->pool is already destroyed. |
573 | 1053 */ |
1054 | |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1055 ngx_exit_log_file.fd = ngx_cycle->log->file->fd; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1056 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1057 ngx_exit_log = *ngx_cycle->log; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1058 ngx_exit_log.file = &ngx_exit_log_file; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1059 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1060 ngx_exit_cycle.log = &ngx_exit_log; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1061 ngx_cycle = &ngx_exit_cycle; |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1062 |
573 | 1063 ngx_destroy_pool(cycle->pool); |
1437
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1064 |
e498f4cb1663
destroy ngx_cycle->pool on exit
Igor Sysoev <igor@sysoev.ru>
parents:
1404
diff
changeset
|
1065 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, "exit"); |
573 | 1066 |
1067 exit(0); | |
1068 } | |
1069 | |
1070 | |
1071 static void | |
501 | 1072 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
|
1073 { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1074 ngx_int_t n; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1075 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
|
1076 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
|
1077 |
467 | 1078 if (ev->timedout) { |
1079 ev->timedout = 0; | |
1080 return; | |
1081 } | |
1082 | |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1083 c = ev->data; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1084 |
357
e260514b9ad4
nginx-0.0.7-2004-06-16-23:36:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
1085 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
|
1086 |
2031 | 1087 for ( ;; ) { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1088 |
2031 | 1089 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log); |
1090 | |
1091 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
|
1092 |
2031 | 1093 if (n == NGX_ERROR) { |
1900
55a9d867e3c8
avoid endless loop if epoll is used
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
1094 |
2031 | 1095 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) { |
1096 ngx_del_conn(c, 0); | |
1097 } | |
1098 | |
1099 ngx_close_connection(c); | |
1100 return; | |
1900
55a9d867e3c8
avoid endless loop if epoll is used
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
1101 } |
55a9d867e3c8
avoid endless loop if epoll is used
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
1102 |
2031 | 1103 if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) { |
1104 if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) { | |
1105 return; | |
1106 } | |
1107 } | |
461 | 1108 |
2031 | 1109 if (n == NGX_AGAIN) { |
1134
384c92c210f9
worker processes did not exit after reconfiguration and
Igor Sysoev <igor@sysoev.ru>
parents:
1133
diff
changeset
|
1110 return; |
384c92c210f9
worker processes did not exit after reconfiguration and
Igor Sysoev <igor@sysoev.ru>
parents:
1133
diff
changeset
|
1111 } |
2031 | 1112 |
1113 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, | |
1114 "channel command: %d", ch.command); | |
1134
384c92c210f9
worker processes did not exit after reconfiguration and
Igor Sysoev <igor@sysoev.ru>
parents:
1133
diff
changeset
|
1115 |
2031 | 1116 switch (ch.command) { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1117 |
2031 | 1118 case NGX_CMD_QUIT: |
1119 ngx_quit = 1; | |
1120 break; | |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1121 |
2031 | 1122 case NGX_CMD_TERMINATE: |
1123 ngx_terminate = 1; | |
1124 break; | |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1125 |
2031 | 1126 case NGX_CMD_REOPEN: |
1127 ngx_reopen = 1; | |
1128 break; | |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1129 |
2031 | 1130 case NGX_CMD_OPEN_CHANNEL: |
360
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
357
diff
changeset
|
1131 |
2031 | 1132 ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0, |
1133 "get channel s:%i pid:%P fd:%d", | |
1134 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
|
1135 |
2031 | 1136 ngx_processes[ch.slot].pid = ch.pid; |
1137 ngx_processes[ch.slot].channel[0] = ch.fd; | |
1138 break; | |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
1139 |
2031 | 1140 case NGX_CMD_CLOSE_CHANNEL: |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
1141 |
2031 | 1142 ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0, |
1143 "close channel s:%i pid:%P our:%P fd:%d", | |
1144 ch.slot, ch.pid, ngx_processes[ch.slot].pid, | |
1145 ngx_processes[ch.slot].channel[0]); | |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
1146 |
2031 | 1147 if (close(ngx_processes[ch.slot].channel[0]) == -1) { |
1148 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, | |
1149 "close() channel failed"); | |
1150 } | |
1151 | |
1152 ngx_processes[ch.slot].channel[0] = -1; | |
1153 break; | |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
362
diff
changeset
|
1154 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1155 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1156 } |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1157 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
345
diff
changeset
|
1158 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1159 #if (NGX_THREADS) |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1160 |
501 | 1161 static void |
1162 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
|
1163 { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1164 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
|
1165 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
|
1166 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1167 for ( ;; ) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1168 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1169 live = 0; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1170 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1171 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
|
1172 if (ngx_threads[i].state < NGX_THREAD_EXIT) { |
469 | 1173 if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) { |
1174 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
|
1175 |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
1176 } else { |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
1177 live = 1; |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
1178 } |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1179 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1180 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1181 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
|
1182 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
|
1183 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
|
1184 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1185 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1186 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1187 if (live == 0) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1188 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
|
1189 "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
|
1190 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1191 /* STUB */ |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1192 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
|
1193 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
|
1194 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
|
1195 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1196 return; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1197 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1198 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1199 ngx_sched_yield(); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1200 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1201 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1202 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1203 |
563 | 1204 static ngx_thread_value_t |
501 | 1205 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
|
1206 { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1207 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
|
1208 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
1209 sigset_t set; |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
1210 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
|
1211 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
|
1212 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
|
1213 |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1214 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
|
1215 |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
1216 sigemptyset(&set); |
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
1217 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
|
1218 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
|
1219 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
|
1220 |
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
1221 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
|
1222 if (err) { |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1223 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
|
1224 ngx_thread_sigmask_n " failed"); |
563 | 1225 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
|
1226 } |
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
1227 |
382
449c4885dcd1
nginx-0.0.7-2004-07-07-23:48:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
1228 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
461 | 1229 "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
|
1230 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1231 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
|
1232 |
501 | 1233 tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log); |
1234 if (tls == NULL) { | |
563 | 1235 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
|
1236 } |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
1237 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
1238 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
|
1239 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
|
1240 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
|
1241 ngx_thread_set_tls_n " failed"); |
563 | 1242 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
|
1243 } |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
1244 |
563 | 1245 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
|
1246 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
1247 for ( ;; ) { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1248 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
|
1249 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1250 if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) { |
563 | 1251 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
|
1252 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1253 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1254 if (ngx_terminate) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1255 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
|
1256 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1257 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
|
1258 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
1259 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
461 | 1260 "thread " NGX_TID_T_FMT " is done", |
1261 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
|
1262 |
563 | 1263 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
|
1264 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1265 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1266 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
|
1267 |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1268 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { |
563 | 1269 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
|
1270 } |
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1271 |
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1272 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { |
563 | 1273 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
|
1274 } |
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
1275 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
1276 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
|
1277 if (ngx_process_changes(cycle, 1) == NGX_ERROR) { |
563 | 1278 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
|
1279 } |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
1280 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
1281 } |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1282 } |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1283 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1284 #endif |
467 | 1285 |
1286 | |
501 | 1287 static void |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
1288 ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data) |
467 | 1289 { |
3018 | 1290 ngx_cache_manager_ctx_t *ctx = data; |
1291 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1292 void *ident[4]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1293 ngx_event_t ev; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1294 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1295 cycle->connection_n = 512; |
467 | 1296 |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3304
diff
changeset
|
1297 ngx_process = NGX_PROCESS_HELPER; |
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3304
diff
changeset
|
1298 |
473 | 1299 ngx_worker_process_init(cycle, 0); |
467 | 1300 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1301 ngx_close_listening_sockets(cycle); |
467 | 1302 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1303 ngx_memzero(&ev, sizeof(ngx_event_t)); |
3018 | 1304 ev.handler = ctx->handler; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1305 ev.data = ident; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1306 ev.log = cycle->log; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1307 ident[3] = (void *) -1; |
467 | 1308 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1309 ngx_use_accept_mutex = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1310 |
3018 | 1311 ngx_setproctitle(ctx->name); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1312 |
3018 | 1313 ngx_add_timer(&ev, ctx->delay); |
467 | 1314 |
1315 for ( ;; ) { | |
1316 | |
1317 if (ngx_terminate || ngx_quit) { | |
477 | 1318 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); |
467 | 1319 exit(0); |
1320 } | |
1321 | |
1322 if (ngx_reopen) { | |
1323 ngx_reopen = 0; | |
477 | 1324 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs"); |
467 | 1325 ngx_reopen_files(cycle, -1); |
1326 } | |
1327 | |
563 | 1328 ngx_process_events_and_timers(cycle); |
467 | 1329 } |
1330 } | |
501 | 1331 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1332 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1333 static void |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
1334 ngx_cache_manager_process_handler(ngx_event_t *ev) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1335 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1336 time_t next, n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1337 ngx_uint_t i; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1338 ngx_path_t **path; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1339 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1340 next = 60 * 60; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1341 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1342 path = ngx_cycle->pathes.elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1343 for (i = 0; i < ngx_cycle->pathes.nelts; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1344 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
1345 if (path[i]->manager) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
1346 n = path[i]->manager(path[i]->data); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1347 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1348 next = (n <= next) ? n : next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1349 |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
1350 ngx_time_update(); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1351 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1352 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1353 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1354 if (next == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1355 next = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1356 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1357 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1358 ngx_add_timer(ev, next * 1000); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2522
diff
changeset
|
1359 } |
3018 | 1360 |
1361 | |
1362 static void | |
1363 ngx_cache_loader_process_handler(ngx_event_t *ev) | |
1364 { | |
1365 ngx_uint_t i; | |
1366 ngx_path_t **path; | |
1367 ngx_cycle_t *cycle; | |
1368 | |
1369 cycle = (ngx_cycle_t *) ngx_cycle; | |
1370 | |
1371 path = cycle->pathes.elts; | |
1372 for (i = 0; i < cycle->pathes.nelts; i++) { | |
1373 | |
1374 if (ngx_terminate || ngx_quit) { | |
1375 break; | |
1376 } | |
1377 | |
1378 if (path[i]->loader) { | |
1379 path[i]->loader(path[i]->data); | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
1380 ngx_time_update(); |
3018 | 1381 } |
1382 } | |
1383 | |
1384 exit(0); | |
1385 } |