annotate src/core/nginx.c @ 234:cd71b95716b4

nginx-0.0.1-2004-01-20-23:40:08 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 20 Jan 2004 20:40:08 +0000
parents 92db0aa1e83f
children 86e473b5641e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
1
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
2 #include <ngx_config.h>
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
3 #include <ngx_core.h>
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
4 #include <ngx_event.h>
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 #include <nginx.h>
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
8 typedef struct {
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
9 int daemon;
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
10 int master;
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
11 uid_t user;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
12 gid_t group;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
13 ngx_str_t pid;
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
14 ngx_str_t newpid;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
15 } ngx_core_conf_t;
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
16
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
17
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
18 typedef struct {
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
19 ngx_file_t pid;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
20 char *name;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
21 char *const *argv;
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
22 } ngx_master_ctx_t;
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
23
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
24
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
25 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
26 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
27 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
28 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp);
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
29 static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
30 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle);
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
31 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
32
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
33
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
34 static ngx_str_t core_name = ngx_string("core");
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
35
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
36 static ngx_command_t ngx_core_commands[] = {
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
37
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
38 { ngx_string("user"),
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
39 NGX_MAIN_CONF|NGX_CONF_TAKE12,
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
40 ngx_set_user,
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
41 0,
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
42 0,
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
43 NULL },
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
44
209
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
45 { ngx_string("daemon"),
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
46 NGX_MAIN_CONF|NGX_CONF_TAKE1,
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
47 ngx_conf_set_core_flag_slot,
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
48 0,
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
49 offsetof(ngx_core_conf_t, daemon),
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
50 NULL },
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
51
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
52 { ngx_string("master_process"),
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
53 NGX_MAIN_CONF|NGX_CONF_TAKE1,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
54 ngx_conf_set_core_flag_slot,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
55 0,
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
56 offsetof(ngx_core_conf_t, master),
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
57 NULL },
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
58
209
e1c815be05ae nginx-0.0.1-2003-12-09-18:08:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 207
diff changeset
59 ngx_null_command
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
60 };
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
61
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
62
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
63 ngx_module_t ngx_core_module = {
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
64 NGX_MODULE,
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
65 &core_name, /* module context */
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
66 ngx_core_commands, /* module directives */
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
67 NGX_CORE_MODULE, /* module type */
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
68 ngx_core_module_init, /* init module */
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
69 NULL /* init child */
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
70 };
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
71
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
72
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
73 ngx_int_t ngx_max_module;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
74 ngx_uint_t ngx_connection_counter;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents: 194
diff changeset
75
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
76 ngx_int_t ngx_process;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
77 ngx_pid_t ngx_new_binary;
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
78
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
79 ngx_int_t ngx_inherited;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
80 ngx_int_t ngx_signal;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
81 ngx_int_t ngx_reap;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
82 ngx_int_t ngx_terminate;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
83 ngx_int_t ngx_quit;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
84 ngx_int_t ngx_noaccept;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
85 ngx_int_t ngx_reconfigure;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
86 ngx_int_t ngx_reopen;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
87 ngx_int_t ngx_change_binary;
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
88
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
89
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
90 int main(int argc, char *const *argv, char **envp)
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
91 {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
92 ngx_fd_t fd;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
93 ngx_int_t i;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
94 ngx_log_t *log;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
95 ngx_cycle_t *cycle, init_cycle;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
96 ngx_open_file_t *file;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
97 ngx_core_conf_t *ccf;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
98 ngx_master_ctx_t ctx;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 144
diff changeset
99 #if !(WIN32)
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
100 size_t len;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
101 char pid[/* STUB */ 10];
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 144
diff changeset
102 #endif
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
103
207
6e0fef527732 nginx-0.0.1-2003-12-05-20:07:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 201
diff changeset
104 #if __FreeBSD__
6e0fef527732 nginx-0.0.1-2003-12-05-20:07:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 201
diff changeset
105 ngx_debug_init();
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
106 #endif
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
107
108
adc093f880c8 nginx-0.0.1-2003-07-02-09:01:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 107
diff changeset
108 /* TODO */ ngx_max_sockets = -1;
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
109
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents: 194
diff changeset
110 ngx_time_init();
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
111
212
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
112 #if (HAVE_PCRE)
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents: 194
diff changeset
113 ngx_regex_init();
212
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
114 #endif
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 144
diff changeset
115
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
116 log = ngx_log_init_errlog();
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
117
212
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
118 /* init_cycle->log is required for signal handlers */
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
119
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
120 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
121 init_cycle.log = log;
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
122 ngx_cycle = &init_cycle;
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 210
diff changeset
123
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
124 if (ngx_os_init(log) == NGX_ERROR) {
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
125 return 1;
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
126 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
127
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
128 ngx_max_module = 0;
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
129 for (i = 0; ngx_modules[i]; i++) {
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
130 ngx_modules[i]->index = ngx_max_module++;
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
131 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
132
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
133 if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
134 return 1;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
135 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
136
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
137 if (ngx_add_inherited_sockets(&init_cycle, envp) == NGX_ERROR) {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
138 return 1;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
139 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
140
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
141 cycle = ngx_init_cycle(&init_cycle);
108
adc093f880c8 nginx-0.0.1-2003-07-02-09:01:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 107
diff changeset
142 if (cycle == NULL) {
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
143 return 1;
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
144 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
145
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
146 ngx_cycle = cycle;
113
d7f606e25b99 nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 111
diff changeset
147
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
148 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
149
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
150 ngx_process = (ccf->master != 0) ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
151
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
152 #if (WIN32)
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
153
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
154 #if 0
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
155
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
156 if (run_as_service) {
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
157 if (ngx_servie(cycle->log) == NGX_ERROR) {
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
158 return 1;
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
159 }
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
160
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
161 return 0;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
162 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
163
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
164 #endif
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
165
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
166 #else
115
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
167
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
168 if (ccf->daemon != 0) {
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
169 if (ngx_daemon(cycle->log) == NGX_ERROR) {
115
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
170 return 1;
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
171 }
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
172 }
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
173
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
174 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
175 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
117
f6e3c5d019b6 nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 115
diff changeset
176 "dup2(STDERR) failed");
115
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
177 return 1;
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
178 }
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
179
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
180 if (ccf->pid.len == 0) {
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
181 ccf->pid.len = sizeof(NGINX_PID) - 1;
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
182 ccf->pid.data = NGINX_PID;
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
183 ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1;
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
184 ccf->newpid.data = NGINX_NEW_PID;
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
185 }
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
186
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
187 len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
188 ngx_memzero(&ctx.pid, sizeof(ngx_file_t));
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
189 ctx.pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
190 ctx.name = ccf->pid.data;
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
191
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
192 ctx.pid.fd = ngx_open_file(ctx.pid.name.data, NGX_FILE_RDWR,
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
193 NGX_FILE_CREATE_OR_OPEN);
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
194
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
195 if (ctx.pid.fd == NGX_INVALID_FILE) {
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
196 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
197 ngx_open_file_n " \"%s\" failed", ctx.pid.name.data);
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
198 return 1;
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
199 }
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
200
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
201 if (ngx_write_file(&ctx.pid, pid, len, 0) == NGX_ERROR) {
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
202 return 1;
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
203 }
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
204
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
205 if (ngx_close_file(ctx.pid.fd) == NGX_FILE_ERROR) {
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
206 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
207 ngx_close_file_n " \"%s\" failed", ctx.pid.name.data);
210
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
208 }
00cafae0bdf1 nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents: 209
diff changeset
209
115
be27f922b9a2 nginx-0.0.1-2003-07-10-20:26:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 114
diff changeset
210 #endif
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
211
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
212 ctx.argv = argv;
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
213
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
214 ngx_master_process_cycle(cycle, &ctx);
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
215
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
216 return 0;
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
217 }
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
218
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
219
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
220 /* TODO: broken single process */
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
221
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
222 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
223 {
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
224 int signo;
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
225 char *name;
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
226 sigset_t set, wset;
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
227 struct timeval tv;
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
228 ngx_uint_t i, live, sent;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
229 ngx_msec_t delay;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
230
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
231 delay = 125;
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
232
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
233 sigemptyset(&set);
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
234 sigaddset(&set, SIGCHLD);
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
235 sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
236 sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
237 sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL));
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
238 sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL));
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
239 sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
240 sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
241
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
242 sigemptyset(&wset);
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
243
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
244 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
245 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
246 "sigprocmask() failed");
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
247 }
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
248
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
249 ngx_signal = 0;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
250 ngx_new_binary = 0;
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
251 signo = 0;
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
252 sent = 0;
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
253 live = 0;
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
254
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
255 for ( ;; ) {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
256 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
257
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
258 if (ngx_process == NGX_PROCESS_MASTER) {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
259 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
260 "worker process", NGX_PROCESS_RESPAWN);
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
261 live = 1;
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
262
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
263 } else {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
264 ngx_init_temp_number();
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
265
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
266 for (i = 0; ngx_modules[i]; i++) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
267 if (ngx_modules[i]->init_process) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
268 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
269 /* fatal */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
270 exit(1);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
271 }
113
d7f606e25b99 nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 111
diff changeset
272 }
d7f606e25b99 nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 111
diff changeset
273 }
d7f606e25b99 nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 111
diff changeset
274 }
110
152567c11325 nginx-0.0.1-2003-07-02-22:51:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 109
diff changeset
275
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
276 /* a cycle with the same configuration because a new one is invalid */
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
277
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
278 for ( ;; ) {
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
279
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
280 /* an event loop */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
281
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
282 for ( ;; ) {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
283
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
284 if (ngx_process == NGX_PROCESS_MASTER) {
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
285 if (sent) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
286 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
287 "sent signal cycle");
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
288
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
289 if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
290 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
291 "sigprocmask() failed");
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
292 continue;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
293 }
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
294
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
295 /*
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
296 * there is very big chance that the pending signals
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
297 * would be delivered right on the sigprocmask() return
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
298 */
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
299
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
300 if (!ngx_signal) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
301
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
302 if (delay < 15000) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
303 delay *= 2;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
304 }
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
305
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
306 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
307 "msleep %d", delay);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
308
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
309 ngx_msleep(delay);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
310
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
311 ngx_gettimeofday(&tv);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
312 ngx_time_update(tv.tv_sec);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
313
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
314 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
315 "wake up");
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
316 }
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
317
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
318 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
319 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
320 "sigprocmask() failed");
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
321 }
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
322
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
323 ngx_signal = 0;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
324
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
325 } else {
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
326 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
327 "sigsuspend");
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
328
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
329 sigsuspend(&wset);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
330
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
331 ngx_gettimeofday(&tv);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
332 ngx_time_update(tv.tv_sec);
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
333
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
334 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
335 "wake up");
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
336 }
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
337
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
338 } else { /* NGX_PROCESS_SINGLE */
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
339 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
340 "worker cycle");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
341
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
342 ngx_process_events(cycle->log);
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
343 }
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
344
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
345 if (ngx_reap) {
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
346 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
347 "reap childs");
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
348
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
349 live = 0;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
350 for (i = 0; i < ngx_last_process; i++) {
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
351
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
352 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
353 "child: " PID_T_FMT
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
354 " s:%d e:%d t:%d d:%d r:%d",
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
355 ngx_processes[i].pid,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
356 ngx_processes[i].signal,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
357 ngx_processes[i].exiting,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
358 ngx_processes[i].exited,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
359 ngx_processes[i].detached,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
360 ngx_processes[i].respawn);
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
361
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
362 if (ngx_processes[i].exited) {
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
363
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
364 if (ngx_processes[i].respawn
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
365 && !ngx_processes[i].exiting
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
366 && !ngx_terminate
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
367 && !ngx_quit)
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
368 {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
369 if (ngx_spawn_process(cycle,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
370 ngx_processes[i].proc,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
371 ngx_processes[i].data,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
372 ngx_processes[i].name, i)
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
373 == NGX_ERROR)
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
374 {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
375 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
376 "can not respawn %s",
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
377 ngx_processes[i].name);
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
378 }
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
379
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
380 continue;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
381 }
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
382
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
383 if (ngx_processes[i].pid == ngx_new_binary) {
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
384 ngx_new_binary = 0;
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
385 }
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
386
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
387 if (i != --ngx_last_process) {
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
388 ngx_processes[i--] =
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
389 ngx_processes[ngx_last_process];
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
390 }
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
391
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
392 } else if (!ngx_processes[i].detached
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
393 && (ngx_terminate || ngx_quit))
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
394 {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
395 live = 1;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
396
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
397 } else if (ngx_processes[i].exiting) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
398 live = 1;
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
399 }
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
400 }
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
401
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
402 if (!live) {
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
403 sent = 0;
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
404 }
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
405 }
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
406
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
407 if (!live && (ngx_terminate || ngx_quit)) {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
408 ngx_master_exit(cycle, ctx);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
409 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
410
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
411 if (ngx_terminate) {
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
412 if (delay > 10000) {
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
413 signo = SIGKILL;
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
414 } else {
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
415 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL);
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
416 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
417
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
418 } else if (ngx_quit) {
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
419 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
420
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
421 } else {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
422
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
423 if (ngx_noaccept) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
424 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
425 }
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
426
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
427 if (ngx_change_binary) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
428 ngx_change_binary = 0;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
429 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
430 "changing binary");
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
431 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv);
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
432 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
433
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
434 if (ngx_reconfigure) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
435 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
436 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
437 "reconfiguring");
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
438 }
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
439
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
440 if (ngx_reopen) {
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
441 /* STUB */
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
442 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
443
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
444 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
445 "reopening logs");
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
446 ngx_reopen_files(cycle);
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
447 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
448 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
449
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
450 if (signo) {
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
451 for (i = 0; i < ngx_last_process; i++) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
452
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
453 if (!ngx_processes[i].detached) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
454 ngx_processes[i].signal = signo;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
455
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
456 ngx_log_debug2(NGX_LOG_DEBUG_EVENT,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
457 cycle->log, 0,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
458 "signal " PID_T_FMT " %d",
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
459 ngx_processes[i].pid, signo);
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
460 }
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
461 }
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
462 delay = 125;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
463 signo = 0;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
464 }
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
465
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
466 for (i = 0; i < ngx_last_process; i++) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
467
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
468 if (ngx_processes[i].signal == 0) {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
469 continue;
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
470 }
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
471
227
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
472 sent = 1;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
473
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
474 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
475 "kill (" PID_T_FMT ", %d)" ,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
476 ngx_processes[i].pid,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
477 ngx_processes[i].signal);
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
478
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
479 if (kill(ngx_processes[i].pid, ngx_processes[i].signal)
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
480 == -1)
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
481 {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
482 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
483 "kill(%d, %d) failed",
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
484 ngx_processes[i].pid,
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
485 ngx_processes[i].signal);
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
486 continue;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
487 }
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
488
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
489 if (ngx_processes[i].signal
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
490 != ngx_signal_value(NGX_REOPEN_SIGNAL))
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
491 {
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
492 ngx_processes[i].exiting = 1;
2ba3477070ac nginx-0.0.1-2004-01-14-21:19:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 226
diff changeset
493 }
223
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
494 }
5d168ebc1ecc nginx-0.0.1-2004-01-09-18:47:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 222
diff changeset
495
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
496 if (ngx_reap) {
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
497 ngx_reap = 0;
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
498 }
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
499
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
500 /* STUB */
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
501 if (ngx_reopen) {
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
502 break;
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
503 }
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
504
224
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
505 if (ngx_reconfigure) {
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
506 break;
d427f1c3fe95 nginx-0.0.1-2004-01-13-09:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 223
diff changeset
507 }
111
1c002f2b77ed nginx-0.0.1-2003-07-03-20:30:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 110
diff changeset
508 }
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
509
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
510 if (ngx_reopen) {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
511 ngx_reopen = 0;
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
512
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
513 } else if (ngx_noaccept) {
225
2e9a8a14a0cf nginx-0.0.1-2004-01-13-19:43:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 224
diff changeset
514 ngx_noaccept = 0;
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
515
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
516 } else {
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
517 cycle = ngx_init_cycle(cycle);
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
518 if (cycle == NULL) {
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
519 cycle = (ngx_cycle_t *) ngx_cycle;
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
520 continue;
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
521 }
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
522
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
523 ngx_cycle = cycle;
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
524 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
525
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
526 ngx_reconfigure = 0;
107
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
527 break;
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
528 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
529 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
530 }
b5be4b0448d3 nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 106
diff changeset
531
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
532
231
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
533 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
534 {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
535 char *name;
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
536
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
537 if (ngx_inherited && getppid() > 1) {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
538 name = ctx->pid.name.data;
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
539
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
540 } else {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
541 name = ctx->name;
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
542 }
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
543
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
544 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
545 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
546 ngx_delete_file_n " \"%s\" failed", name);
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
547 }
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
548
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
549 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit");
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
550 exit(0);
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
551 }
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
552
92db0aa1e83f nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents: 227
diff changeset
553
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
554 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
555 {
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
556 sigset_t set;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
557 ngx_int_t i;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
558 ngx_listening_t *ls;
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
559 ngx_core_conf_t *ccf;
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
560
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
561 ngx_process = NGX_PROCESS_WORKER;
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
562 ngx_last_process = 0;
220
4f81b931e9ff nginx-0.0.1-2004-01-08-11:47:17 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
563
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
564 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
565
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
566 if (ccf->group != (gid_t) NGX_CONF_UNSET) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
567 if (setuid(ccf->group) == -1) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
568 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
569 "setgid(%d) failed", ccf->group);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
570 /* fatal */
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
571 exit(2);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
572 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
573 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
574
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
575 if (ccf->user != (uid_t) NGX_CONF_UNSET && geteuid() == 0) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
576 if (setuid(ccf->user) == -1) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
577 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
578 "setuid(%d) failed", ccf->user);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
579 /* fatal */
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
580 exit(2);
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
581 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
582 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
583
221
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
584 sigemptyset(&set);
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
585
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
586 if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
587 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
588 "sigprocmask() failed");
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
589 }
401154e21826 nginx-0.0.1-2004-01-08-20:08:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 220
diff changeset
590
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
591 ngx_init_temp_number();
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
592
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
593 /*
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
594 * disable deleting previous events for the listening sockets because
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
595 * in the worker processes there are no events at all at this point
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
596 */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
597 ls = cycle->listening.elts;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
598 for (i = 0; i < cycle->listening.nelts; i++) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
599 ls[i].remain = 0;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
600 }
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
601
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
602 for (i = 0; ngx_modules[i]; i++) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
603 if (ngx_modules[i]->init_process) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
604 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
605 /* fatal */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
606 exit(1);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
607 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
608 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
609 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
610
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
611 /* TODO: threads: start ngx_worker_thread_cycle() */
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
612
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
613 for ( ;; ) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
614 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
615
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
616 ngx_process_events(cycle->log);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
617
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
618 if (ngx_terminate) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
619 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
620 exit(0);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
621 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
622
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
623 if (ngx_quit) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
624 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
625 "gracefully shutdowning");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
626 break;
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
627 }
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
628
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
629 if (ngx_reopen) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
630 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
631 ngx_reopen_files(cycle);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
632 ngx_reopen = 0;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
633 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
634 }
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
635
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
636 ngx_close_listening_sockets(cycle);
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
637
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
638 for ( ;; ) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
639 if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
640 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
641 exit(0);
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
642 }
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
643
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
644 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
645
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
646 ngx_process_events(cycle->log);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
647 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
648 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
649
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
650
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
651 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp)
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
652 {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
653 char *p, *v;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
654 ngx_socket_t s;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
655 ngx_listening_t *ls;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
656
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
657 for ( /* void */ ; *envp; envp++) {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
658 if (ngx_strncmp(*envp, NGINX_VAR, NGINX_VAR_LEN) != 0) {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
659 continue;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
660 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
661
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
662 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
663 "using inherited sockets from \"%s\"", *envp);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
664
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
665 ngx_init_array(cycle->listening, cycle->pool,
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
666 10, sizeof(ngx_listening_t), NGX_ERROR);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
667
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
668 for (p = *envp + NGINX_VAR_LEN, v = p; *p; p++) {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
669 if (*p == ':' || *p == ';') {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
670 s = ngx_atoi(v, p - v);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
671 if (s == NGX_ERROR) {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
672 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
673 "invalid socket number \"%s\" "
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
674 "in NGINX enviroment variable, "
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
675 "ignoring the rest of the variable", v);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
676 break;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
677 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
678 v = p + 1;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
679
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
680 if (!(ls = ngx_push_array(&cycle->listening))) {
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
681 return NGX_ERROR;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
682 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
683
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
684 ls->fd = s;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
685 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
686 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
687
222
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
688 ngx_inherited = 1;
99df0edb63ed nginx-0.0.1-2004-01-09-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 221
diff changeset
689
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
690 return ngx_set_inherited_sockets(cycle);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
691 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
692
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
693 return NGX_OK;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
694 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
695
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
696
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
697 static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
698 {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
699 char *env[2], *var, *p;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
700 ngx_int_t i;
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
701 ngx_pid_t pid;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
702 ngx_exec_ctx_t ctx;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
703 ngx_listening_t *ls;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
704
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
705 ctx.path = argv[0];
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
706 ctx.name = "new binary process";
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
707 ctx.argv = argv;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
708
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
709 var = ngx_alloc(NGINX_VAR_LEN
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
710 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 1,
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
711 cycle->log);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
712
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
713 p = ngx_cpymem(var, NGINX_VAR, NGINX_VAR_LEN);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
714
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
715 ls = cycle->listening.elts;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
716 for (i = 0; i < cycle->listening.nelts; i++) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
717 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd);
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
718 }
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
719
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
720 env[0] = var;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
721 env[1] = NULL;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
722 ctx.envp = (char *const *) &env;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
723
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
724 pid = ngx_exec(cycle, &ctx);
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
725
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
726 ngx_free(var);
226
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
727
b0c1e21e68db nginx-0.0.1-2004-01-14-00:33:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 225
diff changeset
728 return pid;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
729 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
730
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
731
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
732 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle)
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
733 {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
734 ngx_core_conf_t *ccf;
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
735
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
736 /*
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
737 * ngx_core_module has a special init procedure: it is called by
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
738 * ngx_init_cycle() before the configuration file parsing to create
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
739 * ngx_core_module configuration and to set its default parameters
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
740 */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
741
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
742 if (((void **)(cycle->conf_ctx))[ngx_core_module.index] != NULL) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
743 return NGX_OK;
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
744 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
745
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
746 if (!(ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t)))) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
747 return NGX_ERROR;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
748 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
749 /* set by pcalloc()
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
750 *
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
751 * ccf->pid = NULL;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
752 */
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
753 ccf->daemon = NGX_CONF_UNSET;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
754 ccf->master = NGX_CONF_UNSET;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
755 ccf->user = (uid_t) NGX_CONF_UNSET;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
756 ccf->group = (gid_t) NGX_CONF_UNSET;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
757
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
758 ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
759
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 217
diff changeset
760 return NGX_OK;
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
761 }
234
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
762
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
763
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
764 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
765 {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
766 struct passwd *pwd;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
767 struct group *grp;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
768 ngx_str_t *value;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
769 ngx_core_conf_t *ccf;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
770
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
771 ccf = *(void **)conf;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
772
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
773 if (ccf->user != (uid_t) NGX_CONF_UNSET) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
774 return "is duplicate";
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
775 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
776
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
777 value = (ngx_str_t *) cf->args->elts;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
778
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
779 pwd = getpwnam(value[1].data);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
780 if (pwd == NULL) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
781 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
782 "getpwnam(%s) failed", value[1].data);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
783 return NGX_CONF_ERROR;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
784 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
785
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
786 ccf->user = pwd->pw_uid;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
787
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
788 if (cf->args->nelts == 2) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
789 return NGX_CONF_OK;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
790 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
791
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
792 grp = getgrnam(value[2].data);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
793 if (grp == NULL) {
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
794 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
795 "getgrnam(%s) failed", value[1].data);
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
796 return NGX_CONF_ERROR;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
797 }
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
798
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
799 ccf->group = grp->gr_gid;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
800
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
801 return NGX_CONF_OK;
cd71b95716b4 nginx-0.0.1-2004-01-20-23:40:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 231
diff changeset
802 }