comparison src/core/ngx_cycle.c @ 480:549994537f15 NGINX_0_7_52

nginx 0.7.52 *) Feature: the first native Windows binary release. *) Bugfix: in processing HEAD method while caching. *) Bugfix: in processing the "If-Modified-Since", "If-Range", etc. client request header lines while caching. *) Bugfix: now the "Set-Cookie" and "P3P" header lines are hidden in cacheable responses. *) Bugfix: if nginx was built with the ngx_http_perl_module and with a perl which supports threads, then during a master process exit the message "panic: MUTEX_LOCK" might be issued. *) Bugfix: nginx could not be built --without-http-cache; the bug had appeared in 0.7.48. *) Bugfix: nginx could not be built on platforms different from i386, amd64, sparc, and ppc; the bug had appeared in 0.7.42.
author Igor Sysoev <http://sysoev.ru>
date Mon, 20 Apr 2009 00:00:00 +0400
parents f2c6a7373274
children 392c16f2d858
comparison
equal deleted inserted replaced
479:eb4fdebda673 480:549994537f15
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 ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log);
13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); 12 static void ngx_destroy_cycle_pools(ngx_conf_t *conf);
14 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);
14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle,
15 ngx_shm_zone_t *shm_zone);
16 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log);
15 static void ngx_clean_old_cycles(ngx_event_t *ev); 17 static void ngx_clean_old_cycles(ngx_event_t *ev);
16 18
17 19
18 volatile ngx_cycle_t *ngx_cycle; 20 volatile ngx_cycle_t *ngx_cycle;
19 ngx_array_t ngx_old_cycles; 21 ngx_array_t ngx_old_cycles;
42 ngx_cycle_t * 44 ngx_cycle_t *
43 ngx_init_cycle(ngx_cycle_t *old_cycle) 45 ngx_init_cycle(ngx_cycle_t *old_cycle)
44 { 46 {
45 void *rv; 47 void *rv;
46 char **senv, **env; 48 char **senv, **env;
47 u_char *lock_file;
48 ngx_uint_t i, n; 49 ngx_uint_t i, n;
49 ngx_log_t *log; 50 ngx_log_t *log;
50 ngx_time_t *tp; 51 ngx_time_t *tp;
51 ngx_conf_t conf; 52 ngx_conf_t conf;
52 ngx_pool_t *pool; 53 ngx_pool_t *pool;
53 ngx_cycle_t *cycle, **old; 54 ngx_cycle_t *cycle, **old;
54 ngx_shm_zone_t *shm_zone, *oshm_zone; 55 ngx_shm_zone_t *shm_zone, *oshm_zone;
55 ngx_slab_pool_t *shpool;
56 ngx_list_part_t *part, *opart; 56 ngx_list_part_t *part, *opart;
57 ngx_open_file_t *file; 57 ngx_open_file_t *file;
58 ngx_listening_t *ls, *nls; 58 ngx_listening_t *ls, *nls;
59 ngx_core_conf_t *ccf, *old_ccf; 59 ngx_core_conf_t *ccf, *old_ccf;
60 ngx_core_module_t *module; 60 ngx_core_module_t *module;
268 ngx_destroy_cycle_pools(&conf); 268 ngx_destroy_cycle_pools(&conf);
269 return NULL; 269 return NULL;
270 } 270 }
271 271
272 if (ngx_test_config) { 272 if (ngx_test_config) {
273 ngx_log_error(NGX_LOG_INFO, log, 0, 273 ngx_log_stderr("the configuration file %s syntax is ok",
274 "the configuration file %s syntax is ok", 274 cycle->conf_file.data);
275 cycle->conf_file.data);
276 } 275 }
277 276
278 277
279 for (i = 0; ngx_modules[i]; i++) { 278 for (i = 0; ngx_modules[i]; i++) {
280 if (ngx_modules[i]->type != NGX_CORE_MODULE) { 279 if (ngx_modules[i]->type != NGX_CORE_MODULE) {
294 } 293 }
295 294
296 295
297 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); 296 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
298 297
299 #if !(NGX_WIN32)
300
301 if (ngx_test_config) { 298 if (ngx_test_config) {
302 299
303 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) { 300 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) {
304 goto failed; 301 goto failed;
305 } 302 }
324 321
325 ngx_delete_pidfile(old_cycle); 322 ngx_delete_pidfile(old_cycle);
326 } 323 }
327 } 324 }
328 325
329 #endif
330
331 326
332 if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) { 327 if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) {
333 goto failed; 328 goto failed;
334 } 329 }
335 330
410 } 405 }
411 406
412 if (shm_zone[i].shm.size == 0) { 407 if (shm_zone[i].shm.size == 0) {
413 ngx_log_error(NGX_LOG_EMERG, log, 0, 408 ngx_log_error(NGX_LOG_EMERG, log, 0,
414 "zero size shared memory zone \"%V\"", 409 "zero size shared memory zone \"%V\"",
415 &shm_zone[i].name); 410 &shm_zone[i].shm.name);
416 goto failed; 411 goto failed;
417 } 412 }
418 413
419 if (shm_zone[i].init == NULL) { 414 if (shm_zone[i].init == NULL) {
420 /* unused shared zone */ 415 /* unused shared zone */
435 opart = opart->next; 430 opart = opart->next;
436 oshm_zone = opart->elts; 431 oshm_zone = opart->elts;
437 n = 0; 432 n = 0;
438 } 433 }
439 434
440 if (shm_zone[i].name.len != oshm_zone[n].name.len) { 435 if (shm_zone[i].shm.name.len != oshm_zone[n].shm.name.len) {
441 continue; 436 continue;
442 } 437 }
443 438
444 if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data, 439 if (ngx_strncmp(shm_zone[i].shm.name.data,
445 shm_zone[i].name.len) 440 oshm_zone[n].shm.name.data,
441 shm_zone[i].shm.name.len)
446 != 0) 442 != 0)
447 { 443 {
448 continue; 444 continue;
449 } 445 }
450 446
467 463
468 if (ngx_shm_alloc(&shm_zone[i].shm) != NGX_OK) { 464 if (ngx_shm_alloc(&shm_zone[i].shm) != NGX_OK) {
469 goto failed; 465 goto failed;
470 } 466 }
471 467
472 shpool = (ngx_slab_pool_t *) shm_zone[i].shm.addr; 468 if (!shm_zone[i].shm.exists) {
473 469
474 shpool->end = shm_zone[i].shm.addr + shm_zone[i].shm.size; 470 if (ngx_init_zone_pool(cycle, &shm_zone[i]) != NGX_OK) {
475 shpool->min_shift = 3; 471 goto failed;
476 472 }
477 #if (NGX_HAVE_ATOMIC_OPS) 473 }
478
479 lock_file = NULL;
480
481 #else
482
483 lock_file = ngx_pnalloc(cycle->pool,
484 cycle->lock_file.len + shm_zone[i].name.len);
485
486 if (lock_file == NULL) {
487 goto failed;
488 }
489
490 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data,
491 cycle->lock_file.len),
492 shm_zone[i].name.data, shm_zone[i].name.len + 1);
493
494 #endif
495
496 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file)
497 != NGX_OK)
498 {
499 goto failed;
500 }
501
502 ngx_slab_init(shpool);
503 474
504 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) { 475 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {
505 goto failed; 476 goto failed;
506 } 477 }
507 478
670 part = part->next; 641 part = part->next;
671 shm_zone = part->elts; 642 shm_zone = part->elts;
672 n = 0; 643 n = 0;
673 } 644 }
674 645
675 if (oshm_zone[i].name.len == shm_zone[n].name.len 646 if (oshm_zone[i].shm.name.len == shm_zone[n].shm.name.len
676 && ngx_strncmp(oshm_zone[i].name.data, 647 && ngx_strncmp(oshm_zone[i].shm.name.data,
677 shm_zone[n].name.data, 648 shm_zone[n].shm.name.data,
678 oshm_zone[i].name.len) 649 oshm_zone[i].shm.name.len)
679 == 0) 650 == 0)
680 { 651 {
681 goto live_shm_zone; 652 goto live_shm_zone;
682 } 653 }
683 } 654 }
915 886
916 return NGX_OK; 887 return NGX_OK;
917 } 888 }
918 889
919 890
920 #if !(NGX_WIN32) 891 static ngx_int_t
892 ngx_init_zone_pool(ngx_cycle_t *cycle, ngx_shm_zone_t *zn)
893 {
894 u_char *file;
895 ngx_slab_pool_t *sp;
896
897 sp = (ngx_slab_pool_t *) zn->shm.addr;
898
899 sp->end = zn->shm.addr + zn->shm.size;
900 sp->min_shift = 3;
901
902 #if (NGX_HAVE_ATOMIC_OPS)
903
904 file = NULL;
905
906 #else
907
908 file = ngx_pnalloc(cycle->pool, cycle->lock_file.len + zn->shm.name.len);
909 if (file == NULL) {
910 return NGX_ERROR;
911 }
912
913 (void) ngx_sprintf(file, "%V%V%Z", &cycle->lock_file, &zn->shm.name);
914
915 #endif
916
917 if (ngx_shmtx_create(&sp->mutex, (void *) &sp->lock, file) != NGX_OK) {
918 return NGX_ERROR;
919 }
920
921 ngx_slab_init(sp);
922
923 return NGX_OK;
924 }
925
921 926
922 ngx_int_t 927 ngx_int_t
923 ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log) 928 ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log)
924 { 929 {
925 size_t len; 930 size_t len;
926 ngx_uint_t create; 931 ngx_uint_t create;
927 ngx_file_t file; 932 ngx_file_t file;
928 u_char pid[NGX_INT64_LEN + 2]; 933 u_char pid[NGX_INT64_LEN + 2];
929 934
935 if (ngx_process > NGX_PROCESS_MASTER) {
936 return NGX_OK;
937 }
938
930 ngx_memzero(&file, sizeof(ngx_file_t)); 939 ngx_memzero(&file, sizeof(ngx_file_t));
931 940
932 file.name = *name; 941 file.name = *name;
933 file.log = log; 942 file.log = log;
934 943
973 if (ngx_delete_file(name) == NGX_FILE_ERROR) { 982 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
974 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 983 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
975 ngx_delete_file_n " \"%s\" failed", name); 984 ngx_delete_file_n " \"%s\" failed", name);
976 } 985 }
977 } 986 }
978
979 #endif
980 987
981 988
982 static ngx_int_t 989 static ngx_int_t
983 ngx_test_lockfile(u_char *file, ngx_log_t *log) 990 ngx_test_lockfile(u_char *file, ngx_log_t *log)
984 { 991 {
1173 part = part->next; 1180 part = part->next;
1174 shm_zone = part->elts; 1181 shm_zone = part->elts;
1175 i = 0; 1182 i = 0;
1176 } 1183 }
1177 1184
1178 if (name->len != shm_zone[i].name.len) { 1185 if (name->len != shm_zone[i].shm.name.len) {
1179 continue; 1186 continue;
1180 } 1187 }
1181 1188
1182 if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) { 1189 if (ngx_strncmp(name->data, shm_zone[i].shm.name.data, name->len)
1190 != 0)
1191 {
1183 continue; 1192 continue;
1184 } 1193 }
1185 1194
1186 if (size && size != shm_zone[i].shm.size) { 1195 if (size && size != shm_zone[i].shm.size) {
1187 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1196 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1188 "the size %uz of shared memory zone \"%V\" " 1197 "the size %uz of shared memory zone \"%V\" "
1189 "conflicts with already declared size %uz", 1198 "conflicts with already declared size %uz",
1190 size, &shm_zone[i].name, shm_zone[i].shm.size); 1199 size, &shm_zone[i].shm.name, shm_zone[i].shm.size);
1191 return NULL; 1200 return NULL;
1192 } 1201 }
1193 1202
1194 if (tag != shm_zone[i].tag) { 1203 if (tag != shm_zone[i].tag) {
1195 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1204 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1196 "the shared memory zone \"%V\" is " 1205 "the shared memory zone \"%V\" is "
1197 "already declared for a different use", 1206 "already declared for a different use",
1198 &shm_zone[i].name); 1207 &shm_zone[i].shm.name);
1199 return NULL; 1208 return NULL;
1200 } 1209 }
1201 1210
1202 return &shm_zone[i]; 1211 return &shm_zone[i];
1203 } 1212 }
1209 } 1218 }
1210 1219
1211 shm_zone->data = NULL; 1220 shm_zone->data = NULL;
1212 shm_zone->shm.log = cf->cycle->log; 1221 shm_zone->shm.log = cf->cycle->log;
1213 shm_zone->shm.size = size; 1222 shm_zone->shm.size = size;
1223 shm_zone->shm.name = *name;
1224 shm_zone->shm.exists = 0;
1214 shm_zone->init = NULL; 1225 shm_zone->init = NULL;
1215 shm_zone->name = *name;
1216 shm_zone->tag = tag; 1226 shm_zone->tag = tag;
1217 1227
1218 return shm_zone; 1228 return shm_zone;
1219 } 1229 }
1220 1230