Mercurial > hg > nginx-mail
comparison src/core/ngx_cycle.c @ 272:29a6403156b0 NGINX_0_5_6
nginx 0.5.6
*) Change: now the ngx_http_index_module ignores all methods except the
GET, HEAD, and POST methods.
*) Feature: the ngx_http_limit_zone_module.
*) Feature: the $binary_remote_addr variable.
*) Feature: the "ssl_session_cache" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the DELETE method supports recursive removal.
*) Bugfix: the byte-ranges were transferred incorrectly if the
$r->sendfile() was used.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 09 Jan 2007 00:00:00 +0300 |
parents | 6eb1e38f0f1f |
children | 052a7b1d40e5 |
comparison
equal
deleted
inserted
replaced
271:fcbee7dacf2b | 272:29a6403156b0 |
---|---|
47 ngx_uint_t i, n; | 47 ngx_uint_t i, n; |
48 ngx_log_t *log; | 48 ngx_log_t *log; |
49 ngx_conf_t conf; | 49 ngx_conf_t conf; |
50 ngx_pool_t *pool; | 50 ngx_pool_t *pool; |
51 ngx_cycle_t *cycle, **old; | 51 ngx_cycle_t *cycle, **old; |
52 ngx_shm_zone_t *shm, *oshm; | 52 ngx_shm_zone_t *shm_zone, *oshm_zone; |
53 ngx_slab_pool_t *shpool; | 53 ngx_slab_pool_t *shpool; |
54 ngx_list_part_t *part, *opart; | 54 ngx_list_part_t *part, *opart; |
55 ngx_open_file_t *file; | 55 ngx_open_file_t *file; |
56 ngx_listening_t *ls, *nls; | 56 ngx_listening_t *ls, *nls; |
57 ngx_core_conf_t *ccf; | 57 ngx_core_conf_t *ccf; |
351 | 351 |
352 | 352 |
353 /* create shared memory */ | 353 /* create shared memory */ |
354 | 354 |
355 part = &cycle->shared_memory.part; | 355 part = &cycle->shared_memory.part; |
356 shm = part->elts; | 356 shm_zone = part->elts; |
357 | 357 |
358 for (i = 0; /* void */ ; i++) { | 358 for (i = 0; /* void */ ; i++) { |
359 | 359 |
360 if (i >= part->nelts) { | 360 if (i >= part->nelts) { |
361 if (part->next == NULL) { | 361 if (part->next == NULL) { |
362 break; | 362 break; |
363 } | 363 } |
364 part = part->next; | 364 part = part->next; |
365 shm = part->elts; | 365 shm_zone = part->elts; |
366 i = 0; | 366 i = 0; |
367 } | 367 } |
368 | 368 |
369 shm[i].shm.log = cycle->log; | 369 if (shm_zone[i].shm.size == 0) { |
370 ngx_log_error(NGX_LOG_EMERG, log, 0, | |
371 "zero size shared memory zone \"%V\"", | |
372 &shm_zone[i].name); | |
373 goto failed; | |
374 } | |
375 | |
376 shm_zone[i].shm.log = cycle->log; | |
370 | 377 |
371 opart = &old_cycle->shared_memory.part; | 378 opart = &old_cycle->shared_memory.part; |
372 oshm = opart->elts; | 379 oshm_zone = opart->elts; |
373 | 380 |
374 for (n = 0; /* void */ ; n++) { | 381 for (n = 0; /* void */ ; n++) { |
375 | 382 |
376 if (n >= opart->nelts) { | 383 if (n >= opart->nelts) { |
377 if (opart->next == NULL) { | 384 if (opart->next == NULL) { |
378 break; | 385 break; |
379 } | 386 } |
380 opart = opart->next; | 387 opart = opart->next; |
381 oshm = opart->elts; | 388 oshm_zone = opart->elts; |
382 n = 0; | 389 n = 0; |
383 } | 390 } |
384 | 391 |
385 if (ngx_strcmp(shm[i].name.data, oshm[n].name.data) != 0) { | 392 if (shm_zone[i].name.len != oshm_zone[n].name.len) { |
386 continue; | 393 continue; |
387 } | 394 } |
388 | 395 |
389 if (shm[i].shm.size == oshm[n].shm.size) { | 396 if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data, |
390 shm[i].shm.addr = oshm[n].shm.addr; | 397 shm_zone[i].name.len) |
391 goto found; | 398 != 0) |
392 } | 399 { |
393 | 400 continue; |
394 ngx_shm_free(&oshm[n].shm); | 401 } |
402 | |
403 if (shm_zone[i].shm.size == oshm_zone[n].shm.size) { | |
404 shm_zone[i].shm.addr = oshm_zone[n].shm.addr; | |
405 | |
406 if (shm_zone[i].init(&shm_zone[i], oshm_zone[n].data) | |
407 != NGX_OK) | |
408 { | |
409 goto failed; | |
410 } | |
411 | |
412 goto shm_zone_found; | |
413 } | |
414 | |
415 ngx_shm_free(&oshm_zone[n].shm); | |
395 | 416 |
396 break; | 417 break; |
397 } | 418 } |
398 | 419 |
399 if (ngx_shm_alloc(&shm[i].shm) != NGX_OK) { | 420 if (ngx_shm_alloc(&shm_zone[i].shm) != NGX_OK) { |
400 goto failed; | 421 goto failed; |
401 } | 422 } |
402 | 423 |
403 shpool = (ngx_slab_pool_t *) shm[i].shm.addr; | 424 shpool = (ngx_slab_pool_t *) shm_zone[i].shm.addr; |
404 | 425 |
405 shpool->end = shm[i].shm.addr + shm[i].shm.size; | 426 shpool->end = shm_zone[i].shm.addr + shm_zone[i].shm.size; |
406 shpool->min_shift = 3; | 427 shpool->min_shift = 3; |
407 | 428 |
408 #if (NGX_HAVE_ATOMIC_OPS) | 429 #if (NGX_HAVE_ATOMIC_OPS) |
409 | 430 |
410 lock_file = NULL; | 431 lock_file = NULL; |
411 | 432 |
412 #else | 433 #else |
413 | 434 |
414 lock_file = ngx_palloc(cycle->pool, | 435 lock_file = ngx_palloc(cycle->pool, |
415 cycle->lock_file.len + shm[i].name.len); | 436 cycle->lock_file.len + shm_zone[i].name.len); |
416 | 437 |
417 if (lock_file == NULL) { | 438 if (lock_file == NULL) { |
418 goto failed; | 439 goto failed; |
419 } | 440 } |
420 | 441 |
421 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data, | 442 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data, |
422 cycle->lock_file.len), | 443 cycle->lock_file.len), |
423 shm[i].name.data, shm[i].name.len + 1); | 444 shm_zone[i].name.data, shm_zone[i].name.len + 1); |
424 | 445 |
425 #endif | 446 #endif |
426 | 447 |
427 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file) | 448 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file) |
428 != NGX_OK) | 449 != NGX_OK) |
430 goto failed; | 451 goto failed; |
431 } | 452 } |
432 | 453 |
433 ngx_slab_init(shpool); | 454 ngx_slab_init(shpool); |
434 | 455 |
435 found: | 456 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) { |
457 goto failed; | |
458 } | |
459 | |
460 shm_zone_found: | |
436 | 461 |
437 continue; | 462 continue; |
438 } | 463 } |
439 | 464 |
440 | 465 |
567 } | 592 } |
568 | 593 |
569 | 594 |
570 /* close and delete stuff that lefts from an old cycle */ | 595 /* close and delete stuff that lefts from an old cycle */ |
571 | 596 |
572 /* close the unneeded listening sockets */ | 597 /* free the unnecessary shared memory */ |
598 | |
599 opart = &old_cycle->shared_memory.part; | |
600 oshm_zone = opart->elts; | |
601 | |
602 for (i = 0; /* void */ ; i++) { | |
603 | |
604 if (i >= opart->nelts) { | |
605 if (opart->next == NULL) { | |
606 goto old_shm_zone_done; | |
607 } | |
608 opart = opart->next; | |
609 oshm_zone = opart->elts; | |
610 i = 0; | |
611 } | |
612 | |
613 part = &cycle->shared_memory.part; | |
614 shm_zone = part->elts; | |
615 | |
616 for (n = 0; /* void */ ; n++) { | |
617 | |
618 if (n >= part->nelts) { | |
619 if (part->next == NULL) { | |
620 break; | |
621 } | |
622 part = part->next; | |
623 shm_zone = part->elts; | |
624 n = 0; | |
625 } | |
626 | |
627 if (oshm_zone[i].name.len == shm_zone[n].name.len | |
628 && ngx_strncmp(oshm_zone[i].name.data, | |
629 shm_zone[n].name.data, | |
630 oshm_zone[i].name.len) | |
631 == 0) | |
632 { | |
633 goto live_shm_zone; | |
634 } | |
635 } | |
636 | |
637 ngx_shm_free(&oshm_zone[i].shm); | |
638 | |
639 live_shm_zone: | |
640 | |
641 continue; | |
642 } | |
643 | |
644 old_shm_zone_done: | |
645 | |
646 | |
647 /* close the unnecessary listening sockets */ | |
573 | 648 |
574 ls = old_cycle->listening.elts; | 649 ls = old_cycle->listening.elts; |
575 for (i = 0; i < old_cycle->listening.nelts; i++) { | 650 for (i = 0; i < old_cycle->listening.nelts; i++) { |
576 if (ls[i].remain) { | 651 if (ls[i].remain) { |
577 continue; | 652 continue; |
583 &ls[i].addr_text); | 658 &ls[i].addr_text); |
584 } | 659 } |
585 } | 660 } |
586 | 661 |
587 | 662 |
588 /* close the unneeded open files */ | 663 /* close the unnecessary open files */ |
589 | 664 |
590 part = &old_cycle->open_files.part; | 665 part = &old_cycle->open_files.part; |
591 file = part->elts; | 666 file = part->elts; |
592 | 667 |
593 for (i = 0; /* void */ ; i++) { | 668 for (i = 0; /* void */ ; i++) { |
986 | 1061 |
987 #endif | 1062 #endif |
988 } | 1063 } |
989 | 1064 |
990 | 1065 |
1066 ngx_shm_zone_t * | |
1067 ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size, void *tag) | |
1068 { | |
1069 ngx_uint_t i; | |
1070 ngx_shm_zone_t *shm_zone; | |
1071 ngx_list_part_t *part; | |
1072 | |
1073 part = &cf->cycle->shared_memory.part; | |
1074 shm_zone = part->elts; | |
1075 | |
1076 for (i = 0; /* void */ ; i++) { | |
1077 | |
1078 if (i >= part->nelts) { | |
1079 if (part->next == NULL) { | |
1080 break; | |
1081 } | |
1082 part = part->next; | |
1083 shm_zone = part->elts; | |
1084 i = 0; | |
1085 } | |
1086 | |
1087 if (name->len != shm_zone[i].name.len) { | |
1088 continue; | |
1089 } | |
1090 | |
1091 if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) { | |
1092 continue; | |
1093 } | |
1094 | |
1095 if (size && size != shm_zone[i].shm.size) { | |
1096 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1097 "the size %uz of shared memory zone \"%V\" " | |
1098 "conflicts with already declared size %uz", | |
1099 size, &shm_zone[i].name, shm_zone[i].shm.size); | |
1100 return NULL; | |
1101 } | |
1102 | |
1103 if (tag != shm_zone[i].tag) { | |
1104 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1105 "the shared memory zone \"%V\" is " | |
1106 "already declared for a different use", | |
1107 &shm_zone[i].name); | |
1108 return NULL; | |
1109 } | |
1110 | |
1111 return &shm_zone[i]; | |
1112 } | |
1113 | |
1114 shm_zone = ngx_list_push(&cf->cycle->shared_memory); | |
1115 | |
1116 if (shm_zone == NULL) { | |
1117 return NULL; | |
1118 } | |
1119 | |
1120 shm_zone->data = NULL; | |
1121 shm_zone->shm.log = cf->cycle->log; | |
1122 shm_zone->shm.size = size; | |
1123 shm_zone->init = NULL; | |
1124 shm_zone->name = *name; | |
1125 shm_zone->tag = tag; | |
1126 | |
1127 return shm_zone; | |
1128 } | |
1129 | |
1130 | |
991 static void | 1131 static void |
992 ngx_clean_old_cycles(ngx_event_t *ev) | 1132 ngx_clean_old_cycles(ngx_event_t *ev) |
993 { | 1133 { |
994 ngx_uint_t i, n, found, live; | 1134 ngx_uint_t i, n, found, live; |
995 ngx_log_t *log; | 1135 ngx_log_t *log; |