comparison src/core/ngx_cycle.c @ 258:6ae1357b7b7c NGINX_0_4_14

nginx 0.4.14 *) Feature: the "proxy_pass_error_message" directive in IMAP/POP3 proxy. *) Feature: now configure detects system PCRE library on FreeBSD, Linux, and NetBSD. *) Bugfix: ngx_http_perl_module did not work with perl built with the threads support; bug appeared in 0.3.38. *) Bugfix: ngx_http_perl_module did not work if perl was called recursively. *) Bugfix: nginx ignored a host name in an request line. *) Bugfix: a worker process may got caught in an endless loop, if a FastCGI server sent too many data to the stderr. *) Bugfix: the $upstream_response_time variable may be negative if the system time was changed backward. *) Bugfix: the "Auth-Login-Attempt" parameter was not sent to IMAP/POP3 proxy authentication server when POP3 was used. *) Bugfix: a segmentation fault might occur if connect to IMAP/POP3 proxy authentication server failed.
author Igor Sysoev <http://sysoev.ru>
date Mon, 27 Nov 2006 00:00:00 +0300
parents 73e8476f9142
children 6eb1e38f0f1f
comparison
equal deleted inserted replaced
257:0e566ee1bcd5 258:6ae1357b7b7c
41 41
42 ngx_cycle_t * 42 ngx_cycle_t *
43 ngx_init_cycle(ngx_cycle_t *old_cycle) 43 ngx_init_cycle(ngx_cycle_t *old_cycle)
44 { 44 {
45 void *rv; 45 void *rv;
46 u_char *lock_file;
46 ngx_uint_t i, n; 47 ngx_uint_t i, n;
47 ngx_log_t *log; 48 ngx_log_t *log;
48 ngx_conf_t conf; 49 ngx_conf_t conf;
49 ngx_pool_t *pool; 50 ngx_pool_t *pool;
50 ngx_cycle_t *cycle, **old; 51 ngx_cycle_t *cycle, **old;
51 ngx_list_part_t *part; 52 ngx_shm_zone_t *shm, *oshm;
53 ngx_slab_pool_t *shpool;
54 ngx_list_part_t *part, *opart;
52 ngx_open_file_t *file; 55 ngx_open_file_t *file;
53 ngx_listening_t *ls, *nls; 56 ngx_listening_t *ls, *nls;
54 ngx_core_conf_t *ccf; 57 ngx_core_conf_t *ccf;
55 ngx_core_module_t *module; 58 ngx_core_module_t *module;
56 #if !(WIN32) 59 #if !(WIN32)
118 ngx_destroy_pool(pool); 121 ngx_destroy_pool(pool);
119 return NULL; 122 return NULL;
120 } 123 }
121 124
122 125
126 if (old_cycle->shared_memory.part.nelts) {
127 n = old_cycle->shared_memory.part.nelts;
128 for (part = old_cycle->shared_memory.part.next; part; part = part->next)
129 {
130 n += part->nelts;
131 }
132
133 } else {
134 n = 1;
135 }
136
137 if (ngx_list_init(&cycle->shared_memory, pool, n, sizeof(ngx_shm_zone_t))
138 == NGX_ERROR)
139 {
140 ngx_destroy_pool(pool);
141 return NULL;
142 }
143
144
123 cycle->new_log = ngx_log_create_errlog(cycle, NULL); 145 cycle->new_log = ngx_log_create_errlog(cycle, NULL);
124 if (cycle->new_log == NULL) { 146 if (cycle->new_log == NULL) {
125 ngx_destroy_pool(pool); 147 ngx_destroy_pool(pool);
126 return NULL; 148 return NULL;
127 } 149 }
179 conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log); 201 conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
180 if (conf.temp_pool == NULL) { 202 if (conf.temp_pool == NULL) {
181 ngx_destroy_pool(pool); 203 ngx_destroy_pool(pool);
182 return NULL; 204 return NULL;
183 } 205 }
184
185
186 #if 0
187 cycle->shm.size = /* STUB */ ngx_pagesize;
188 cycle->shm.log = log;
189
190 if (ngx_shm_alloc(&cycle->shm) != NGX_OK) {
191 ngx_destroy_pool(conf.temp_pool);
192 ngx_destroy_pool(pool);
193 return NULL;
194 }
195
196 cycle->shm_last = cycle->shm.addr;
197 cycle->shm_end = cycle->shm.addr + cycle->shm.size;
198 #endif
199 206
200 207
201 conf.ctx = cycle->conf_ctx; 208 conf.ctx = cycle->conf_ctx;
202 conf.cycle = cycle; 209 conf.cycle = cycle;
203 conf.pool = pool; 210 conf.pool = pool;
272 } 279 }
273 280
274 #endif 281 #endif
275 282
276 283
277 if (ngx_test_lockfile(ccf->lock_file.data, log) != NGX_OK) { 284 if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) {
278 goto failed; 285 goto failed;
279 } 286 }
280 287
281 288
282 if (ngx_create_pathes(cycle, ccf->user) != NGX_OK) { 289 if (ngx_create_pathes(cycle, ccf->user) != NGX_OK) {
338 cycle->log = cycle->new_log; 345 cycle->log = cycle->new_log;
339 pool->log = cycle->new_log; 346 pool->log = cycle->new_log;
340 347
341 if (cycle->log->log_level == 0) { 348 if (cycle->log->log_level == 0) {
342 cycle->log->log_level = NGX_LOG_ERR; 349 cycle->log->log_level = NGX_LOG_ERR;
350 }
351
352
353 /* create shared memory */
354
355 part = &cycle->shared_memory.part;
356 shm = part->elts;
357
358 for (i = 0; /* void */ ; i++) {
359
360 if (i >= part->nelts) {
361 if (part->next == NULL) {
362 break;
363 }
364 part = part->next;
365 shm = part->elts;
366 i = 0;
367 }
368
369 shm[i].shm.log = cycle->log;
370
371 opart = &old_cycle->shared_memory.part;
372 oshm = opart->elts;
373
374 for (n = 0; /* void */ ; n++) {
375
376 if (n >= opart->nelts) {
377 if (opart->next == NULL) {
378 break;
379 }
380 opart = opart->next;
381 oshm = opart->elts;
382 n = 0;
383 }
384
385 if (ngx_strcmp(shm[i].name.data, oshm[n].name.data) != 0) {
386 continue;
387 }
388
389 if (shm[i].shm.size == oshm[n].shm.size) {
390 shm[i].shm.addr = oshm[n].shm.addr;
391 goto found;
392 }
393
394 ngx_shm_free(&oshm[n].shm);
395
396 break;
397 }
398
399 if (ngx_shm_alloc(&shm[i].shm) != NGX_OK) {
400 goto failed;
401 }
402
403 shpool = (ngx_slab_pool_t *) shm[i].shm.addr;
404
405 shpool->end = shm[i].shm.addr + shm[i].shm.size;
406 shpool->min_shift = 3;
407
408 #if (NGX_HAVE_ATOMIC_OPS)
409
410 lock_file = NULL;
411
412 #else
413
414 lock_file = ngx_palloc(cycle->pool,
415 cycle->lock_file.len + shm[i].name.len);
416
417 if (lock_file == NULL) {
418 goto failed;
419 }
420
421 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data,
422 cycle->lock_file.len),
423 shm[i].name.data, shm[i].name.len + 1);
424
425 #endif
426
427 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file)
428 != NGX_OK)
429 {
430 goto failed;
431 }
432
433 ngx_slab_init(shpool);
434
435 found:
436
437 continue;
343 } 438 }
344 439
345 440
346 /* handle the listening sockets */ 441 /* handle the listening sockets */
347 442
519 614
520 ngx_destroy_pool(conf.temp_pool); 615 ngx_destroy_pool(conf.temp_pool);
521 616
522 if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) { 617 if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
523 618
524 if (old_cycle->shm.addr) {
525 ngx_shm_free(&old_cycle->shm);
526 }
527
528 ngx_destroy_pool(old_cycle->pool); 619 ngx_destroy_pool(old_cycle->pool);
529
530 cycle->old_cycle = NULL; 620 cycle->old_cycle = NULL;
531 621
532 return cycle; 622 return cycle;
533 } 623 }
534 624
628 718
629 719
630 static void 720 static void
631 ngx_destroy_cycle_pools(ngx_conf_t *conf) 721 ngx_destroy_cycle_pools(ngx_conf_t *conf)
632 { 722 {
633 if (conf->cycle->shm.addr) {
634 ngx_shm_free(&conf->cycle->shm);
635 }
636
637 ngx_destroy_pool(conf->temp_pool); 723 ngx_destroy_pool(conf->temp_pool);
638 ngx_destroy_pool(conf->pool); 724 ngx_destroy_pool(conf->pool);
639 } 725 }
640 726
641 727