Mercurial > hg > nginx
comparison src/core/nginx.c @ 282:30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 09 Mar 2004 19:47:07 +0000 |
parents | b79f021a644a |
children | 0750faf8d7e3 |
comparison
equal
deleted
inserted
replaced
281:014292b55158 | 282:30310107dbc9 |
---|---|
33 static int ngx_worker_thread_cycle(void *data); | 33 static int ngx_worker_thread_cycle(void *data); |
34 #endif | 34 #endif |
35 | 35 |
36 #endif | 36 #endif |
37 | 37 |
38 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); | 38 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); |
39 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); | 39 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); |
40 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); | 40 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); |
41 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 41 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
42 | 42 |
43 | 43 |
110 ngx_int_t ngx_reconfigure; | 110 ngx_int_t ngx_reconfigure; |
111 ngx_int_t ngx_reopen; | 111 ngx_int_t ngx_reopen; |
112 ngx_int_t ngx_change_binary; | 112 ngx_int_t ngx_change_binary; |
113 | 113 |
114 | 114 |
115 int main(int argc, char *const *argv, char **envp) | 115 int main(int argc, char *const *argv) |
116 { | 116 { |
117 ngx_int_t i; | 117 ngx_int_t i; |
118 ngx_log_t *log; | 118 ngx_log_t *log; |
119 ngx_cycle_t *cycle, init_cycle; | 119 ngx_cycle_t *cycle, init_cycle; |
120 ngx_core_conf_t *ccf; | 120 ngx_core_conf_t *ccf; |
143 | 143 |
144 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); | 144 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); |
145 init_cycle.log = log; | 145 init_cycle.log = log; |
146 ngx_cycle = &init_cycle; | 146 ngx_cycle = &init_cycle; |
147 | 147 |
148 #if 0 | |
149 /* STUB */ log->log_level = NGX_LOG_DEBUG_ALL; | |
150 #endif | |
151 | |
148 ngx_memzero(&ctx, sizeof(ngx_master_ctx_t)); | 152 ngx_memzero(&ctx, sizeof(ngx_master_ctx_t)); |
149 ctx.argc = argc; | 153 ctx.argc = argc; |
150 ctx.argv = argv; | 154 ctx.argv = argv; |
151 | 155 |
152 #if (NGX_THREADS) | 156 #if (NGX_THREADS) |
170 | 174 |
171 if (!(init_cycle.pool = ngx_create_pool(1024, log))) { | 175 if (!(init_cycle.pool = ngx_create_pool(1024, log))) { |
172 return 1; | 176 return 1; |
173 } | 177 } |
174 | 178 |
175 if (ngx_add_inherited_sockets(&init_cycle, envp) == NGX_ERROR) { | 179 if (ngx_add_inherited_sockets(&init_cycle) == NGX_ERROR) { |
176 return 1; | 180 return 1; |
177 } | 181 } |
178 | 182 |
179 cycle = ngx_init_cycle(&init_cycle); | 183 cycle = ngx_init_cycle(&init_cycle); |
180 if (cycle == NULL) { | 184 if (cycle == NULL) { |
254 | 258 |
255 return 0; | 259 return 0; |
256 } | 260 } |
257 | 261 |
258 | 262 |
259 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp) | 263 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle) |
260 { | 264 { |
261 char *p, *v; | 265 char *p, *v, *inherited; |
262 ngx_socket_t s; | 266 ngx_socket_t s; |
263 ngx_listening_t *ls; | 267 ngx_listening_t *ls; |
264 | 268 |
265 for ( /* void */ ; *envp; envp++) { | 269 inherited = getenv(NGINX_VAR); |
266 if (ngx_strncmp(*envp, NGINX_VAR, NGINX_VAR_LEN) != 0) { | 270 |
267 continue; | 271 if (inherited == NULL) { |
268 } | 272 return NGX_OK; |
269 | 273 } |
270 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 274 |
271 "using inherited sockets from \"%s\"", *envp); | 275 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
272 | 276 "using inherited sockets from \"%s\"", inherited); |
273 ngx_init_array(cycle->listening, cycle->pool, | 277 |
274 10, sizeof(ngx_listening_t), NGX_ERROR); | 278 ngx_init_array(cycle->listening, cycle->pool, |
275 | 279 10, sizeof(ngx_listening_t), NGX_ERROR); |
276 for (p = *envp + NGINX_VAR_LEN, v = p; *p; p++) { | 280 |
277 if (*p == ':' || *p == ';') { | 281 for (p = inherited, v = p; *p; p++) { |
278 s = ngx_atoi(v, p - v); | 282 if (*p == ':' || *p == ';') { |
279 if (s == NGX_ERROR) { | 283 s = ngx_atoi(v, p - v); |
280 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | 284 if (s == NGX_ERROR) { |
281 "invalid socket number \"%s\" " | 285 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
282 "in NGINX enviroment variable, " | 286 "invalid socket number \"%s\" in " |
283 "ignoring the rest of the variable", v); | 287 NGINX_VAR " enviroment variable, " |
284 break; | 288 "ignoring the rest of the variable", v); |
285 } | 289 break; |
286 v = p + 1; | |
287 | |
288 if (!(ls = ngx_push_array(&cycle->listening))) { | |
289 return NGX_ERROR; | |
290 } | |
291 | |
292 ls->fd = s; | |
293 } | 290 } |
294 } | 291 |
295 | 292 v = p + 1; |
296 ngx_inherited = 1; | 293 |
297 | 294 if (!(ls = ngx_push_array(&cycle->listening))) { |
298 return ngx_set_inherited_sockets(cycle); | 295 return NGX_ERROR; |
299 } | 296 } |
300 | 297 |
301 return NGX_OK; | 298 ls->fd = s; |
299 } | |
300 } | |
301 | |
302 ngx_inherited = 1; | |
303 | |
304 return ngx_set_inherited_sockets(cycle); | |
302 } | 305 } |
303 | 306 |
304 | 307 |
305 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) | 308 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) |
306 { | 309 { |
312 | 315 |
313 ctx.path = argv[0]; | 316 ctx.path = argv[0]; |
314 ctx.name = "new binary process"; | 317 ctx.name = "new binary process"; |
315 ctx.argv = argv; | 318 ctx.argv = argv; |
316 | 319 |
317 var = ngx_alloc(NGINX_VAR_LEN | 320 var = ngx_alloc(sizeof(NGINX_VAR) |
318 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 1, | 321 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, |
319 cycle->log); | 322 cycle->log); |
320 | 323 |
321 p = ngx_cpymem(var, NGINX_VAR, NGINX_VAR_LEN); | 324 p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); |
322 | 325 |
323 ls = cycle->listening.elts; | 326 ls = cycle->listening.elts; |
324 for (i = 0; i < cycle->listening.nelts; i++) { | 327 for (i = 0; i < cycle->listening.nelts; i++) { |
325 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd); | 328 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd); |
326 } | 329 } |
330 | |
331 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); | |
327 | 332 |
328 env[0] = var; | 333 env[0] = var; |
329 env[1] = NULL; | 334 env[1] = NULL; |
330 ctx.envp = (char *const *) &env; | 335 ctx.envp = (char *const *) &env; |
331 | 336 |