Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_posix_cycle.c @ 370:54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 27 Jun 2004 18:01:57 +0000 |
parents | 8aa1bc7d06ba |
children |
rev | line source |
---|---|
228
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
3 void ngx_posix_master_cycle(ngx_cycle_t *cycle) |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
4 { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
5 static ngx_int_t sent; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 static ngx_msec_t delay = 125; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 if (ngx_process == NGX_PROCESS_MASTER) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 if (sent) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 "sent signal cycle"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 "sigprocmask() failed"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 continue; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 /* |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 * there is very big chance that the pending signals |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 * would be delivered right on the sigprocmask() return |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 */ |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 if (!ngx_signal) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 if (delay < 15000) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 delay *= 2; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 "msleep %d", delay); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 ngx_msleep(delay); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 ngx_gettimeofday(&tv); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 ngx_time_update(tv.tv_sec); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 "wake up"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 "sigprocmask() failed"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 ngx_signal = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 } else { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 "sigsuspend"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 sigsuspend(&wset); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 ngx_gettimeofday(&tv); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 ngx_time_update(tv.tv_sec); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 "wake up"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 } else { /* NGX_PROCESS_SINGLE */ |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 "worker cycle"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 ngx_process_events(cycle->log); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 if (ngx_reap) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 "reap childs"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 live = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 for (i = 0; i < ngx_last_process; i++) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 "child: " PID_T_FMT |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 " s:%d e:%d t:%d d:%d r:%d", |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 ngx_processes[i].pid, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 ngx_processes[i].signal, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 ngx_processes[i].exiting, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 ngx_processes[i].exited, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 ngx_processes[i].detached, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 ngx_processes[i].respawn); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 if (ngx_processes[i].exited) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 if (ngx_processes[i].respawn |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 && !ngx_processes[i].exiting |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 && !ngx_terminate |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 && !ngx_quit) |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 if (ngx_spawn_process(cycle, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 ngx_processes[i].proc, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 ngx_processes[i].data, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 ngx_processes[i].name, i) |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 == NGX_ERROR) |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 "can not respawn %s", |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 ngx_processes[i].name); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
104 continue; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 if (ngx_processes[i].pid == ngx_new_binary) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 ngx_new_binary = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 if (i != --ngx_last_process) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 ngx_processes[i--] = |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 ngx_processes[ngx_last_process]; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 } else if (!ngx_processes[i].detached |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 && (ngx_terminate || ngx_quit)) |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 live = 1; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 } else if (ngx_processes[i].exiting) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 live = 1; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 if (!live) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 if (ngx_terminate || ngx_quit) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 if (ngx_inherited && getppid() > 1) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 name = ctx->pid.name.data; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 } else { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 name = ctx->name; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 ngx_log_error(NGX_LOG_ALERT, cycle->log, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 ngx_errno, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 ngx_delete_file_n |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 " \"%s\" failed", name); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 exit(0); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 } else { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 sent = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 if (ngx_terminate) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 if (delay > 10000) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 signo = SIGKILL; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 } else { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 } else if (ngx_quit) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 } else { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 if (ngx_noaccept) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 if (ngx_change_binary) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 ngx_change_binary = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "changing binary"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 if (ngx_reconfigure) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 if (ngx_reopen) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 /* STUB */ |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopening logs"); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 ngx_reopen_files(cycle); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 if (signo) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 for (i = 0; i < ngx_last_process; i++) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 if (!ngx_processes[i].detached) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 ngx_processes[i].signal = signo; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 "signal " PID_T_FMT " %d", |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 ngx_processes[i].pid, signo); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 delay = 125; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 signo = 0; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 for (i = 0; i < ngx_last_process; i++) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 if (ngx_processes[i].signal == 0) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 continue; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 if (ccf->kqueue_signal != 1) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 sent = 1; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 "kill (" PID_T_FMT ", %d)" , |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 ngx_processes[i].pid, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 ngx_processes[i].signal); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 if (kill(ngx_processes[i].pid, ngx_processes[i].signal) == -1) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 "kill(%d, %d) failed", |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 ngx_processes[i].pid, ngx_processes[i].signal); |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
224 continue; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 if (ngx_processes[i].signal != ngx_signal_value(NGX_REOPEN_SIGNAL)) { |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 ngx_processes[i].exiting = 1; |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 } |
8aa1bc7d06ba
nginx-0.0.1-2004-01-15-11:12:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 } |