Mercurial > hg > nginx
comparison src/core/nginx.c @ 452:23fb87bddda1 release-0.1.1
nginx-0.1.1-RELEASE import
*) Feature: the gzip_types directive.
*) Feature: the tcp_nodelay directive.
*) Feature: the send_lowat directive is working not only on OSes that
support kqueue NOTE_LOWAT, but also on OSes that support SO_SNDLOWAT.
*) Feature: the setproctitle() emulation for Linux and Solaris.
*) Bugfix: the "Location" header rewrite bug fixed while the proxying.
*) Bugfix: the ngx_http_chunked_module module may get caught in an
endless loop.
*) Bugfix: the /dev/poll module bugs fixed.
*) Bugfix: the responses were corrupted when the temporary files were
used while the proxying.
*) Bugfix: the unescaped requests were passed to the backend.
*) Bugfix: while the build configuration on Linux 2.4 the
--with-poll_module parameter was required.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Oct 2004 15:07:03 +0000 |
parents | 3b1e8c9df9ad |
children | 295d97d70c69 |
comparison
equal
deleted
inserted
replaced
451:f40362e47689 | 452:23fb87bddda1 |
---|---|
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <nginx.h> | 10 #include <nginx.h> |
11 | 11 |
12 | 12 |
13 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); | 13 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); |
14 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); | 14 static ngx_int_t ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv); |
15 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv); | |
15 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); | 16 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); |
16 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); | 17 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); |
17 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 18 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
18 | 19 |
19 | 20 |
94 | 95 |
95 | 96 |
96 ngx_uint_t ngx_max_module; | 97 ngx_uint_t ngx_max_module; |
97 | 98 |
98 | 99 |
99 int main(int argc, char *const *argv) | 100 int main(int argc, char *const *argv, char *const *envp) |
100 { | 101 { |
101 ngx_int_t i; | 102 ngx_int_t i; |
102 ngx_log_t *log; | 103 ngx_log_t *log; |
103 ngx_cycle_t *cycle, init_cycle; | 104 ngx_cycle_t *cycle, init_cycle; |
104 ngx_core_conf_t *ccf; | 105 ngx_core_conf_t *ccf; |
105 ngx_master_ctx_t ctx; | |
106 | 106 |
107 #if defined __FreeBSD__ | 107 #if defined __FreeBSD__ |
108 ngx_debug_init(); | 108 ngx_debug_init(); |
109 #endif | 109 #endif |
110 | 110 |
130 | 130 |
131 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); | 131 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); |
132 init_cycle.log = log; | 132 init_cycle.log = log; |
133 ngx_cycle = &init_cycle; | 133 ngx_cycle = &init_cycle; |
134 | 134 |
135 ngx_memzero(&ctx, sizeof(ngx_master_ctx_t)); | |
136 ctx.argc = argc; | |
137 ctx.argv = argv; | |
138 | |
139 if (!(init_cycle.pool = ngx_create_pool(1024, log))) { | 135 if (!(init_cycle.pool = ngx_create_pool(1024, log))) { |
140 return 1; | 136 return 1; |
141 } | 137 } |
142 | 138 |
143 if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) { | 139 if (ngx_getopt(&init_cycle, argc, argv) == NGX_ERROR) { |
140 return 1; | |
141 } | |
142 | |
143 if (ngx_save_argv(&init_cycle, argc, argv) == NGX_ERROR) { | |
144 return 1; | 144 return 1; |
145 } | 145 } |
146 | 146 |
147 if (ngx_test_config) { | 147 if (ngx_test_config) { |
148 log->log_level = NGX_LOG_INFO; | 148 log->log_level = NGX_LOG_INFO; |
217 } | 217 } |
218 | 218 |
219 #endif | 219 #endif |
220 | 220 |
221 if (ngx_process == NGX_PROCESS_MASTER) { | 221 if (ngx_process == NGX_PROCESS_MASTER) { |
222 ngx_master_process_cycle(cycle, &ctx); | 222 ngx_master_process_cycle(cycle); |
223 | 223 |
224 } else { | 224 } else { |
225 ngx_single_process_cycle(cycle, &ctx); | 225 ngx_single_process_cycle(cycle); |
226 } | 226 } |
227 | 227 |
228 return 0; | 228 return 0; |
229 } | 229 } |
230 | 230 |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) | 277 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) |
278 { | 278 { |
279 char *env[2], *var, *p; | 279 char *env[3], *var, *p; |
280 ngx_uint_t i; | 280 ngx_uint_t i; |
281 ngx_pid_t pid; | 281 ngx_pid_t pid; |
282 ngx_exec_ctx_t ctx; | 282 ngx_exec_ctx_t ctx; |
283 ngx_listening_t *ls; | 283 ngx_listening_t *ls; |
284 | 284 |
298 } | 298 } |
299 | 299 |
300 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); | 300 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); |
301 | 301 |
302 env[0] = var; | 302 env[0] = var; |
303 | |
304 #if (NGX_SETPROCTITLE_USES_ENV) | |
305 | |
306 /* allocate spare 300 bytes for the new binary process title */ | |
307 | |
308 env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
309 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
310 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
311 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
312 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | |
313 | |
314 env[2] = NULL; | |
315 | |
316 #else | |
317 | |
303 env[1] = NULL; | 318 env[1] = NULL; |
319 | |
320 #endif | |
321 | |
304 ctx.envp = (char *const *) &env; | 322 ctx.envp = (char *const *) &env; |
305 | 323 |
306 pid = ngx_execute(cycle, &ctx); | 324 pid = ngx_execute(cycle, &ctx); |
307 | 325 |
308 ngx_free(var); | 326 ngx_free(var); |
309 | 327 |
310 return pid; | 328 return pid; |
311 } | 329 } |
312 | 330 |
313 | 331 |
314 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle) | 332 static ngx_int_t ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv) |
315 { | 333 { |
316 ngx_int_t i; | 334 ngx_int_t i; |
317 | 335 |
318 for (i = 1; i < ctx->argc; i++) { | 336 for (i = 1; i < argc; i++) { |
319 if (ctx->argv[i][0] != '-') { | 337 if (argv[i][0] != '-') { |
320 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | 338 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
321 "invalid option: \"%s\"", ctx->argv[i]); | 339 "invalid option: \"%s\"", argv[i]); |
322 return NGX_ERROR; | 340 return NGX_ERROR; |
323 } | 341 } |
324 | 342 |
325 switch (ctx->argv[i][1]) { | 343 switch (argv[i][1]) { |
326 | 344 |
327 case 't': | 345 case 't': |
328 ngx_test_config = 1; | 346 ngx_test_config = 1; |
329 break; | 347 break; |
330 | 348 |
331 case 'c': | 349 case 'c': |
332 if (ctx->argv[i + 1] == NULL) { | 350 if (argv[i + 1] == NULL) { |
333 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | 351 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
334 "the option: \"%s\" requires file name", | 352 "the option: \"%s\" requires file name", |
335 ctx->argv[i]); | 353 argv[i]); |
336 return NGX_ERROR; | 354 return NGX_ERROR; |
337 } | 355 } |
338 | 356 |
339 cycle->conf_file.data = (u_char *) ctx->argv[++i]; | 357 cycle->conf_file.data = (u_char *) argv[++i]; |
340 cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); | 358 cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); |
341 break; | 359 break; |
342 | 360 |
343 default: | 361 default: |
344 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | 362 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
345 "invalid option: \"%s\"", ctx->argv[i]); | 363 "invalid option: \"%s\"", argv[i]); |
346 return NGX_ERROR; | 364 return NGX_ERROR; |
347 } | 365 } |
348 } | 366 } |
349 | 367 |
350 if (cycle->conf_file.data == NULL) { | 368 if (cycle->conf_file.data == NULL) { |
353 } | 371 } |
354 | 372 |
355 if (ngx_conf_full_name(cycle, &cycle->conf_file) == NGX_ERROR) { | 373 if (ngx_conf_full_name(cycle, &cycle->conf_file) == NGX_ERROR) { |
356 return NGX_ERROR; | 374 return NGX_ERROR; |
357 } | 375 } |
376 | |
377 return NGX_OK; | |
378 } | |
379 | |
380 | |
381 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv) | |
382 { | |
383 size_t len; | |
384 ngx_int_t i; | |
385 | |
386 ngx_os_argv = (char **) argv; | |
387 | |
388 ngx_argc = argc; | |
389 | |
390 #if __FreeBSD__ | |
391 | |
392 ngx_argv = (char **) argv; | |
393 | |
394 #else | |
395 | |
396 if (!(ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log))) { | |
397 return NGX_ERROR; | |
398 } | |
399 | |
400 for (i = 0; i < argc; i++) { | |
401 len = ngx_strlen(argv[i]) + 1; | |
402 | |
403 if (!(ngx_argv[i] = ngx_alloc(len, cycle->log))) { | |
404 return NGX_ERROR; | |
405 } | |
406 | |
407 ngx_cpystrn((u_char *) ngx_argv[i], (u_char *) argv[i], len); | |
408 } | |
409 | |
410 ngx_argv[i] = NULL; | |
411 | |
412 #endif | |
358 | 413 |
359 return NGX_OK; | 414 return NGX_OK; |
360 } | 415 } |
361 | 416 |
362 | 417 |
405 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); | 460 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); |
406 #endif | 461 #endif |
407 | 462 |
408 #if !(WIN32) | 463 #if !(WIN32) |
409 | 464 |
465 #if 0 | |
410 if (ccf->user == (uid_t) NGX_CONF_UNSET) { | 466 if (ccf->user == (uid_t) NGX_CONF_UNSET) { |
411 | 467 |
412 pwd = getpwnam("nobody"); | 468 pwd = getpwnam("nobody"); |
413 if (pwd == NULL) { | 469 if (pwd == NULL) { |
414 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 470 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
425 return NGX_CONF_ERROR; | 481 return NGX_CONF_ERROR; |
426 } | 482 } |
427 | 483 |
428 ccf->group = grp->gr_gid; | 484 ccf->group = grp->gr_gid; |
429 } | 485 } |
486 #endif | |
430 | 487 |
431 if (ccf->pid.len == 0) { | 488 if (ccf->pid.len == 0) { |
432 ccf->pid.len = sizeof(NGX_PID_PATH) - 1; | 489 ccf->pid.len = sizeof(NGX_PID_PATH) - 1; |
433 ccf->pid.data = NGX_PID_PATH; | 490 ccf->pid.data = (u_char *) NGX_PID_PATH; |
434 } | 491 } |
435 | 492 |
436 if (ngx_conf_full_name(cycle, &ccf->pid) == NGX_ERROR) { | 493 if (ngx_conf_full_name(cycle, &ccf->pid) == NGX_ERROR) { |
437 return NGX_CONF_ERROR; | 494 return NGX_CONF_ERROR; |
438 } | 495 } |
476 value = (ngx_str_t *) cf->args->elts; | 533 value = (ngx_str_t *) cf->args->elts; |
477 | 534 |
478 pwd = getpwnam((const char *) value[1].data); | 535 pwd = getpwnam((const char *) value[1].data); |
479 if (pwd == NULL) { | 536 if (pwd == NULL) { |
480 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, | 537 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
481 "getpwnam(%s) failed", value[1].data); | 538 "getpwnam(\"%s\") failed", value[1].data); |
482 return NGX_CONF_ERROR; | 539 return NGX_CONF_ERROR; |
483 } | 540 } |
484 | 541 |
485 ccf->user = pwd->pw_uid; | 542 ccf->user = pwd->pw_uid; |
486 | 543 |
489 } | 546 } |
490 | 547 |
491 grp = getgrnam((const char *) value[2].data); | 548 grp = getgrnam((const char *) value[2].data); |
492 if (grp == NULL) { | 549 if (grp == NULL) { |
493 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, | 550 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
494 "getgrnam(%s) failed", value[1].data); | 551 "getgrnam(\"%s\") failed", value[2].data); |
495 return NGX_CONF_ERROR; | 552 return NGX_CONF_ERROR; |
496 } | 553 } |
497 | 554 |
498 ccf->group = grp->gr_gid; | 555 ccf->group = grp->gr_gid; |
499 | 556 |