Mercurial > hg > nginx-quic
comparison src/core/nginx.c @ 220:4f81b931e9ff
nginx-0.0.1-2004-01-08-11:47:17 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 08 Jan 2004 08:47:17 +0000 |
parents | f57597ec5249 |
children | 401154e21826 |
comparison
equal
deleted
inserted
replaced
219:f57597ec5249 | 220:4f81b931e9ff |
---|---|
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 #include <nginx.h> | 5 #include <nginx.h> |
6 | 6 |
7 | 7 |
8 static void ngx_master_process_cycle(ngx_cycle_t *cycle); | |
8 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 9 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
9 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); | 10 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); |
10 static void ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); | 11 static void ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); |
11 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); | 12 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); |
12 | 13 |
64 /* STUB */ | 65 /* STUB */ |
65 uid_t user; | 66 uid_t user; |
66 | 67 |
67 u_int ngx_connection_counter; | 68 u_int ngx_connection_counter; |
68 | 69 |
69 ngx_int_t ngx_master; | 70 ngx_int_t ngx_process; |
70 ngx_int_t ngx_single; | |
71 | 71 |
72 | 72 |
73 ngx_int_t ngx_respawn; | 73 ngx_int_t ngx_respawn; |
74 ngx_int_t ngx_terminate; | 74 ngx_int_t ngx_terminate; |
75 ngx_int_t ngx_quit; | 75 ngx_int_t ngx_quit; |
78 ngx_int_t ngx_change_binary; | 78 ngx_int_t ngx_change_binary; |
79 | 79 |
80 | 80 |
81 int main(int argc, char *const *argv, char **envp) | 81 int main(int argc, char *const *argv, char **envp) |
82 { | 82 { |
83 struct timeval tv; | |
84 ngx_fd_t fd; | 83 ngx_fd_t fd; |
85 ngx_int_t i; | 84 ngx_int_t i; |
86 ngx_err_t err; | |
87 ngx_log_t *log; | 85 ngx_log_t *log; |
88 ngx_cycle_t *cycle, init_cycle; | 86 ngx_cycle_t *cycle, init_cycle; |
89 ngx_open_file_t *file; | 87 ngx_open_file_t *file; |
90 ngx_core_conf_t *ccf; | 88 ngx_core_conf_t *ccf; |
91 #if !(WIN32) | 89 #if !(WIN32) |
138 | 136 |
139 ngx_cycle = cycle; | 137 ngx_cycle = cycle; |
140 | 138 |
141 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 139 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
142 | 140 |
143 if (ccf->single == 1) { | 141 ngx_process = (ccf->single == 1) ? NGX_PROCESS_SINGLE : NGX_PROCESS_MASTER; |
144 ngx_master = 0; | 142 |
145 ngx_single = 1; | 143 #if (WIN32) |
146 | 144 |
147 } else { | 145 #if 0 |
148 ngx_master = 1; | 146 |
149 ngx_single = 0; | 147 if (run_as_service) { |
150 } | 148 if (ngx_servie(cycle->log) == NGX_ERROR) { |
151 | 149 return 1; |
152 #if !(WIN32) | 150 } |
151 | |
152 return 0; | |
153 } | |
154 | |
155 #endif | |
156 | |
157 #else | |
153 | 158 |
154 /* STUB */ | 159 /* STUB */ |
155 if (ccf->user.len) { | 160 if (ccf->user.len) { |
156 pwd = getpwnam(ccf->user.data); | 161 pwd = getpwnam(ccf->user.data); |
157 if (pwd == NULL) { | 162 if (pwd == NULL) { |
203 ngx_close_file_n " \"%s\" failed", pidfile.name.data); | 208 ngx_close_file_n " \"%s\" failed", pidfile.name.data); |
204 } | 209 } |
205 | 210 |
206 #endif | 211 #endif |
207 | 212 |
208 /* a life cycle */ | 213 ngx_master_process_cycle(cycle); |
214 | |
215 return 0; | |
216 } | |
217 | |
218 | |
219 static void ngx_master_process_cycle(ngx_cycle_t *cycle) | |
220 { | |
221 struct timeval tv; | |
222 ngx_int_t i; | |
223 ngx_err_t err; | |
209 | 224 |
210 for ( ;; ) { | 225 for ( ;; ) { |
211 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); | 226 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); |
212 | 227 |
213 if (ngx_master) { | 228 if (ngx_process == NGX_PROCESS_MASTER) { |
214 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | 229 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, |
215 "worker process", NGX_PROCESS_RESPAWN); | 230 "worker process", NGX_PROCESS_RESPAWN); |
216 | 231 |
217 } else { | 232 } else { |
218 ngx_init_temp_number(); | 233 ngx_init_temp_number(); |
225 } | 240 } |
226 } | 241 } |
227 } | 242 } |
228 } | 243 } |
229 | 244 |
230 #if 0 | |
231 reconfigure = 0; | |
232 reopen = 0; | |
233 #endif | |
234 | 245 |
235 /* a cycle with the same configuration */ | 246 /* a cycle with the same configuration */ |
236 | 247 |
237 for ( ;; ) { | 248 for ( ;; ) { |
238 | 249 |
240 | 251 |
241 for ( ;; ) { | 252 for ( ;; ) { |
242 | 253 |
243 err = 0; | 254 err = 0; |
244 | 255 |
245 if (ngx_single) { | 256 if (ngx_process == NGX_PROCESS_SINGLE) { |
246 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 257 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
247 "worker cycle"); | 258 "worker cycle"); |
248 | 259 |
249 ngx_process_events(cycle->log); | 260 ngx_process_events(cycle->log); |
250 | 261 |
262 } | 273 } |
263 } | 274 } |
264 | 275 |
265 if (ngx_quit || ngx_terminate) { | 276 if (ngx_quit || ngx_terminate) { |
266 #if !(WIN32) | 277 #if !(WIN32) |
278 #if 0 | |
267 if (ngx_delete_file(pidfile.name.data) == NGX_FILE_ERROR) { | 279 if (ngx_delete_file(pidfile.name.data) == NGX_FILE_ERROR) { |
268 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 280 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
269 ngx_delete_file_n " \"%s\" failed", | 281 ngx_delete_file_n " \"%s\" failed", |
270 pidfile.name.data); | 282 pidfile.name.data); |
271 } | 283 } |
272 #endif | 284 #endif |
285 #endif | |
273 | 286 |
274 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting"); | 287 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting"); |
275 | 288 |
276 if (ngx_master) { | 289 if (ngx_process == NGX_PROCESS_MASTER) { |
277 ngx_signal_processes(cycle, | 290 ngx_signal_processes(cycle, |
278 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); | 291 ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); |
279 | 292 |
280 /* TODO: wait workers */ | 293 /* TODO: wait workers */ |
281 | 294 |
291 | 304 |
292 if (err == NGX_EINTR) { | 305 if (err == NGX_EINTR) { |
293 ngx_respawn_processes(cycle); | 306 ngx_respawn_processes(cycle); |
294 } | 307 } |
295 | 308 |
309 #if 0 | |
296 if (ngx_change_binary) { | 310 if (ngx_change_binary) { |
297 ngx_change_binary = 0; | 311 ngx_change_binary = 0; |
298 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 312 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
299 "changing binary"); | 313 "changing binary"); |
300 ngx_exec_new_binary(cycle, argv); | 314 ngx_exec_new_binary(cycle, argv); |
301 /* TODO: quit workers */ | 315 /* TODO: quit workers */ |
302 } | 316 } |
317 #endif | |
303 | 318 |
304 if (ngx_reconfigure) { | 319 if (ngx_reconfigure) { |
305 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); | 320 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reconfiguring"); |
306 break; | 321 break; |
307 } | 322 } |
331 | 346 |
332 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) | 347 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) |
333 { | 348 { |
334 ngx_int_t i; | 349 ngx_int_t i; |
335 ngx_listening_t *ls; | 350 ngx_listening_t *ls; |
351 | |
352 ngx_process = NGX_PROCESS_WORKER; | |
336 | 353 |
337 if (user) { | 354 if (user) { |
338 if (setuid(user) == -1) { | 355 if (setuid(user) == -1) { |
339 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 356 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
340 "setuid() failed"); | 357 "setuid() failed"); |