0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_event.h>
|
|
10
|
|
11
|
160
|
12 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log);
|
154
|
13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf);
|
28
|
14 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2);
|
0
|
15 static void ngx_clean_old_cycles(ngx_event_t *ev);
|
|
16
|
|
17
|
|
18 volatile ngx_cycle_t *ngx_cycle;
|
|
19 ngx_array_t ngx_old_cycles;
|
|
20
|
|
21 static ngx_pool_t *ngx_temp_pool;
|
|
22 static ngx_event_t ngx_cleaner_event;
|
|
23
|
|
24 ngx_uint_t ngx_test_config;
|
|
25
|
|
26 #if (NGX_THREADS)
|
|
27 ngx_tls_key_t ngx_core_tls_key;
|
|
28 #endif
|
|
29
|
|
30
|
|
31 /* STUB NAME */
|
|
32 static ngx_connection_t dumb;
|
|
33 /* STUB */
|
|
34
|
|
35 #ifdef NGX_ERROR_LOG_PATH
|
|
36 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
|
|
37 #else
|
|
38 static ngx_str_t error_log = ngx_null_string;
|
|
39 #endif
|
|
40
|
|
41
|
112
|
42 ngx_cycle_t *
|
|
43 ngx_init_cycle(ngx_cycle_t *old_cycle)
|
0
|
44 {
|
356
|
45 void *rv;
|
|
46 char **senv, **env;
|
|
47 u_char *lock_file;
|
|
48 ngx_uint_t i, n;
|
|
49 ngx_log_t *log;
|
|
50 ngx_conf_t conf;
|
|
51 ngx_pool_t *pool;
|
|
52 ngx_cycle_t *cycle, **old;
|
|
53 ngx_shm_zone_t *shm_zone, *oshm_zone;
|
|
54 ngx_slab_pool_t *shpool;
|
|
55 ngx_list_part_t *part, *opart;
|
|
56 ngx_open_file_t *file;
|
|
57 ngx_listening_t *ls, *nls;
|
|
58 ngx_core_conf_t *ccf, *old_ccf;
|
|
59 ngx_core_module_t *module;
|
376
|
60 char hostname[NGX_MAXHOSTNAMELEN];
|
0
|
61
|
|
62 log = old_cycle->log;
|
|
63
|
56
|
64 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
|
50
|
65 if (pool == NULL) {
|
0
|
66 return NULL;
|
|
67 }
|
|
68 pool->log = log;
|
|
69
|
50
|
70 cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t));
|
|
71 if (cycle == NULL) {
|
0
|
72 ngx_destroy_pool(pool);
|
|
73 return NULL;
|
|
74 }
|
50
|
75
|
0
|
76 cycle->pool = pool;
|
|
77 cycle->log = log;
|
|
78 cycle->old_cycle = old_cycle;
|
|
79 cycle->root.len = sizeof(NGX_PREFIX) - 1;
|
|
80 cycle->root.data = (u_char *) NGX_PREFIX;
|
|
81
|
|
82
|
154
|
83 cycle->conf_file.len = old_cycle->conf_file.len;
|
382
|
84 cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1);
|
154
|
85 if (cycle->conf_file.data == NULL) {
|
|
86 ngx_destroy_pool(pool);
|
|
87 return NULL;
|
|
88 }
|
|
89 ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,
|
|
90 old_cycle->conf_file.len + 1);
|
|
91
|
|
92
|
384
|
93 cycle->conf_param.len = old_cycle->conf_param.len;
|
|
94 cycle->conf_param.data = ngx_pnalloc(pool, old_cycle->conf_param.len);
|
|
95 if (cycle->conf_param.data == NULL) {
|
|
96 ngx_destroy_pool(pool);
|
|
97 return NULL;
|
|
98 }
|
|
99 ngx_memcpy(cycle->conf_param.data, old_cycle->conf_param.data,
|
|
100 old_cycle->conf_param.len);
|
|
101
|
|
102
|
0
|
103 n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
|
50
|
104
|
|
105 cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
|
|
106 if (cycle->pathes.elts == NULL) {
|
0
|
107 ngx_destroy_pool(pool);
|
|
108 return NULL;
|
|
109 }
|
50
|
110
|
0
|
111 cycle->pathes.nelts = 0;
|
|
112 cycle->pathes.size = sizeof(ngx_path_t *);
|
|
113 cycle->pathes.nalloc = n;
|
|
114 cycle->pathes.pool = pool;
|
|
115
|
|
116
|
|
117 if (old_cycle->open_files.part.nelts) {
|
|
118 n = old_cycle->open_files.part.nelts;
|
|
119 for (part = old_cycle->open_files.part.next; part; part = part->next) {
|
|
120 n += part->nelts;
|
|
121 }
|
|
122
|
|
123 } else {
|
|
124 n = 20;
|
|
125 }
|
|
126
|
|
127 if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
|
154
|
128 == NGX_ERROR)
|
0
|
129 {
|
|
130 ngx_destroy_pool(pool);
|
|
131 return NULL;
|
|
132 }
|
|
133
|
|
134
|
258
|
135 if (old_cycle->shared_memory.part.nelts) {
|
|
136 n = old_cycle->shared_memory.part.nelts;
|
|
137 for (part = old_cycle->shared_memory.part.next; part; part = part->next)
|
|
138 {
|
|
139 n += part->nelts;
|
|
140 }
|
|
141
|
|
142 } else {
|
|
143 n = 1;
|
|
144 }
|
|
145
|
|
146 if (ngx_list_init(&cycle->shared_memory, pool, n, sizeof(ngx_shm_zone_t))
|
|
147 == NGX_ERROR)
|
|
148 {
|
|
149 ngx_destroy_pool(pool);
|
|
150 return NULL;
|
|
151 }
|
|
152
|
|
153
|
50
|
154 cycle->new_log = ngx_log_create_errlog(cycle, NULL);
|
|
155 if (cycle->new_log == NULL) {
|
0
|
156 ngx_destroy_pool(pool);
|
|
157 return NULL;
|
|
158 }
|
|
159
|
|
160 cycle->new_log->file->name = error_log;
|
|
161
|
|
162
|
|
163 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
|
50
|
164
|
0
|
165 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
|
|
166 if (cycle->listening.elts == NULL) {
|
|
167 ngx_destroy_pool(pool);
|
|
168 return NULL;
|
|
169 }
|
50
|
170
|
0
|
171 cycle->listening.nelts = 0;
|
|
172 cycle->listening.size = sizeof(ngx_listening_t);
|
|
173 cycle->listening.nalloc = n;
|
|
174 cycle->listening.pool = pool;
|
|
175
|
|
176
|
|
177 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
|
|
178 if (cycle->conf_ctx == NULL) {
|
|
179 ngx_destroy_pool(pool);
|
|
180 return NULL;
|
|
181 }
|
|
182
|
|
183
|
376
|
184 if (gethostname(hostname, NGX_MAXHOSTNAMELEN) == -1) {
|
|
185 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "gethostname() failed");
|
|
186 ngx_destroy_pool(pool);
|
|
187 return NULL;
|
|
188 }
|
|
189
|
|
190 /* on Linux gethostname() silently truncates name that does not fit */
|
|
191
|
|
192 hostname[NGX_MAXHOSTNAMELEN - 1] = '\0';
|
|
193 cycle->hostname.len = ngx_strlen(hostname);
|
|
194
|
382
|
195 cycle->hostname.data = ngx_pnalloc(pool, cycle->hostname.len);
|
376
|
196 if (cycle->hostname.data == NULL) {
|
|
197 ngx_destroy_pool(pool);
|
|
198 return NULL;
|
|
199 }
|
|
200
|
|
201 ngx_memcpy(cycle->hostname.data, hostname, cycle->hostname.len);
|
|
202
|
|
203
|
0
|
204 for (i = 0; ngx_modules[i]; i++) {
|
|
205 if (ngx_modules[i]->type != NGX_CORE_MODULE) {
|
|
206 continue;
|
|
207 }
|
|
208
|
|
209 module = ngx_modules[i]->ctx;
|
|
210
|
|
211 if (module->create_conf) {
|
|
212 rv = module->create_conf(cycle);
|
|
213 if (rv == NGX_CONF_ERROR) {
|
|
214 ngx_destroy_pool(pool);
|
|
215 return NULL;
|
|
216 }
|
|
217 cycle->conf_ctx[ngx_modules[i]->index] = rv;
|
|
218 }
|
|
219 }
|
|
220
|
|
221
|
356
|
222 senv = environ;
|
|
223
|
|
224
|
0
|
225 ngx_memzero(&conf, sizeof(ngx_conf_t));
|
|
226 /* STUB: init array ? */
|
50
|
227 conf.args = ngx_array_create(pool, 10, sizeof(ngx_str_t));
|
0
|
228 if (conf.args == NULL) {
|
|
229 ngx_destroy_pool(pool);
|
|
230 return NULL;
|
|
231 }
|
|
232
|
142
|
233 conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
|
|
234 if (conf.temp_pool == NULL) {
|
|
235 ngx_destroy_pool(pool);
|
|
236 return NULL;
|
|
237 }
|
|
238
|
154
|
239
|
0
|
240 conf.ctx = cycle->conf_ctx;
|
|
241 conf.cycle = cycle;
|
|
242 conf.pool = pool;
|
|
243 conf.log = log;
|
|
244 conf.module_type = NGX_CORE_MODULE;
|
|
245 conf.cmd_type = NGX_MAIN_CONF;
|
|
246
|
4
|
247 #if 0
|
|
248 log->log_level = NGX_LOG_DEBUG_ALL;
|
|
249 #endif
|
0
|
250
|
384
|
251 if (ngx_conf_param(&conf) != NGX_CONF_OK) {
|
|
252 ngx_destroy_cycle_pools(&conf);
|
|
253 return NULL;
|
|
254 }
|
|
255
|
0
|
256 if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
|
154
|
257 ngx_destroy_cycle_pools(&conf);
|
0
|
258 return NULL;
|
|
259 }
|
|
260
|
|
261 if (ngx_test_config) {
|
|
262 ngx_log_error(NGX_LOG_INFO, log, 0,
|
|
263 "the configuration file %s syntax is ok",
|
|
264 cycle->conf_file.data);
|
|
265 }
|
|
266
|
|
267
|
|
268 for (i = 0; ngx_modules[i]; i++) {
|
|
269 if (ngx_modules[i]->type != NGX_CORE_MODULE) {
|
|
270 continue;
|
|
271 }
|
|
272
|
|
273 module = ngx_modules[i]->ctx;
|
|
274
|
|
275 if (module->init_conf) {
|
|
276 if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index])
|
142
|
277 == NGX_CONF_ERROR)
|
0
|
278 {
|
154
|
279 ngx_destroy_cycle_pools(&conf);
|
0
|
280 return NULL;
|
|
281 }
|
|
282 }
|
|
283 }
|
|
284
|
|
285
|
160
|
286 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
0
|
287
|
10
|
288 #if !(NGX_WIN32)
|
160
|
289
|
|
290 if (ngx_test_config) {
|
|
291
|
|
292 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) {
|
|
293 goto failed;
|
|
294 }
|
|
295
|
|
296 } else if (!ngx_is_init_cycle(old_cycle)) {
|
|
297
|
|
298 /*
|
|
299 * we do not create the pid file in the first ngx_init_cycle() call
|
|
300 * because we need to write the demonized process pid
|
|
301 */
|
|
302
|
|
303 old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx,
|
|
304 ngx_core_module);
|
|
305 if (ccf->pid.len != old_ccf->pid.len
|
|
306 || ngx_strcmp(ccf->pid.data, old_ccf->pid.data) != 0)
|
|
307 {
|
|
308 /* new pid file name */
|
|
309
|
|
310 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) {
|
|
311 goto failed;
|
|
312 }
|
|
313
|
|
314 ngx_delete_pidfile(old_cycle);
|
|
315 }
|
0
|
316 }
|
160
|
317
|
0
|
318 #endif
|
|
319
|
|
320
|
258
|
321 if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) {
|
160
|
322 goto failed;
|
|
323 }
|
16
|
324
|
160
|
325
|
|
326 if (ngx_create_pathes(cycle, ccf->user) != NGX_OK) {
|
|
327 goto failed;
|
16
|
328 }
|
|
329
|
|
330
|
160
|
331 /* open the new files */
|
0
|
332
|
160
|
333 part = &cycle->open_files.part;
|
|
334 file = part->elts;
|
0
|
335
|
160
|
336 for (i = 0; /* void */ ; i++) {
|
0
|
337
|
160
|
338 if (i >= part->nelts) {
|
|
339 if (part->next == NULL) {
|
0
|
340 break;
|
|
341 }
|
160
|
342 part = part->next;
|
|
343 file = part->elts;
|
|
344 i = 0;
|
|
345 }
|
|
346
|
|
347 if (file[i].name.data == NULL) {
|
|
348 continue;
|
|
349 }
|
|
350
|
|
351 file[i].fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,
|
276
|
352 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND,
|
|
353 NGX_FILE_DEFAULT_ACCESS);
|
160
|
354
|
|
355 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
|
|
356 "log: %p %d \"%s\"",
|
|
357 &file[i], file[i].fd, file[i].name.data);
|
|
358
|
|
359 if (file[i].fd == NGX_INVALID_FILE) {
|
|
360 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
361 ngx_open_file_n " \"%s\" failed",
|
|
362 file[i].name.data);
|
|
363 goto failed;
|
|
364 }
|
0
|
365
|
10
|
366 #if (NGX_WIN32)
|
160
|
367 if (ngx_file_append_mode(file[i].fd) != NGX_OK) {
|
|
368 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
369 ngx_file_append_mode_n " \"%s\" failed",
|
|
370 file[i].name.data);
|
|
371 goto failed;
|
|
372 }
|
0
|
373 #else
|
160
|
374 if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) {
|
|
375 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
376 "fcntl(FD_CLOEXEC) \"%s\" failed",
|
|
377 file[i].name.data);
|
|
378 goto failed;
|
|
379 }
|
0
|
380 #endif
|
|
381 }
|
|
382
|
|
383 cycle->log = cycle->new_log;
|
|
384 pool->log = cycle->new_log;
|
|
385
|
|
386 if (cycle->log->log_level == 0) {
|
|
387 cycle->log->log_level = NGX_LOG_ERR;
|
|
388 }
|
|
389
|
10
|
390
|
258
|
391 /* create shared memory */
|
|
392
|
|
393 part = &cycle->shared_memory.part;
|
272
|
394 shm_zone = part->elts;
|
258
|
395
|
|
396 for (i = 0; /* void */ ; i++) {
|
|
397
|
|
398 if (i >= part->nelts) {
|
|
399 if (part->next == NULL) {
|
|
400 break;
|
|
401 }
|
|
402 part = part->next;
|
272
|
403 shm_zone = part->elts;
|
258
|
404 i = 0;
|
|
405 }
|
|
406
|
272
|
407 if (shm_zone[i].shm.size == 0) {
|
|
408 ngx_log_error(NGX_LOG_EMERG, log, 0,
|
|
409 "zero size shared memory zone \"%V\"",
|
|
410 &shm_zone[i].name);
|
|
411 goto failed;
|
|
412 }
|
|
413
|
274
|
414 if (shm_zone[i].init == NULL) {
|
|
415 /* unused shared zone */
|
|
416 continue;
|
|
417 }
|
|
418
|
272
|
419 shm_zone[i].shm.log = cycle->log;
|
258
|
420
|
|
421 opart = &old_cycle->shared_memory.part;
|
272
|
422 oshm_zone = opart->elts;
|
258
|
423
|
|
424 for (n = 0; /* void */ ; n++) {
|
|
425
|
|
426 if (n >= opart->nelts) {
|
|
427 if (opart->next == NULL) {
|
|
428 break;
|
|
429 }
|
|
430 opart = opart->next;
|
272
|
431 oshm_zone = opart->elts;
|
258
|
432 n = 0;
|
|
433 }
|
|
434
|
272
|
435 if (shm_zone[i].name.len != oshm_zone[n].name.len) {
|
|
436 continue;
|
|
437 }
|
|
438
|
|
439 if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data,
|
|
440 shm_zone[i].name.len)
|
|
441 != 0)
|
|
442 {
|
258
|
443 continue;
|
|
444 }
|
|
445
|
272
|
446 if (shm_zone[i].shm.size == oshm_zone[n].shm.size) {
|
|
447 shm_zone[i].shm.addr = oshm_zone[n].shm.addr;
|
|
448
|
|
449 if (shm_zone[i].init(&shm_zone[i], oshm_zone[n].data)
|
|
450 != NGX_OK)
|
|
451 {
|
|
452 goto failed;
|
|
453 }
|
|
454
|
|
455 goto shm_zone_found;
|
258
|
456 }
|
|
457
|
272
|
458 ngx_shm_free(&oshm_zone[n].shm);
|
258
|
459
|
|
460 break;
|
|
461 }
|
|
462
|
272
|
463 if (ngx_shm_alloc(&shm_zone[i].shm) != NGX_OK) {
|
258
|
464 goto failed;
|
|
465 }
|
|
466
|
272
|
467 shpool = (ngx_slab_pool_t *) shm_zone[i].shm.addr;
|
258
|
468
|
272
|
469 shpool->end = shm_zone[i].shm.addr + shm_zone[i].shm.size;
|
258
|
470 shpool->min_shift = 3;
|
|
471
|
|
472 #if (NGX_HAVE_ATOMIC_OPS)
|
|
473
|
|
474 lock_file = NULL;
|
|
475
|
|
476 #else
|
|
477
|
382
|
478 lock_file = ngx_pnalloc(cycle->pool,
|
|
479 cycle->lock_file.len + shm_zone[i].name.len);
|
258
|
480
|
|
481 if (lock_file == NULL) {
|
|
482 goto failed;
|
|
483 }
|
|
484
|
|
485 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data,
|
|
486 cycle->lock_file.len),
|
272
|
487 shm_zone[i].name.data, shm_zone[i].name.len + 1);
|
258
|
488
|
|
489 #endif
|
|
490
|
|
491 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file)
|
|
492 != NGX_OK)
|
|
493 {
|
|
494 goto failed;
|
|
495 }
|
|
496
|
|
497 ngx_slab_init(shpool);
|
|
498
|
272
|
499 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {
|
|
500 goto failed;
|
|
501 }
|
|
502
|
|
503 shm_zone_found:
|
258
|
504
|
|
505 continue;
|
|
506 }
|
|
507
|
|
508
|
160
|
509 /* handle the listening sockets */
|
10
|
510
|
160
|
511 if (old_cycle->listening.nelts) {
|
|
512 ls = old_cycle->listening.elts;
|
|
513 for (i = 0; i < old_cycle->listening.nelts; i++) {
|
|
514 ls[i].remain = 0;
|
|
515 }
|
0
|
516
|
160
|
517 nls = cycle->listening.elts;
|
|
518 for (n = 0; n < cycle->listening.nelts; n++) {
|
10
|
519
|
160
|
520 for (i = 0; i < old_cycle->listening.nelts; i++) {
|
|
521 if (ls[i].ignore) {
|
|
522 continue;
|
|
523 }
|
0
|
524
|
160
|
525 if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr) == NGX_OK)
|
|
526 {
|
|
527 nls[n].fd = ls[i].fd;
|
|
528 nls[n].previous = &ls[i];
|
|
529 ls[i].remain = 1;
|
72
|
530
|
160
|
531 if (ls[n].backlog != nls[i].backlog) {
|
|
532 nls[n].listen = 1;
|
|
533 }
|
86
|
534
|
72
|
535 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
|
536
|
160
|
537 /*
|
|
538 * FreeBSD, except the most recent versions,
|
|
539 * could not remove accept filter
|
|
540 */
|
|
541 nls[n].deferred_accept = ls[i].deferred_accept;
|
72
|
542
|
160
|
543 if (ls[i].accept_filter && nls[n].accept_filter) {
|
|
544 if (ngx_strcmp(ls[i].accept_filter,
|
|
545 nls[n].accept_filter)
|
|
546 != 0)
|
|
547 {
|
72
|
548 nls[n].delete_deferred = 1;
|
|
549 nls[n].add_deferred = 1;
|
|
550 }
|
160
|
551
|
|
552 } else if (ls[i].accept_filter) {
|
|
553 nls[n].delete_deferred = 1;
|
|
554
|
|
555 } else if (nls[n].accept_filter) {
|
|
556 nls[n].add_deferred = 1;
|
|
557 }
|
72
|
558 #endif
|
|
559
|
|
560 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
561
|
160
|
562 if (ls[n].deferred_accept && !nls[n].deferred_accept) {
|
|
563 nls[n].delete_deferred = 1;
|
72
|
564
|
160
|
565 } else if (ls[i].deferred_accept != nls[n].deferred_accept)
|
|
566 {
|
|
567 nls[n].add_deferred = 1;
|
|
568 }
|
72
|
569 #endif
|
160
|
570 break;
|
0
|
571 }
|
|
572 }
|
|
573
|
160
|
574 if (nls[n].fd == -1) {
|
|
575 nls[n].open = 1;
|
0
|
576 }
|
|
577 }
|
|
578
|
160
|
579 } else {
|
|
580 ls = cycle->listening.elts;
|
|
581 for (i = 0; i < cycle->listening.nelts; i++) {
|
|
582 ls[i].open = 1;
|
|
583 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
|
584 if (ls[i].accept_filter) {
|
|
585 ls[i].add_deferred = 1;
|
0
|
586 }
|
160
|
587 #endif
|
|
588 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
589 if (ls[i].deferred_accept) {
|
|
590 ls[i].add_deferred = 1;
|
72
|
591 }
|
160
|
592 #endif
|
0
|
593 }
|
|
594 }
|
|
595
|
160
|
596 if (ngx_open_listening_sockets(cycle) != NGX_OK) {
|
|
597 goto failed;
|
|
598 }
|
0
|
599
|
160
|
600 if (!ngx_test_config) {
|
|
601 ngx_configure_listening_socket(cycle);
|
0
|
602 }
|
|
603
|
|
604
|
|
605 /* commit the new cycle configuration */
|
|
606
|
10
|
607 #if !(NGX_WIN32)
|
0
|
608
|
|
609 if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
|
|
610
|
|
611 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
|
10
|
612 "dup2: %p %d \"%s\"",
|
0
|
613 cycle->log->file,
|
|
614 cycle->log->file->fd, cycle->log->file->name.data);
|
|
615
|
160
|
616 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
|
0
|
617 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
618 "dup2(STDERR) failed");
|
|
619 /* fatal */
|
|
620 exit(1);
|
|
621 }
|
|
622 }
|
|
623
|
|
624 #endif
|
|
625
|
|
626 pool->log = cycle->log;
|
|
627
|
|
628 for (i = 0; ngx_modules[i]; i++) {
|
|
629 if (ngx_modules[i]->init_module) {
|
160
|
630 if (ngx_modules[i]->init_module(cycle) != NGX_OK) {
|
0
|
631 /* fatal */
|
|
632 exit(1);
|
|
633 }
|
|
634 }
|
|
635 }
|
|
636
|
16
|
637
|
0
|
638 /* close and delete stuff that lefts from an old cycle */
|
|
639
|
272
|
640 /* free the unnecessary shared memory */
|
|
641
|
|
642 opart = &old_cycle->shared_memory.part;
|
|
643 oshm_zone = opart->elts;
|
|
644
|
|
645 for (i = 0; /* void */ ; i++) {
|
|
646
|
|
647 if (i >= opart->nelts) {
|
|
648 if (opart->next == NULL) {
|
|
649 goto old_shm_zone_done;
|
|
650 }
|
|
651 opart = opart->next;
|
|
652 oshm_zone = opart->elts;
|
|
653 i = 0;
|
|
654 }
|
|
655
|
|
656 part = &cycle->shared_memory.part;
|
|
657 shm_zone = part->elts;
|
|
658
|
|
659 for (n = 0; /* void */ ; n++) {
|
|
660
|
|
661 if (n >= part->nelts) {
|
|
662 if (part->next == NULL) {
|
|
663 break;
|
|
664 }
|
|
665 part = part->next;
|
|
666 shm_zone = part->elts;
|
|
667 n = 0;
|
|
668 }
|
|
669
|
|
670 if (oshm_zone[i].name.len == shm_zone[n].name.len
|
|
671 && ngx_strncmp(oshm_zone[i].name.data,
|
|
672 shm_zone[n].name.data,
|
|
673 oshm_zone[i].name.len)
|
|
674 == 0)
|
|
675 {
|
|
676 goto live_shm_zone;
|
|
677 }
|
|
678 }
|
|
679
|
|
680 ngx_shm_free(&oshm_zone[i].shm);
|
|
681
|
|
682 live_shm_zone:
|
|
683
|
|
684 continue;
|
|
685 }
|
|
686
|
|
687 old_shm_zone_done:
|
|
688
|
|
689
|
|
690 /* close the unnecessary listening sockets */
|
0
|
691
|
|
692 ls = old_cycle->listening.elts;
|
|
693 for (i = 0; i < old_cycle->listening.nelts; i++) {
|
|
694 if (ls[i].remain) {
|
|
695 continue;
|
|
696 }
|
|
697
|
|
698 if (ngx_close_socket(ls[i].fd) == -1) {
|
|
699 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
92
|
700 ngx_close_socket_n " listening socket on %V failed",
|
10
|
701 &ls[i].addr_text);
|
0
|
702 }
|
|
703 }
|
|
704
|
|
705
|
272
|
706 /* close the unnecessary open files */
|
0
|
707
|
|
708 part = &old_cycle->open_files.part;
|
|
709 file = part->elts;
|
|
710
|
|
711 for (i = 0; /* void */ ; i++) {
|
|
712
|
|
713 if (i >= part->nelts) {
|
|
714 if (part->next == NULL) {
|
|
715 break;
|
|
716 }
|
|
717 part = part->next;
|
|
718 file = part->elts;
|
|
719 i = 0;
|
|
720 }
|
|
721
|
|
722 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) {
|
|
723 continue;
|
|
724 }
|
|
725
|
|
726 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
|
727 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
728 ngx_close_file_n " \"%s\" failed",
|
|
729 file[i].name.data);
|
|
730 }
|
|
731 }
|
|
732
|
142
|
733 ngx_destroy_pool(conf.temp_pool);
|
|
734
|
154
|
735 if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
|
|
736
|
356
|
737 /*
|
|
738 * perl_destruct() frees environ if it is not the same as it was at
|
|
739 * perl_construct() time. So we have saved an previous cycle
|
|
740 * environment before ngx_conf_parse() where it will be changed.
|
|
741 */
|
|
742
|
|
743 env = environ;
|
|
744 environ = senv;
|
|
745
|
0
|
746 ngx_destroy_pool(old_cycle->pool);
|
160
|
747 cycle->old_cycle = NULL;
|
|
748
|
356
|
749 environ = env;
|
|
750
|
0
|
751 return cycle;
|
|
752 }
|
|
753
|
|
754
|
|
755 if (ngx_temp_pool == NULL) {
|
|
756 ngx_temp_pool = ngx_create_pool(128, cycle->log);
|
|
757 if (ngx_temp_pool == NULL) {
|
|
758 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
|
|
759 "can not create ngx_temp_pool");
|
|
760 exit(1);
|
|
761 }
|
|
762
|
|
763 n = 10;
|
|
764 ngx_old_cycles.elts = ngx_pcalloc(ngx_temp_pool,
|
|
765 n * sizeof(ngx_cycle_t *));
|
|
766 if (ngx_old_cycles.elts == NULL) {
|
|
767 exit(1);
|
|
768 }
|
|
769 ngx_old_cycles.nelts = 0;
|
|
770 ngx_old_cycles.size = sizeof(ngx_cycle_t *);
|
|
771 ngx_old_cycles.nalloc = n;
|
|
772 ngx_old_cycles.pool = ngx_temp_pool;
|
|
773
|
58
|
774 ngx_cleaner_event.handler = ngx_clean_old_cycles;
|
0
|
775 ngx_cleaner_event.log = cycle->log;
|
|
776 ngx_cleaner_event.data = &dumb;
|
|
777 dumb.fd = (ngx_socket_t) -1;
|
|
778 }
|
|
779
|
|
780 ngx_temp_pool->log = cycle->log;
|
|
781
|
50
|
782 old = ngx_array_push(&ngx_old_cycles);
|
0
|
783 if (old == NULL) {
|
|
784 exit(1);
|
|
785 }
|
|
786 *old = old_cycle;
|
|
787
|
|
788 if (!ngx_cleaner_event.timer_set) {
|
|
789 ngx_add_timer(&ngx_cleaner_event, 30000);
|
|
790 ngx_cleaner_event.timer_set = 1;
|
|
791 }
|
|
792
|
|
793 return cycle;
|
160
|
794
|
|
795
|
|
796 failed:
|
|
797
|
296
|
798 if (!ngx_is_init_cycle(old_cycle)) {
|
|
799 old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx,
|
|
800 ngx_core_module);
|
|
801 if (old_ccf->environment) {
|
|
802 environ = old_ccf->environment;
|
|
803 }
|
|
804 }
|
|
805
|
160
|
806 /* rollback the new cycle configuration */
|
|
807
|
|
808 part = &cycle->open_files.part;
|
|
809 file = part->elts;
|
|
810
|
|
811 for (i = 0; /* void */ ; i++) {
|
|
812
|
|
813 if (i >= part->nelts) {
|
|
814 if (part->next == NULL) {
|
|
815 break;
|
|
816 }
|
|
817 part = part->next;
|
|
818 file = part->elts;
|
|
819 i = 0;
|
|
820 }
|
|
821
|
|
822 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) {
|
|
823 continue;
|
|
824 }
|
|
825
|
|
826 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
|
827 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
828 ngx_close_file_n " \"%s\" failed",
|
|
829 file[i].name.data);
|
|
830 }
|
|
831 }
|
|
832
|
|
833 if (ngx_test_config) {
|
|
834 ngx_destroy_cycle_pools(&conf);
|
|
835 return NULL;
|
|
836 }
|
|
837
|
|
838 ls = cycle->listening.elts;
|
|
839 for (i = 0; i < cycle->listening.nelts; i++) {
|
|
840 if (ls[i].fd == -1 || !ls[i].open) {
|
|
841 continue;
|
|
842 }
|
|
843
|
|
844 if (ngx_close_socket(ls[i].fd) == -1) {
|
|
845 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
|
846 ngx_close_socket_n " %V failed",
|
|
847 &ls[i].addr_text);
|
|
848 }
|
|
849 }
|
|
850
|
|
851 ngx_destroy_cycle_pools(&conf);
|
|
852
|
|
853 return NULL;
|
0
|
854 }
|
|
855
|
|
856
|
154
|
857 static void
|
|
858 ngx_destroy_cycle_pools(ngx_conf_t *conf)
|
|
859 {
|
|
860 ngx_destroy_pool(conf->temp_pool);
|
|
861 ngx_destroy_pool(conf->pool);
|
|
862 }
|
|
863
|
|
864
|
112
|
865 static ngx_int_t
|
|
866 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2)
|
10
|
867 {
|
|
868 struct sockaddr_in *sin1, *sin2;
|
|
869
|
|
870 /* AF_INET only */
|
|
871
|
28
|
872 if (sa1->sa_family != AF_INET || sa2->sa_family != AF_INET) {
|
10
|
873 return NGX_DECLINED;
|
|
874 }
|
|
875
|
28
|
876 sin1 = (struct sockaddr_in *) sa1;
|
|
877 sin2 = (struct sockaddr_in *) sa2;
|
10
|
878
|
|
879 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) {
|
|
880 return NGX_DECLINED;
|
|
881 }
|
|
882
|
|
883 if (sin1->sin_port != sin2->sin_port) {
|
|
884 return NGX_DECLINED;
|
|
885 }
|
|
886
|
|
887 return NGX_OK;
|
|
888 }
|
|
889
|
|
890
|
|
891 #if !(NGX_WIN32)
|
0
|
892
|
112
|
893 ngx_int_t
|
160
|
894 ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log)
|
0
|
895 {
|
160
|
896 size_t len;
|
0
|
897 ngx_uint_t trunc;
|
|
898 ngx_file_t file;
|
270
|
899 u_char pid[NGX_INT64_LEN + 2];
|
0
|
900
|
|
901 ngx_memzero(&file, sizeof(ngx_file_t));
|
92
|
902
|
160
|
903 file.name = *name;
|
|
904 file.log = log;
|
0
|
905
|
160
|
906 trunc = ngx_test_config ? 0 : NGX_FILE_TRUNCATE;
|
0
|
907
|
|
908 file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR,
|
276
|
909 NGX_FILE_CREATE_OR_OPEN|trunc,
|
|
910 NGX_FILE_DEFAULT_ACCESS);
|
0
|
911
|
|
912 if (file.fd == NGX_INVALID_FILE) {
|
160
|
913 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
0
|
914 ngx_open_file_n " \"%s\" failed", file.name.data);
|
|
915 return NGX_ERROR;
|
|
916 }
|
|
917
|
|
918 if (!ngx_test_config) {
|
270
|
919 len = ngx_snprintf(pid, NGX_INT64_LEN + 2, "%P%N", ngx_pid) - pid;
|
10
|
920
|
0
|
921 if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
|
|
922 return NGX_ERROR;
|
|
923 }
|
|
924 }
|
|
925
|
|
926 if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
|
160
|
927 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
0
|
928 ngx_close_file_n " \"%s\" failed", file.name.data);
|
|
929 }
|
|
930
|
|
931 return NGX_OK;
|
|
932 }
|
|
933
|
|
934
|
112
|
935 void
|
|
936 ngx_delete_pidfile(ngx_cycle_t *cycle)
|
126
|
937 {
|
0
|
938 u_char *name;
|
|
939 ngx_core_conf_t *ccf;
|
|
940
|
|
941 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
|
|
942
|
92
|
943 name = ngx_new_binary ? ccf->oldpid.data : ccf->pid.data;
|
0
|
944
|
|
945 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
|
|
946 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
947 ngx_delete_file_n " \"%s\" failed", name);
|
|
948 }
|
|
949 }
|
|
950
|
|
951 #endif
|
|
952
|
|
953
|
160
|
954 static ngx_int_t
|
|
955 ngx_test_lockfile(u_char *file, ngx_log_t *log)
|
|
956 {
|
|
957 #if !(NGX_HAVE_ATOMIC_OPS)
|
|
958 ngx_fd_t fd;
|
|
959
|
284
|
960 fd = ngx_open_file(file, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN,
|
|
961 NGX_FILE_DEFAULT_ACCESS);
|
160
|
962
|
|
963 if (fd == NGX_INVALID_FILE) {
|
|
964 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
|
965 ngx_open_file_n " \"%s\" failed", file);
|
|
966 return NGX_ERROR;
|
|
967 }
|
|
968
|
|
969 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
970 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
|
971 ngx_close_file_n " \"%s\" failed", file);
|
|
972 }
|
|
973
|
|
974 if (ngx_delete_file(file) == NGX_FILE_ERROR) {
|
|
975 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
|
976 ngx_delete_file_n " \"%s\" failed", file);
|
|
977 }
|
|
978
|
|
979 #endif
|
|
980
|
|
981 return NGX_OK;
|
|
982 }
|
|
983
|
|
984
|
112
|
985 void
|
|
986 ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
|
0
|
987 {
|
|
988 ngx_fd_t fd;
|
|
989 ngx_uint_t i;
|
|
990 ngx_list_part_t *part;
|
|
991 ngx_open_file_t *file;
|
|
992
|
|
993 part = &cycle->open_files.part;
|
|
994 file = part->elts;
|
|
995
|
|
996 for (i = 0; /* void */ ; i++) {
|
|
997
|
|
998 if (i >= part->nelts) {
|
|
999 if (part->next == NULL) {
|
|
1000 break;
|
|
1001 }
|
|
1002 part = part->next;
|
72
|
1003 file = part->elts;
|
0
|
1004 i = 0;
|
|
1005 }
|
|
1006
|
|
1007 if (file[i].name.data == NULL) {
|
|
1008 continue;
|
|
1009 }
|
|
1010
|
120
|
1011 if (file[i].buffer && file[i].pos - file[i].buffer != 0) {
|
|
1012 ngx_write_fd(file[i].fd, file[i].buffer,
|
|
1013 file[i].pos - file[i].buffer);
|
|
1014 file[i].pos = file[i].buffer;
|
|
1015 }
|
|
1016
|
0
|
1017 fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,
|
276
|
1018 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND,
|
|
1019 NGX_FILE_DEFAULT_ACCESS);
|
0
|
1020
|
|
1021 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
1022 "reopen file \"%s\", old:%d new:%d",
|
|
1023 file[i].name.data, file[i].fd, fd);
|
|
1024
|
|
1025 if (fd == NGX_INVALID_FILE) {
|
|
1026 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1027 ngx_open_file_n " \"%s\" failed", file[i].name.data);
|
|
1028 continue;
|
|
1029 }
|
|
1030
|
10
|
1031 #if (NGX_WIN32)
|
0
|
1032 if (ngx_file_append_mode(fd) == NGX_ERROR) {
|
|
1033 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1034 ngx_file_append_mode_n " \"%s\" failed",
|
|
1035 file[i].name.data);
|
|
1036
|
|
1037 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
1038 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1039 ngx_close_file_n " \"%s\" failed",
|
|
1040 file[i].name.data);
|
|
1041 }
|
|
1042
|
|
1043 continue;
|
|
1044 }
|
|
1045 #else
|
66
|
1046 if (user != (ngx_uid_t) NGX_CONF_UNSET_UINT) {
|
356
|
1047 ngx_file_info_t fi;
|
2
|
1048
|
|
1049 if (ngx_file_info((const char *) file[i].name.data, &fi) == -1) {
|
|
1050 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1051 ngx_file_info_n " \"%s\" failed",
|
|
1052 file[i].name.data);
|
|
1053
|
|
1054 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
1055 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1056 ngx_close_file_n " \"%s\" failed",
|
|
1057 file[i].name.data);
|
|
1058 }
|
|
1059 }
|
|
1060
|
16
|
1061 if (fi.st_uid != user) {
|
|
1062 if (chown((const char *) file[i].name.data, user, -1) == -1) {
|
|
1063 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1064 "chown(\"%s\", %d) failed",
|
|
1065 file[i].name.data, user);
|
|
1066
|
|
1067 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
1068 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1069 ngx_close_file_n " \"%s\" failed",
|
|
1070 file[i].name.data);
|
|
1071 }
|
|
1072 }
|
|
1073 }
|
|
1074
|
2
|
1075 if ((fi.st_mode & (S_IRUSR|S_IWUSR)) != (S_IRUSR|S_IWUSR)) {
|
|
1076
|
|
1077 fi.st_mode |= (S_IRUSR|S_IWUSR);
|
|
1078
|
|
1079 if (chmod((const char *) file[i].name.data, fi.st_mode) == -1) {
|
|
1080 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
16
|
1081 "chmod() \"%s\" failed", file[i].name.data);
|
2
|
1082
|
|
1083 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
1084 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1085 ngx_close_file_n " \"%s\" failed",
|
|
1086 file[i].name.data);
|
|
1087 }
|
|
1088 }
|
|
1089 }
|
0
|
1090 }
|
|
1091
|
|
1092 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
|
1093 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1094 "fcntl(FD_CLOEXEC) \"%s\" failed",
|
|
1095 file[i].name.data);
|
|
1096
|
|
1097 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
1098 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1099 ngx_close_file_n " \"%s\" failed",
|
|
1100 file[i].name.data);
|
|
1101 }
|
|
1102
|
|
1103 continue;
|
|
1104 }
|
|
1105 #endif
|
|
1106
|
|
1107 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
|
1108 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1109 ngx_close_file_n " \"%s\" failed",
|
|
1110 file[i].name.data);
|
|
1111 }
|
|
1112
|
|
1113 file[i].fd = fd;
|
|
1114 }
|
|
1115
|
10
|
1116 #if !(NGX_WIN32)
|
0
|
1117
|
|
1118 if (cycle->log->file->fd != STDERR_FILENO) {
|
|
1119 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
|
|
1120 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
1121 "dup2(STDERR) failed");
|
|
1122 }
|
|
1123 }
|
|
1124
|
|
1125 #endif
|
|
1126 }
|
|
1127
|
|
1128
|
272
|
1129 ngx_shm_zone_t *
|
|
1130 ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size, void *tag)
|
|
1131 {
|
|
1132 ngx_uint_t i;
|
|
1133 ngx_shm_zone_t *shm_zone;
|
|
1134 ngx_list_part_t *part;
|
|
1135
|
|
1136 part = &cf->cycle->shared_memory.part;
|
|
1137 shm_zone = part->elts;
|
|
1138
|
|
1139 for (i = 0; /* void */ ; i++) {
|
|
1140
|
|
1141 if (i >= part->nelts) {
|
|
1142 if (part->next == NULL) {
|
|
1143 break;
|
|
1144 }
|
|
1145 part = part->next;
|
|
1146 shm_zone = part->elts;
|
|
1147 i = 0;
|
|
1148 }
|
|
1149
|
|
1150 if (name->len != shm_zone[i].name.len) {
|
|
1151 continue;
|
|
1152 }
|
|
1153
|
|
1154 if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) {
|
|
1155 continue;
|
|
1156 }
|
|
1157
|
|
1158 if (size && size != shm_zone[i].shm.size) {
|
|
1159 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1160 "the size %uz of shared memory zone \"%V\" "
|
|
1161 "conflicts with already declared size %uz",
|
|
1162 size, &shm_zone[i].name, shm_zone[i].shm.size);
|
|
1163 return NULL;
|
|
1164 }
|
|
1165
|
|
1166 if (tag != shm_zone[i].tag) {
|
|
1167 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1168 "the shared memory zone \"%V\" is "
|
|
1169 "already declared for a different use",
|
|
1170 &shm_zone[i].name);
|
|
1171 return NULL;
|
|
1172 }
|
|
1173
|
|
1174 return &shm_zone[i];
|
|
1175 }
|
|
1176
|
|
1177 shm_zone = ngx_list_push(&cf->cycle->shared_memory);
|
|
1178
|
|
1179 if (shm_zone == NULL) {
|
|
1180 return NULL;
|
|
1181 }
|
|
1182
|
|
1183 shm_zone->data = NULL;
|
|
1184 shm_zone->shm.log = cf->cycle->log;
|
|
1185 shm_zone->shm.size = size;
|
|
1186 shm_zone->init = NULL;
|
|
1187 shm_zone->name = *name;
|
|
1188 shm_zone->tag = tag;
|
|
1189
|
|
1190 return shm_zone;
|
|
1191 }
|
|
1192
|
|
1193
|
112
|
1194 static void
|
|
1195 ngx_clean_old_cycles(ngx_event_t *ev)
|
0
|
1196 {
|
|
1197 ngx_uint_t i, n, found, live;
|
|
1198 ngx_log_t *log;
|
|
1199 ngx_cycle_t **cycle;
|
|
1200
|
|
1201 log = ngx_cycle->log;
|
|
1202 ngx_temp_pool->log = log;
|
|
1203
|
|
1204 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "clean old cycles");
|
|
1205
|
|
1206 live = 0;
|
|
1207
|
|
1208 cycle = ngx_old_cycles.elts;
|
|
1209 for (i = 0; i < ngx_old_cycles.nelts; i++) {
|
|
1210
|
|
1211 if (cycle[i] == NULL) {
|
|
1212 continue;
|
|
1213 }
|
|
1214
|
|
1215 found = 0;
|
|
1216
|
|
1217 for (n = 0; n < cycle[i]->connection_n; n++) {
|
110
|
1218 if (cycle[i]->connections[n].fd != (ngx_socket_t) -1) {
|
0
|
1219 found = 1;
|
|
1220
|
|
1221 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "live fd:%d", n);
|
|
1222
|
|
1223 break;
|
|
1224 }
|
|
1225 }
|
|
1226
|
|
1227 if (found) {
|
|
1228 live = 1;
|
|
1229 continue;
|
|
1230 }
|
|
1231
|
|
1232 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "clean old cycle: %d", i);
|
|
1233
|
|
1234 ngx_destroy_pool(cycle[i]->pool);
|
|
1235 cycle[i] = NULL;
|
|
1236 }
|
|
1237
|
|
1238 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "old cycles status: %d", live);
|
|
1239
|
|
1240 if (live) {
|
|
1241 ngx_add_timer(ev, 30000);
|
|
1242
|
|
1243 } else {
|
|
1244 ngx_destroy_pool(ngx_temp_pool);
|
|
1245 ngx_temp_pool = NULL;
|
|
1246 ngx_old_cycles.nelts = 0;
|
|
1247 }
|
|
1248 }
|