Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_process.c @ 5860:c9787372f16d
Limit conn: use complex value in limit_conn_zone (ticket #121).
One intentional side effect of this change is that key is allowed only
in the first position. Previously, it was possible to specify the key
variable at any position, but that was never documented, and is contrary
to nginx configuration practice for positional parameters.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 24 Sep 2014 21:55:19 +0400 |
parents | 593d344999f5 |
children | 2b7dacb381ed |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
10 #include <ngx_event.h> |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
11 #include <ngx_channel.h> |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
539 | 14 typedef struct { |
3681 | 15 int signo; |
16 char *signame; | |
17 char *name; | |
18 void (*handler)(int signo); | |
539 | 19 } ngx_signal_t; |
20 | |
21 | |
22 | |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
23 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); |
539 | 24 static void ngx_signal_handler(int signo); |
25 static void ngx_process_get_status(void); | |
4311
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
26 static void ngx_unlock_mutexes(ngx_pid_t pid); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
27 |
452 | 28 |
29 int ngx_argc; | |
30 char **ngx_argv; | |
31 char **ngx_os_argv; | |
32 | |
33 ngx_int_t ngx_process_slot; | |
34 ngx_socket_t ngx_channel; | |
35 ngx_int_t ngx_last_process; | |
36 ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
539 | 39 ngx_signal_t signals[] = { |
40 { ngx_signal_value(NGX_RECONFIGURE_SIGNAL), | |
41 "SIG" ngx_value(NGX_RECONFIGURE_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
42 "reload", |
539 | 43 ngx_signal_handler }, |
44 | |
45 { ngx_signal_value(NGX_REOPEN_SIGNAL), | |
46 "SIG" ngx_value(NGX_REOPEN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
47 "reopen", |
539 | 48 ngx_signal_handler }, |
49 | |
50 { ngx_signal_value(NGX_NOACCEPT_SIGNAL), | |
51 "SIG" ngx_value(NGX_NOACCEPT_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
52 "", |
539 | 53 ngx_signal_handler }, |
54 | |
55 { ngx_signal_value(NGX_TERMINATE_SIGNAL), | |
56 "SIG" ngx_value(NGX_TERMINATE_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
57 "stop", |
539 | 58 ngx_signal_handler }, |
59 | |
60 { ngx_signal_value(NGX_SHUTDOWN_SIGNAL), | |
61 "SIG" ngx_value(NGX_SHUTDOWN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
62 "quit", |
539 | 63 ngx_signal_handler }, |
64 | |
65 { ngx_signal_value(NGX_CHANGEBIN_SIGNAL), | |
66 "SIG" ngx_value(NGX_CHANGEBIN_SIGNAL), | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
67 "", |
539 | 68 ngx_signal_handler }, |
69 | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
70 { SIGALRM, "SIGALRM", "", ngx_signal_handler }, |
539 | 71 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
72 { SIGINT, "SIGINT", "", ngx_signal_handler }, |
539 | 73 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
74 { SIGIO, "SIGIO", "", ngx_signal_handler }, |
539 | 75 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
76 { SIGCHLD, "SIGCHLD", "", ngx_signal_handler }, |
539 | 77 |
3045 | 78 { SIGSYS, "SIGSYS, SIG_IGN", "", SIG_IGN }, |
79 | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
80 { SIGPIPE, "SIGPIPE, SIG_IGN", "", SIG_IGN }, |
539 | 81 |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
82 { 0, NULL, "", NULL } |
539 | 83 }; |
84 | |
85 | |
515 | 86 ngx_pid_t |
87 ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, | |
88 char *name, ngx_int_t respawn) | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 { |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
90 u_long on; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
91 ngx_pid_t pid; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
92 ngx_int_t s; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
93 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
94 if (respawn >= 0) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
95 s = respawn; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
96 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
97 } else { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
98 for (s = 0; s < ngx_last_process; s++) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
99 if (ngx_processes[s].pid == -1) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
100 break; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
101 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
102 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
103 |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
104 if (s == NGX_MAX_PROCESSES) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
105 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
106 "no more than %d processes can be spawned", |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
107 NGX_MAX_PROCESSES); |
543 | 108 return NGX_INVALID_PID; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
109 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
110 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
111 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
112 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
113 if (respawn != NGX_PROCESS_DETACHED) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
114 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
115 /* Solaris 9 still has no AF_LOCAL */ |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
116 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
117 if (socketpair(AF_UNIX, SOCK_STREAM, 0, ngx_processes[s].channel) == -1) |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
118 { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
119 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
120 "socketpair() failed while spawning \"%s\"", name); |
543 | 121 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
122 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
123 |
391
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
124 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
125 "channel %d:%d", |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
126 ngx_processes[s].channel[0], |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
127 ngx_processes[s].channel[1]); |
b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
128 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
129 if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
130 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
131 ngx_nonblocking_n " failed while spawning \"%s\"", |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
132 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
133 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 134 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
135 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
136 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
137 if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
138 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
139 ngx_nonblocking_n " failed while spawning \"%s\"", |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
140 name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
141 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 142 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
143 } |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
144 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
145 on = 1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
146 if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
147 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
148 "ioctl(FIOASYNC) failed while spawning \"%s\"", name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
149 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 150 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
151 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
152 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
153 if (fcntl(ngx_processes[s].channel[0], F_SETOWN, ngx_pid) == -1) { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
154 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
155 "fcntl(F_SETOWN) failed while spawning \"%s\"", name); |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
156 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 157 return NGX_INVALID_PID; |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
158 } |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
159 |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
160 if (fcntl(ngx_processes[s].channel[0], F_SETFD, FD_CLOEXEC) == -1) { |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
161 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
162 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"", |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
163 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
164 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 165 return NGX_INVALID_PID; |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
166 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
167 |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
168 if (fcntl(ngx_processes[s].channel[1], F_SETFD, FD_CLOEXEC) == -1) { |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
169 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
170 "fcntl(FD_CLOEXEC) failed while spawning \"%s\"", |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
171 name); |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
172 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 173 return NGX_INVALID_PID; |
366
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
174 } |
e411b1482ee3
nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
365
diff
changeset
|
175 |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
176 ngx_channel = ngx_processes[s].channel[1]; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
177 |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
178 } else { |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
179 ngx_processes[s].channel[0] = -1; |
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
180 ngx_processes[s].channel[1] = -1; |
360
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
181 } |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
182 |
239e37d44a34
nginx-0.0.7-2004-06-18-20:22:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
183 ngx_process_slot = s; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
184 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 pid = fork(); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
188 switch (pid) { |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
189 |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
190 case -1: |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
191 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
192 "fork() failed while spawning \"%s\"", name); |
365
fd24ba70e1b3
nginx-0.0.7-2004-06-23-09:54:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
360
diff
changeset
|
193 ngx_close_channel(ngx_processes[s].channel, cycle->log); |
543 | 194 return NGX_INVALID_PID; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 case 0: |
249
2a0540287298
nginx-0.0.2-2004-02-03-19:43:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
197 ngx_pid = ngx_getpid(); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
198 proc(cycle, data); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 break; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 default: |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
202 break; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 |
477 | 205 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start %s %P", name, pid); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
206 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
207 ngx_processes[s].pid = pid; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
208 ngx_processes[s].exited = 0; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
209 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
210 if (respawn >= 0) { |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
211 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
212 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
214 ngx_processes[s].proc = proc; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
215 ngx_processes[s].data = data; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
216 ngx_processes[s].name = name; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
217 ngx_processes[s].exiting = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
218 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
219 switch (respawn) { |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
220 |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
221 case NGX_PROCESS_NORESPAWN: |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
222 ngx_processes[s].respawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
223 ngx_processes[s].just_spawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
224 ngx_processes[s].detached = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
225 break; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
226 |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
227 case NGX_PROCESS_JUST_SPAWN: |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
228 ngx_processes[s].respawn = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
229 ngx_processes[s].just_spawn = 1; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
230 ngx_processes[s].detached = 0; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
231 break; |
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
232 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
233 case NGX_PROCESS_RESPAWN: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
234 ngx_processes[s].respawn = 1; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
235 ngx_processes[s].just_spawn = 0; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
236 ngx_processes[s].detached = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
237 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
238 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
239 case NGX_PROCESS_JUST_RESPAWN: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
240 ngx_processes[s].respawn = 1; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
241 ngx_processes[s].just_spawn = 1; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
242 ngx_processes[s].detached = 0; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
243 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
244 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
245 case NGX_PROCESS_DETACHED: |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
246 ngx_processes[s].respawn = 0; |
3016
d82993af1da0
introduce NGX_PROCESS_JUST_SPAWN and change field name accordingly
Igor Sysoev <igor@sysoev.ru>
parents:
2738
diff
changeset
|
247 ngx_processes[s].just_spawn = 0; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
248 ngx_processes[s].detached = 1; |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
249 break; |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
250 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
251 |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
252 if (s == ngx_last_process) { |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
253 ngx_last_process++; |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
254 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 |
225
2e9a8a14a0cf
nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
224
diff
changeset
|
256 return pid; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
257 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
258 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
259 |
515 | 260 ngx_pid_t |
261 ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
262 { |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
263 return ngx_spawn_process(cycle, ngx_execute_proc, ctx, ctx->name, |
226
b0c1e21e68db
nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
225
diff
changeset
|
264 NGX_PROCESS_DETACHED); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
267 |
515 | 268 static void |
269 ngx_execute_proc(ngx_cycle_t *cycle, void *data) | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
270 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
271 ngx_exec_ctx_t *ctx = data; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
272 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
273 if (execve(ctx->path, ctx->argv, ctx->envp) == -1) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
274 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
275 "execve() failed while executing %s \"%s\"", |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
276 ctx->name, ctx->path); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
277 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
278 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
279 exit(1); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
280 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
281 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
282 |
539 | 283 ngx_int_t |
284 ngx_init_signals(ngx_log_t *log) | |
285 { | |
286 ngx_signal_t *sig; | |
287 struct sigaction sa; | |
288 | |
289 for (sig = signals; sig->signo != 0; sig++) { | |
290 ngx_memzero(&sa, sizeof(struct sigaction)); | |
291 sa.sa_handler = sig->handler; | |
292 sigemptyset(&sa.sa_mask); | |
293 if (sigaction(sig->signo, &sa, NULL) == -1) { | |
5244
593d344999f5
Valgrind: sigaction() failure now ignored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4889
diff
changeset
|
294 #if (NGX_VALGRIND) |
593d344999f5
Valgrind: sigaction() failure now ignored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4889
diff
changeset
|
295 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
593d344999f5
Valgrind: sigaction() failure now ignored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4889
diff
changeset
|
296 "sigaction(%s) failed, ignored", sig->signame); |
593d344999f5
Valgrind: sigaction() failure now ignored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4889
diff
changeset
|
297 #else |
539 | 298 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
299 "sigaction(%s) failed", sig->signame); | |
300 return NGX_ERROR; | |
5244
593d344999f5
Valgrind: sigaction() failure now ignored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4889
diff
changeset
|
301 #endif |
539 | 302 } |
303 } | |
304 | |
305 return NGX_OK; | |
306 } | |
307 | |
308 | |
515 | 309 void |
539 | 310 ngx_signal_handler(int signo) |
311 { | |
312 char *action; | |
313 ngx_int_t ignore; | |
314 ngx_err_t err; | |
315 ngx_signal_t *sig; | |
316 | |
317 ignore = 0; | |
318 | |
319 err = ngx_errno; | |
320 | |
321 for (sig = signals; sig->signo != 0; sig++) { | |
322 if (sig->signo == signo) { | |
323 break; | |
324 } | |
325 } | |
326 | |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
327 ngx_time_sigsafe_update(); |
539 | 328 |
329 action = ""; | |
330 | |
331 switch (ngx_process) { | |
332 | |
333 case NGX_PROCESS_MASTER: | |
334 case NGX_PROCESS_SINGLE: | |
335 switch (signo) { | |
336 | |
337 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
338 ngx_quit = 1; | |
339 action = ", shutting down"; | |
340 break; | |
341 | |
342 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
343 case SIGINT: | |
344 ngx_terminate = 1; | |
345 action = ", exiting"; | |
346 break; | |
347 | |
348 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
4019
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
349 if (ngx_daemonized) { |
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
350 ngx_noaccept = 1; |
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
351 action = ", stop accepting connections"; |
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
352 } |
539 | 353 break; |
354 | |
355 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
356 ngx_reconfigure = 1; | |
357 action = ", reconfiguring"; | |
358 break; | |
359 | |
360 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
361 ngx_reopen = 1; | |
362 action = ", reopening logs"; | |
363 break; | |
364 | |
365 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
366 if (getppid() > 1 || ngx_new_binary > 0) { | |
367 | |
368 /* | |
369 * Ignore the signal in the new binary if its parent is | |
370 * not the init process, i.e. the old binary's process | |
698 | 371 * is still running. Or ignore the signal in the old binary's |
539 | 372 * process if the new binary's process is already running. |
373 */ | |
374 | |
375 action = ", ignoring"; | |
376 ignore = 1; | |
377 break; | |
378 } | |
379 | |
380 ngx_change_binary = 1; | |
381 action = ", changing binary"; | |
382 break; | |
383 | |
384 case SIGALRM: | |
3048
846d0e2fa483
twice termination delay only after SIGALRM, otherwise many separate SIGCHLD
Igor Sysoev <igor@sysoev.ru>
parents:
3045
diff
changeset
|
385 ngx_sigalrm = 1; |
539 | 386 break; |
387 | |
388 case SIGIO: | |
389 ngx_sigio = 1; | |
390 break; | |
391 | |
392 case SIGCHLD: | |
393 ngx_reap = 1; | |
394 break; | |
395 } | |
396 | |
397 break; | |
398 | |
399 case NGX_PROCESS_WORKER: | |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3048
diff
changeset
|
400 case NGX_PROCESS_HELPER: |
539 | 401 switch (signo) { |
402 | |
403 case ngx_signal_value(NGX_NOACCEPT_SIGNAL): | |
4019
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
404 if (!ngx_daemonized) { |
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
405 break; |
5364d2e711cc
SIGWINCH/NOACCEPT signal is disabled now in non-daemon mode.
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
406 } |
539 | 407 ngx_debug_quit = 1; |
408 case ngx_signal_value(NGX_SHUTDOWN_SIGNAL): | |
409 ngx_quit = 1; | |
410 action = ", shutting down"; | |
411 break; | |
412 | |
413 case ngx_signal_value(NGX_TERMINATE_SIGNAL): | |
414 case SIGINT: | |
415 ngx_terminate = 1; | |
416 action = ", exiting"; | |
417 break; | |
418 | |
419 case ngx_signal_value(NGX_REOPEN_SIGNAL): | |
420 ngx_reopen = 1; | |
421 action = ", reopening logs"; | |
422 break; | |
423 | |
424 case ngx_signal_value(NGX_RECONFIGURE_SIGNAL): | |
425 case ngx_signal_value(NGX_CHANGEBIN_SIGNAL): | |
426 case SIGIO: | |
427 action = ", ignoring"; | |
428 break; | |
429 } | |
430 | |
431 break; | |
432 } | |
433 | |
434 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, | |
435 "signal %d (%s) received%s", signo, sig->signame, action); | |
436 | |
437 if (ignore) { | |
438 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0, | |
439 "the changing binary signal is ignored: " | |
440 "you should shutdown or terminate " | |
441 "before either old or new binary's process"); | |
442 } | |
443 | |
444 if (signo == SIGCHLD) { | |
445 ngx_process_get_status(); | |
446 } | |
447 | |
448 ngx_set_errno(err); | |
449 } | |
450 | |
451 | |
452 static void | |
515 | 453 ngx_process_get_status(void) |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
454 { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
455 int status; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
456 char *process; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
457 ngx_pid_t pid; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
458 ngx_err_t err; |
354
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
459 ngx_int_t i; |
eaf1f651cf86
nginx-0.0.7-2004-06-15-11:55:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
460 ngx_uint_t one; |
477 | 461 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
462 one = 0; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
463 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
464 for ( ;; ) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
465 pid = waitpid(-1, &status, WNOHANG); |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
467 if (pid == 0) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
468 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
469 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
470 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
471 if (pid == -1) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
472 err = ngx_errno; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
473 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
474 if (err == NGX_EINTR) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
475 continue; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
476 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
477 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
478 if (err == NGX_ECHILD && one) { |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
479 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
480 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
481 |
452 | 482 /* |
483 * Solaris always calls the signal handler for each exited process | |
943
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
484 * despite waitpid() may be already called for this process. |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
485 * |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
486 * When several processes exit at the same time FreeBSD may |
cbe0292e53b3
lower the log level of the waitpid() ENOCHILD error on FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
698
diff
changeset
|
487 * erroneously call the signal handler for exited process |
1963 | 488 * despite waitpid() may be already called for this process. |
452 | 489 */ |
490 | |
491 if (err == NGX_ECHILD) { | |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
492 ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, err, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
493 "waitpid() failed"); |
563 | 494 return; |
452 | 495 } |
496 | |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
497 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3681
diff
changeset
|
498 "waitpid() failed"); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
499 return; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
500 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
501 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
279
diff
changeset
|
502 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
503 one = 1; |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
366
diff
changeset
|
504 process = "unknown process"; |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
505 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
506 for (i = 0; i < ngx_last_process; i++) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
507 if (ngx_processes[i].pid == pid) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
508 ngx_processes[i].status = status; |
222
99df0edb63ed
nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
221
diff
changeset
|
509 ngx_processes[i].exited = 1; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
510 process = ngx_processes[i].name; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
511 break; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
512 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
513 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
514 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
515 if (WTERMSIG(status)) { |
2494 | 516 #ifdef WCOREDUMP |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
517 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
461 | 518 "%s %P exited on signal %d%s", |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
519 process, pid, WTERMSIG(status), |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
520 WCOREDUMP(status) ? " (core dumped)" : ""); |
2494 | 521 #else |
522 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, | |
523 "%s %P exited on signal %d", | |
524 process, pid, WTERMSIG(status)); | |
525 #endif | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
526 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
527 } else { |
477 | 528 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
461 | 529 "%s %P exited with code %d", |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
530 process, pid, WEXITSTATUS(status)); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
531 } |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
532 |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
533 if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) { |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
534 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
1963 | 535 "%s %P exited with fatal code %d " |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
4019
diff
changeset
|
536 "and cannot be respawned", |
1963 | 537 process, pid, WEXITSTATUS(status)); |
234
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
538 ngx_processes[i].respawn = 0; |
cd71b95716b4
nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
227
diff
changeset
|
539 } |
4311
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
540 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
541 ngx_unlock_mutexes(pid); |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
542 } |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
543 } |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
544 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
545 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
546 static void |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
547 ngx_unlock_mutexes(ngx_pid_t pid) |
4522 | 548 { |
4311
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
549 ngx_uint_t i; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
550 ngx_shm_zone_t *shm_zone; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
551 ngx_list_part_t *part; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
552 ngx_slab_pool_t *sp; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
553 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
554 /* |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
555 * unlock the accept mutex if the abnormally exited process |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
556 * held it |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
557 */ |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
558 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
559 if (ngx_accept_mutex_ptr) { |
4315
424a1ac6af43
Added (void) as we intentionally ignore returned values.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4311
diff
changeset
|
560 (void) ngx_shmtx_force_unlock(&ngx_accept_mutex, pid); |
4311
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
561 } |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
562 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
563 /* |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
564 * unlock shared memory mutexes if held by the abnormally exited |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
565 * process |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
566 */ |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
567 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
568 part = (ngx_list_part_t *) &ngx_cycle->shared_memory.part; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
569 shm_zone = part->elts; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
570 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
571 for (i = 0; /* void */ ; i++) { |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
572 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
573 if (i >= part->nelts) { |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
574 if (part->next == NULL) { |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
575 break; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
576 } |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
577 part = part->next; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
578 shm_zone = part->elts; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
579 i = 0; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
580 } |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
581 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
582 sp = (ngx_slab_pool_t *) shm_zone[i].shm.addr; |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
583 |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
584 if (ngx_shmtx_force_unlock(&sp->mutex, pid)) { |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
585 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
586 "shared memory zone \"%V\" was locked by %P", |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
587 &shm_zone[i].shm.name, pid); |
45272aab5eea
Unlock of shared memory zones on process crash.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
588 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
589 } |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
590 } |
461 | 591 |
592 | |
515 | 593 void |
594 ngx_debug_point(void) | |
461 | 595 { |
596 ngx_core_conf_t *ccf; | |
597 | |
598 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | |
599 ngx_core_module); | |
600 | |
601 switch (ccf->debug_points) { | |
602 | |
603 case NGX_DEBUG_POINTS_STOP: | |
604 raise(SIGSTOP); | |
605 break; | |
606 | |
607 case NGX_DEBUG_POINTS_ABORT: | |
563 | 608 ngx_abort(); |
461 | 609 } |
610 } | |
2738
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
611 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
612 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
613 ngx_int_t |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
614 ngx_os_signal_process(ngx_cycle_t *cycle, char *name, ngx_int_t pid) |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
615 { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
616 ngx_signal_t *sig; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
617 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
618 for (sig = signals; sig->signo != 0; sig++) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
619 if (ngx_strcmp(name, sig->name) == 0) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
620 if (kill(pid, sig->signo) != -1) { |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
621 return 0; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
622 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
623 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
624 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
625 "kill(%P, %d) failed", pid, sig->signo); |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
626 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
627 } |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
628 |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
629 return 1; |
ae81441e23f4
implement "-s signal" option for Unix
Igor Sysoev <igor@sysoev.ru>
parents:
2494
diff
changeset
|
630 } |