comparison src/core/ngx_cycle.c @ 605:5dac8c7fb71b release-0.3.24

nginx-0.3.24-RELEASE import *) Workaround: for bug in FreeBSD kqueue. *) Bugfix: now a response generated by the "post_action" directive is not transferred to a client. *) Bugfix: the memory leaks were occurring if many log files were used. *) Bugfix: the first "proxy_redirect" directive was working inside one location. *) Bugfix: on 64-bit platforms segmentation fault may occurred on start if the many names were used in the "server_name" directives; the bug had appeared in 0.3.18.
author Igor Sysoev <igor@sysoev.ru>
date Wed, 01 Feb 2006 18:22:15 +0000
parents 425af804d968
children 77cdfe394a94
comparison
equal deleted inserted replaced
604:f4a6e8f250a8 605:5dac8c7fb71b
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 10
11 11
12 static void ngx_destroy_cycle_pools(ngx_conf_t *conf);
12 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2); 13 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2);
13 static void ngx_clean_old_cycles(ngx_event_t *ev); 14 static void ngx_clean_old_cycles(ngx_event_t *ev);
14 15
15 16
16 volatile ngx_cycle_t *ngx_cycle; 17 volatile ngx_cycle_t *ngx_cycle;
38 39
39 40
40 ngx_cycle_t * 41 ngx_cycle_t *
41 ngx_init_cycle(ngx_cycle_t *old_cycle) 42 ngx_init_cycle(ngx_cycle_t *old_cycle)
42 { 43 {
43 void *rv; 44 void *rv;
44 ngx_uint_t i, n, failed; 45 ngx_uint_t i, n, failed;
45 ngx_log_t *log; 46 ngx_log_t *log;
46 ngx_conf_t conf; 47 ngx_conf_t conf;
47 ngx_pool_t *pool; 48 ngx_pool_t *pool;
48 ngx_cycle_t *cycle, **old; 49 ngx_cycle_t *cycle, **old;
49 ngx_list_part_t *part; 50 ngx_list_part_t *part;
50 ngx_open_file_t *file; 51 ngx_open_file_t *file;
51 ngx_listening_t *ls, *nls; 52 ngx_listening_t *ls, *nls;
52 ngx_core_conf_t *ccf; 53 ngx_core_conf_t *ccf;
53 ngx_core_module_t *module; 54 ngx_core_module_t *module;
55
54 56
55 log = old_cycle->log; 57 log = old_cycle->log;
56 58
57 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log); 59 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
58 if (pool == NULL) { 60 if (pool == NULL) {
67 } 69 }
68 70
69 cycle->pool = pool; 71 cycle->pool = pool;
70 cycle->log = log; 72 cycle->log = log;
71 cycle->old_cycle = old_cycle; 73 cycle->old_cycle = old_cycle;
72 cycle->conf_file = old_cycle->conf_file;
73 cycle->root.len = sizeof(NGX_PREFIX) - 1; 74 cycle->root.len = sizeof(NGX_PREFIX) - 1;
74 cycle->root.data = (u_char *) NGX_PREFIX; 75 cycle->root.data = (u_char *) NGX_PREFIX;
76
77
78 cycle->conf_file.len = old_cycle->conf_file.len;
79 cycle->conf_file.data = ngx_palloc(pool, old_cycle->conf_file.len + 1);
80 if (cycle->conf_file.data == NULL) {
81 ngx_destroy_pool(pool);
82 return NULL;
83 }
84 ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,
85 old_cycle->conf_file.len + 1);
75 86
76 87
77 n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; 88 n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
78 89
79 cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)); 90 cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
97 } else { 108 } else {
98 n = 20; 109 n = 20;
99 } 110 }
100 111
101 if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t)) 112 if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
102 == NGX_ERROR) 113 == NGX_ERROR)
103 { 114 {
104 ngx_destroy_pool(pool); 115 ngx_destroy_pool(pool);
105 return NULL; 116 return NULL;
106 } 117 }
107 118
165 conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log); 176 conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
166 if (conf.temp_pool == NULL) { 177 if (conf.temp_pool == NULL) {
167 ngx_destroy_pool(pool); 178 ngx_destroy_pool(pool);
168 return NULL; 179 return NULL;
169 } 180 }
181
182
183 #if 0
184 cycle->shm.size = /* STUB */ ngx_pagesize;
185 cycle->shm.log = log;
186
187 if (ngx_shm_alloc(&cycle->shm) != NGX_OK) {
188 ngx_destroy_pool(conf.temp_pool);
189 ngx_destroy_pool(pool);
190 return NULL;
191 }
192
193 cycle->shm_last = cycle->shm.addr;
194 cycle->shm_end = cycle->shm.addr + cycle->shm.size;
195 #endif
196
170 197
171 conf.ctx = cycle->conf_ctx; 198 conf.ctx = cycle->conf_ctx;
172 conf.cycle = cycle; 199 conf.cycle = cycle;
173 conf.pool = pool; 200 conf.pool = pool;
174 conf.log = log; 201 conf.log = log;
178 #if 0 205 #if 0
179 log->log_level = NGX_LOG_DEBUG_ALL; 206 log->log_level = NGX_LOG_DEBUG_ALL;
180 #endif 207 #endif
181 208
182 if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) { 209 if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
183 ngx_destroy_pool(conf.temp_pool); 210 ngx_destroy_cycle_pools(&conf);
184 ngx_destroy_pool(pool);
185 return NULL; 211 return NULL;
186 } 212 }
187 213
188 if (ngx_test_config) { 214 if (ngx_test_config) {
189 ngx_log_error(NGX_LOG_INFO, log, 0, 215 ngx_log_error(NGX_LOG_INFO, log, 0,
201 227
202 if (module->init_conf) { 228 if (module->init_conf) {
203 if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index]) 229 if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index])
204 == NGX_CONF_ERROR) 230 == NGX_CONF_ERROR)
205 { 231 {
206 ngx_destroy_pool(conf.temp_pool); 232 ngx_destroy_cycle_pools(&conf);
207 ngx_destroy_pool(pool);
208 return NULL; 233 return NULL;
209 } 234 }
210 } 235 }
211 } 236 }
212 237
395 ngx_configure_listening_socket(cycle); 420 ngx_configure_listening_socket(cycle);
396 } 421 }
397 } 422 }
398 } 423 }
399 424
425
400 if (failed) { 426 if (failed) {
401 427
402 /* rollback the new cycle configuration */ 428 /* rollback the new cycle configuration */
403 429
404 part = &cycle->open_files.part; 430 part = &cycle->open_files.part;
427 file[i].name.data); 453 file[i].name.data);
428 } 454 }
429 } 455 }
430 456
431 if (ngx_test_config) { 457 if (ngx_test_config) {
432 ngx_destroy_pool(conf.temp_pool); 458 ngx_destroy_cycle_pools(&conf);
433 ngx_destroy_pool(pool);
434 return NULL; 459 return NULL;
435 } 460 }
436 461
437 ls = cycle->listening.elts; 462 ls = cycle->listening.elts;
438 for (i = 0; i < cycle->listening.nelts; i++) { 463 for (i = 0; i < cycle->listening.nelts; i++) {
445 ngx_close_socket_n " %V failed", 470 ngx_close_socket_n " %V failed",
446 &ls[i].addr_text); 471 &ls[i].addr_text);
447 } 472 }
448 } 473 }
449 474
450 ngx_destroy_pool(conf.temp_pool); 475 ngx_destroy_cycle_pools(&conf);
451 ngx_destroy_pool(pool);
452 return NULL; 476 return NULL;
453 } 477 }
454 478
455 479
456 /* commit the new cycle configuration */ 480 /* commit the new cycle configuration */
531 } 555 }
532 } 556 }
533 557
534 ngx_destroy_pool(conf.temp_pool); 558 ngx_destroy_pool(conf.temp_pool);
535 559
536 if (old_cycle->connections == NULL) { 560 if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
537 /* an old cycle is an init cycle */ 561
562 if (old_cycle->shm.addr) {
563 ngx_shm_free(&old_cycle->shm);
564 }
565
538 ngx_destroy_pool(old_cycle->pool); 566 ngx_destroy_pool(old_cycle->pool);
539 return cycle; 567 return cycle;
540 } 568 }
541 569
542 if (ngx_process == NGX_PROCESS_MASTER) {
543 ngx_destroy_pool(old_cycle->pool);
544 return cycle;
545 }
546 570
547 if (ngx_temp_pool == NULL) { 571 if (ngx_temp_pool == NULL) {
548 ngx_temp_pool = ngx_create_pool(128, cycle->log); 572 ngx_temp_pool = ngx_create_pool(128, cycle->log);
549 if (ngx_temp_pool == NULL) { 573 if (ngx_temp_pool == NULL) {
550 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, 574 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
581 ngx_add_timer(&ngx_cleaner_event, 30000); 605 ngx_add_timer(&ngx_cleaner_event, 30000);
582 ngx_cleaner_event.timer_set = 1; 606 ngx_cleaner_event.timer_set = 1;
583 } 607 }
584 608
585 return cycle; 609 return cycle;
610 }
611
612
613 static void
614 ngx_destroy_cycle_pools(ngx_conf_t *conf)
615 {
616 ngx_shm_free(&conf->cycle->shm);
617 ngx_destroy_pool(conf->temp_pool);
618 ngx_destroy_pool(conf->pool);
586 } 619 }
587 620
588 621
589 static ngx_int_t 622 static ngx_int_t
590 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2) 623 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2)
621 size_t len; 654 size_t len;
622 u_char pid[NGX_INT64_LEN]; 655 u_char pid[NGX_INT64_LEN];
623 ngx_file_t file; 656 ngx_file_t file;
624 ngx_core_conf_t *ccf, *old_ccf; 657 ngx_core_conf_t *ccf, *old_ccf;
625 658
626 if (!ngx_test_config && old_cycle && old_cycle->conf_ctx == NULL) { 659 if (!ngx_test_config && ngx_is_init_cycle(old_cycle)) {
627 660
628 /* 661 /*
629 * do not create the pid file in the first ngx_init_cycle() call 662 * do not create the pid file in the first ngx_init_cycle() call
630 * because we need to write the demonized process pid 663 * because we need to write the demonized process pid
631 */ 664 */