comparison src/core/ngx_cycle.c @ 482:392c16f2d858 NGINX_0_7_53

nginx 0.7.53 *) Change: now a log set by --error-log-path is created from the very start-up. *) Feature: now the start up errors and warnings are outputted to an error_log and stderr. *) Feature: the empty --prefix= configure parameter forces nginx to use a directory where it was run as prefix. *) Feature: the -p switch. *) Feature: the -s switch on Unix platforms. *) Feature: the -? and -h switches. Thanks to Jerome Loyet. *) Feature: now switches may be set in condensed form. *) Bugfix: nginx/Windows did not work if configuration file was given by the -c switch. *) Bugfix: temporary files might be not removed if the "proxy_store", "fastcgi_store", "proxy_cache", or "fastcgi_cache" were used. Thanks to Maxim Dounin. *) Bugfix: an incorrect value was passed to mail proxy authentication server in "Auth-Method" header line; the bug had appeared in 0.7.34. Thanks to Simon Lecaille. *) Bugfix: system error text descriptions were not logged on Linux; the bug had appeared in 0.7.45. *) Bugfix: the "fastcgi_cache_min_uses" directive did not work. Thanks to Andrew Vorobyoff.
author Igor Sysoev <http://sysoev.ru>
date Mon, 27 Apr 2009 00:00:00 +0400
parents 549994537f15
children ed5e10fb40fc
comparison
equal deleted inserted replaced
481:0c98173187ac 482:392c16f2d858
32 32
33 /* STUB NAME */ 33 /* STUB NAME */
34 static ngx_connection_t dumb; 34 static ngx_connection_t dumb;
35 /* STUB */ 35 /* STUB */
36 36
37 #ifdef NGX_ERROR_LOG_PATH
38 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH); 37 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
39 #else
40 static ngx_str_t error_log = ngx_null_string;
41 #endif
42 38
43 39
44 ngx_cycle_t * 40 ngx_cycle_t *
45 ngx_init_cycle(ngx_cycle_t *old_cycle) 41 ngx_init_cycle(ngx_cycle_t *old_cycle)
46 { 42 {
85 } 81 }
86 82
87 cycle->pool = pool; 83 cycle->pool = pool;
88 cycle->log = log; 84 cycle->log = log;
89 cycle->old_cycle = old_cycle; 85 cycle->old_cycle = old_cycle;
90 cycle->root.len = sizeof(NGX_PREFIX) - 1; 86
91 cycle->root.data = (u_char *) NGX_PREFIX; 87 cycle->conf_prefix.len = old_cycle->conf_prefix.len;
92 88 cycle->conf_prefix.data = ngx_pstrdup(pool, &old_cycle->conf_prefix);
89 if (cycle->conf_prefix.data == NULL) {
90 ngx_destroy_pool(pool);
91 return NULL;
92 }
93
94 cycle->prefix.len = old_cycle->prefix.len;
95 cycle->prefix.data = ngx_pstrdup(pool, &old_cycle->prefix);
96 if (cycle->prefix.data == NULL) {
97 ngx_destroy_pool(pool);
98 return NULL;
99 }
93 100
94 cycle->conf_file.len = old_cycle->conf_file.len; 101 cycle->conf_file.len = old_cycle->conf_file.len;
95 cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1); 102 cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1);
96 if (cycle->conf_file.data == NULL) { 103 if (cycle->conf_file.data == NULL) {
97 ngx_destroy_pool(pool); 104 ngx_destroy_pool(pool);
98 return NULL; 105 return NULL;
99 } 106 }
100 ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data, 107 ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,
101 old_cycle->conf_file.len + 1); 108 old_cycle->conf_file.len + 1);
102 109
103
104 cycle->conf_param.len = old_cycle->conf_param.len; 110 cycle->conf_param.len = old_cycle->conf_param.len;
105 cycle->conf_param.data = ngx_pnalloc(pool, old_cycle->conf_param.len); 111 cycle->conf_param.data = ngx_pstrdup(pool, &old_cycle->conf_param);
106 if (cycle->conf_param.data == NULL) { 112 if (cycle->conf_param.data == NULL) {
107 ngx_destroy_pool(pool); 113 ngx_destroy_pool(pool);
108 return NULL; 114 return NULL;
109 } 115 }
110 ngx_memcpy(cycle->conf_param.data, old_cycle->conf_param.data,
111 old_cycle->conf_param.len);
112 116
113 117
114 n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; 118 n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
115 119
116 cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)); 120 cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
160 ngx_destroy_pool(pool); 164 ngx_destroy_pool(pool);
161 return NULL; 165 return NULL;
162 } 166 }
163 167
164 168
165 cycle->new_log = ngx_log_create_errlog(cycle, NULL); 169 cycle->new_log = ngx_log_create_errlog(cycle, &error_log);
166 if (cycle->new_log == NULL) { 170 if (cycle->new_log == NULL) {
167 ngx_destroy_pool(pool); 171 ngx_destroy_pool(pool);
168 return NULL; 172 return NULL;
169 } 173 }
170
171 cycle->new_log->file->name = error_log;
172 174
173 175
174 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10; 176 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
175 177
176 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); 178 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
268 ngx_destroy_cycle_pools(&conf); 270 ngx_destroy_cycle_pools(&conf);
269 return NULL; 271 return NULL;
270 } 272 }
271 273
272 if (ngx_test_config) { 274 if (ngx_test_config) {
273 ngx_log_stderr("the configuration file %s syntax is ok", 275 ngx_log_stderr(0, "the configuration file %s syntax is ok",
274 cycle->conf_file.data); 276 cycle->conf_file.data);
275 } 277 }
276 278
277 279
278 for (i = 0; ngx_modules[i]; i++) { 280 for (i = 0; ngx_modules[i]; i++) {
348 part = part->next; 350 part = part->next;
349 file = part->elts; 351 file = part->elts;
350 i = 0; 352 i = 0;
351 } 353 }
352 354
353 if (file[i].name.data == NULL) { 355 if (file[i].name.len == 0) {
354 continue; 356 continue;
355 } 357 }
356 358
357 file[i].fd = ngx_open_file(file[i].name.data, 359 file[i].fd = ngx_open_file(file[i].name.data,
358 NGX_FILE_APPEND, 360 NGX_FILE_APPEND,
465 goto failed; 467 goto failed;
466 } 468 }
467 469
468 if (!shm_zone[i].shm.exists) { 470 if (!shm_zone[i].shm.exists) {
469 471
470 if (ngx_init_zone_pool(cycle, &shm_zone[i]) != NGX_OK) { 472 if (ngx_init_zone_pool(cycle, &shm_zone[i]) != NGX_OK) {
471 goto failed; 473 goto failed;
472 } 474 }
473 } 475 }
474 476
475 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) { 477 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {
476 goto failed; 478 goto failed;
477 } 479 }
567 } 569 }
568 #endif 570 #endif
569 } 571 }
570 } 572 }
571 573
572 if (ngx_open_listening_sockets(cycle) != NGX_OK) { 574 if (ngx_process != NGX_PROCESS_SIGNALLER) {
573 goto failed; 575 if (ngx_open_listening_sockets(cycle) != NGX_OK) {
574 } 576 goto failed;
575 577 }
576 if (!ngx_test_config) { 578
577 ngx_configure_listening_socket(cycle); 579 if (!ngx_test_config) {
580 ngx_configure_listening_socket(cycle);
581 }
578 } 582 }
579 583
580 584
581 /* commit the new cycle configuration */ 585 /* commit the new cycle configuration */
582 586
583 #if !(NGX_WIN32) 587 if (!ngx_use_stderr && cycle->log->file->fd != ngx_stderr) {
584 588
585 if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { 589 if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) {
586 590 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
587 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, 591 ngx_set_stderr_n " failed");
588 "dup2: %p %d \"%s\"", 592 }
589 cycle->log->file, 593 }
590 cycle->log->file->fd, cycle->log->file->name.data);
591
592 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
593 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
594 "dup2(STDERR) failed");
595 /* fatal */
596 exit(1);
597 }
598 }
599
600 #endif
601 594
602 pool->log = cycle->log; 595 pool->log = cycle->log;
603 596
604 for (i = 0; ngx_modules[i]; i++) { 597 for (i = 0; ngx_modules[i]; i++) {
605 if (ngx_modules[i]->init_module) { 598 if (ngx_modules[i]->init_module) {
693 part = part->next; 686 part = part->next;
694 file = part->elts; 687 file = part->elts;
695 i = 0; 688 i = 0;
696 } 689 }
697 690
698 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) { 691 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr) {
699 continue; 692 continue;
700 } 693 }
701 694
702 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 695 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
703 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 696 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
793 part = part->next; 786 part = part->next;
794 file = part->elts; 787 file = part->elts;
795 i = 0; 788 i = 0;
796 } 789 }
797 790
798 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) { 791 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr) {
799 continue; 792 continue;
800 } 793 }
801 794
802 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 795 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
803 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 796 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
905 898
906 #else 899 #else
907 900
908 file = ngx_pnalloc(cycle->pool, cycle->lock_file.len + zn->shm.name.len); 901 file = ngx_pnalloc(cycle->pool, cycle->lock_file.len + zn->shm.name.len);
909 if (file == NULL) { 902 if (file == NULL) {
910 return NGX_ERROR; 903 return NGX_ERROR;
911 } 904 }
912 905
913 (void) ngx_sprintf(file, "%V%V%Z", &cycle->lock_file, &zn->shm.name); 906 (void) ngx_sprintf(file, "%V%V%Z", &cycle->lock_file, &zn->shm.name);
914 907
915 #endif 908 #endif
916 909
917 if (ngx_shmtx_create(&sp->mutex, (void *) &sp->lock, file) != NGX_OK) { 910 if (ngx_shmtx_create(&sp->mutex, (void *) &sp->lock, file) != NGX_OK) {
918 return NGX_ERROR; 911 return NGX_ERROR;
919 } 912 }
920 913
921 ngx_slab_init(sp); 914 ngx_slab_init(sp);
922 915
923 return NGX_OK; 916 return NGX_OK;
981 974
982 if (ngx_delete_file(name) == NGX_FILE_ERROR) { 975 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
983 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 976 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
984 ngx_delete_file_n " \"%s\" failed", name); 977 ngx_delete_file_n " \"%s\" failed", name);
985 } 978 }
979 }
980
981
982 ngx_int_t
983 ngx_signal_process(ngx_cycle_t *cycle, char *sig)
984 {
985 ssize_t n;
986 ngx_int_t pid;
987 ngx_file_t file;
988 ngx_core_conf_t *ccf;
989 u_char buf[NGX_INT64_LEN + 2];
990
991 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "signal process started");
992
993 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
994
995 file.name = ccf->pid;
996 file.log = cycle->log;
997
998 file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY,
999 NGX_FILE_OPEN, NGX_FILE_DEFAULT_ACCESS);
1000
1001 if (file.fd == NGX_INVALID_FILE) {
1002 ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno,
1003 ngx_open_file_n " \"%s\" failed", file.name.data);
1004 return 1;
1005 }
1006
1007 n = ngx_read_file(&file, buf, NGX_INT64_LEN + 2, 0);
1008
1009 if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
1010 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
1011 ngx_close_file_n " \"%s\" failed", file.name.data);
1012 }
1013
1014 if (n == NGX_ERROR) {
1015 return 1;
1016 }
1017
1018 while (n-- && (buf[n] == CR || buf[n] == LF)) { /* void */ }
1019
1020 pid = ngx_atoi(buf, ++n);
1021
1022 if (pid == NGX_ERROR) {
1023 ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
1024 "invalid PID number \"%*s\" in \"%s\"",
1025 n, buf, file.name.data);
1026 return 1;
1027 }
1028
1029 return ngx_os_signal_process(cycle, sig, pid);
1030
986 } 1031 }
987 1032
988 1033
989 static ngx_int_t 1034 static ngx_int_t
990 ngx_test_lockfile(u_char *file, ngx_log_t *log) 1035 ngx_test_lockfile(u_char *file, ngx_log_t *log)
1038 part = part->next; 1083 part = part->next;
1039 file = part->elts; 1084 file = part->elts;
1040 i = 0; 1085 i = 0;
1041 } 1086 }
1042 1087
1043 if (file[i].name.data == NULL) { 1088 if (file[i].name.len == 0) {
1044 continue; 1089 continue;
1045 } 1090 }
1046 1091
1047 len = file[i].pos - file[i].buffer; 1092 len = file[i].pos - file[i].buffer;
1048 1093