Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 1 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 7 | #include <ngx_config.h> |
| 8 | #include <ngx_core.h> |
| 9 | #include <ngx_event.h> |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | static void ngx_clean_old_cycles(ngx_event_t *ev); |
| 13 | |
| 14 | |
| 15 | volatile ngx_cycle_t *ngx_cycle; |
| 16 | ngx_array_t ngx_old_cycles; |
| 17 | |
| 18 | static ngx_pool_t *ngx_temp_pool; |
| 19 | static ngx_event_t ngx_cleaner_event; |
| 20 | |
Igor Sysoev | 630ad0c | 2004-04-16 05:14:16 +0000 | [diff] [blame] | 21 | ngx_uint_t ngx_test_config; |
| 22 | |
Igor Sysoev | 2b97993 | 2004-07-07 15:01:00 +0000 | [diff] [blame] | 23 | #if (NGX_THREADS) |
| 24 | ngx_tls_key_t ngx_core_tls_key; |
| 25 | #endif |
| 26 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 27 | |
| 28 | /* STUB NAME */ |
| 29 | static ngx_connection_t dumb; |
| 30 | /* STUB */ |
| 31 | |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 32 | #ifdef NGX_ERROR_LOG_PATH |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 33 | static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH); |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 34 | #else |
| 35 | static ngx_str_t error_log = ngx_null_string; |
| 36 | #endif |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 37 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 38 | |
| 39 | ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) |
| 40 | { |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 41 | void *rv; |
| 42 | ngx_uint_t i, n, failed; |
Igor Sysoev | 68df19d | 2004-04-15 15:34:36 +0000 | [diff] [blame] | 43 | ngx_log_t *log; |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 44 | ngx_conf_t conf; |
| 45 | ngx_pool_t *pool; |
| 46 | ngx_cycle_t *cycle, **old; |
| 47 | ngx_socket_t fd; |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 48 | ngx_list_part_t *part; |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 49 | ngx_open_file_t *file; |
| 50 | ngx_listening_t *ls, *nls; |
| 51 | ngx_core_module_t *module; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 52 | |
| 53 | log = old_cycle->log; |
| 54 | |
| 55 | if (!(pool = ngx_create_pool(16 * 1024, log))) { |
| 56 | return NULL; |
| 57 | } |
Igor Sysoev | 68df19d | 2004-04-15 15:34:36 +0000 | [diff] [blame] | 58 | pool->log = log; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 59 | |
| 60 | if (!(cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t)))) { |
| 61 | ngx_destroy_pool(pool); |
| 62 | return NULL; |
| 63 | } |
| 64 | cycle->pool = pool; |
Igor Sysoev | cccc552 | 2004-04-14 20:34:05 +0000 | [diff] [blame] | 65 | cycle->log = log; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 66 | cycle->old_cycle = old_cycle; |
Igor Sysoev | e9b2cb1 | 2004-02-09 20:47:18 +0000 | [diff] [blame] | 67 | cycle->conf_file = old_cycle->conf_file; |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 68 | cycle->root.len = sizeof(NGX_PREFIX) - 1; |
| 69 | cycle->root.data = (u_char *) NGX_PREFIX; |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 70 | |
| 71 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 72 | n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; |
| 73 | if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) { |
| 74 | ngx_destroy_pool(pool); |
| 75 | return NULL; |
| 76 | } |
| 77 | cycle->pathes.nelts = 0; |
| 78 | cycle->pathes.size = sizeof(ngx_path_t *); |
| 79 | cycle->pathes.nalloc = n; |
| 80 | cycle->pathes.pool = pool; |
| 81 | |
| 82 | |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 83 | if (old_cycle->open_files.part.nelts) { |
| 84 | n = old_cycle->open_files.part.nelts; |
| 85 | for (part = old_cycle->open_files.part.next; part; part = part->next) { |
| 86 | n += part->nelts; |
| 87 | } |
| 88 | |
| 89 | } else { |
| 90 | n = 20; |
| 91 | } |
| 92 | |
Igor Sysoev | aab4d8c | 2004-09-06 18:45:00 +0000 | [diff] [blame] | 93 | if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t)) |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 94 | == NGX_ERROR) |
| 95 | { |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 96 | ngx_destroy_pool(pool); |
| 97 | return NULL; |
| 98 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 99 | |
| 100 | |
Igor Sysoev | 68df19d | 2004-04-15 15:34:36 +0000 | [diff] [blame] | 101 | if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 102 | ngx_destroy_pool(pool); |
| 103 | return NULL; |
| 104 | } |
| 105 | |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 106 | cycle->new_log->file->name = error_log; |
| 107 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 108 | |
| 109 | n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10; |
| 110 | cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); |
| 111 | if (cycle->listening.elts == NULL) { |
| 112 | ngx_destroy_pool(pool); |
| 113 | return NULL; |
| 114 | } |
| 115 | cycle->listening.nelts = 0; |
| 116 | cycle->listening.size = sizeof(ngx_listening_t); |
| 117 | cycle->listening.nalloc = n; |
| 118 | cycle->listening.pool = pool; |
| 119 | |
| 120 | |
| 121 | cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *)); |
| 122 | if (cycle->conf_ctx == NULL) { |
| 123 | ngx_destroy_pool(pool); |
| 124 | return NULL; |
| 125 | } |
| 126 | |
| 127 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 128 | for (i = 0; ngx_modules[i]; i++) { |
| 129 | if (ngx_modules[i]->type != NGX_CORE_MODULE) { |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | module = ngx_modules[i]->ctx; |
| 134 | |
| 135 | if (module->create_conf) { |
| 136 | rv = module->create_conf(cycle); |
| 137 | if (rv == NGX_CONF_ERROR) { |
| 138 | ngx_destroy_pool(pool); |
| 139 | return NULL; |
| 140 | } |
| 141 | cycle->conf_ctx[ngx_modules[i]->index] = rv; |
| 142 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
| 146 | ngx_memzero(&conf, sizeof(ngx_conf_t)); |
| 147 | /* STUB: init array ? */ |
| 148 | conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t)); |
| 149 | if (conf.args == NULL) { |
| 150 | ngx_destroy_pool(pool); |
| 151 | return NULL; |
| 152 | } |
| 153 | |
| 154 | conf.ctx = cycle->conf_ctx; |
| 155 | conf.cycle = cycle; |
Igor Sysoev | 68df19d | 2004-04-15 15:34:36 +0000 | [diff] [blame] | 156 | conf.pool = pool; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 157 | conf.log = log; |
| 158 | conf.module_type = NGX_CORE_MODULE; |
| 159 | conf.cmd_type = NGX_MAIN_CONF; |
| 160 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 161 | |
Igor Sysoev | e9b2cb1 | 2004-02-09 20:47:18 +0000 | [diff] [blame] | 162 | if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 163 | ngx_destroy_pool(pool); |
| 164 | return NULL; |
| 165 | } |
| 166 | |
Igor Sysoev | 9bfb434 | 2004-04-18 19:06:02 +0000 | [diff] [blame] | 167 | if (ngx_test_config) { |
| 168 | ngx_log_error(NGX_LOG_INFO, log, 0, |
| 169 | "the configuration file %s syntax is ok", |
| 170 | cycle->conf_file.data); |
| 171 | } |
| 172 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 173 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 174 | for (i = 0; ngx_modules[i]; i++) { |
| 175 | if (ngx_modules[i]->type != NGX_CORE_MODULE) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 176 | continue; |
| 177 | } |
| 178 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 179 | module = ngx_modules[i]->ctx; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 180 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 181 | if (module->init_conf) { |
| 182 | if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index]) |
| 183 | == NGX_CONF_ERROR) |
| 184 | { |
| 185 | ngx_destroy_pool(pool); |
| 186 | return NULL; |
| 187 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 188 | } |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
| 192 | failed = 0; |
| 193 | |
| 194 | |
| 195 | #if !(WIN32) |
| 196 | if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { |
| 197 | failed = 1; |
| 198 | } |
| 199 | #endif |
| 200 | |
| 201 | |
| 202 | if (!failed) { |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 203 | |
| 204 | part = &cycle->open_files.part; |
| 205 | file = part->elts; |
| 206 | |
| 207 | for (i = 0; /* void */ ; i++) { |
| 208 | |
| 209 | if (i >= part->nelts) { |
| 210 | if (part->next == NULL) { |
| 211 | break; |
| 212 | } |
| 213 | part = part->next; |
| 214 | file = part->elts; |
| 215 | i = 0; |
| 216 | } |
| 217 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 218 | if (file[i].name.data == NULL) { |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | file[i].fd = ngx_open_file(file[i].name.data, |
| 223 | NGX_FILE_RDWR, |
| 224 | NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); |
| 225 | |
Igor Sysoev | 8035fd2 | 2004-10-01 15:53:53 +0000 | [diff] [blame] | 226 | #if 0 |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 227 | log->log_level = NGX_LOG_DEBUG_ALL; |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 228 | #endif |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 229 | ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, |
| 230 | "log: %0X %d \"%s\"", |
| 231 | &file[i], file[i].fd, file[i].name.data); |
| 232 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 233 | if (file[i].fd == NGX_INVALID_FILE) { |
| 234 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 235 | ngx_open_file_n " \"%s\" failed", |
| 236 | file[i].name.data); |
| 237 | failed = 1; |
| 238 | break; |
| 239 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 240 | |
| 241 | #if (WIN32) |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 242 | if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { |
| 243 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 244 | ngx_file_append_mode_n " \"%s\" failed", |
| 245 | file[i].name.data); |
| 246 | failed = 1; |
| 247 | break; |
| 248 | } |
Igor Sysoev | 0911f77 | 2004-01-14 18:19:42 +0000 | [diff] [blame] | 249 | #else |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 250 | if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) { |
| 251 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 252 | "fcntl(FD_CLOEXEC) \"%s\" failed", |
| 253 | file[i].name.data); |
| 254 | failed = 1; |
| 255 | break; |
| 256 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 257 | #endif |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 258 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Igor Sysoev | 68df19d | 2004-04-15 15:34:36 +0000 | [diff] [blame] | 261 | cycle->log = cycle->new_log; |
| 262 | pool->log = cycle->new_log; |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 263 | |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 264 | if (cycle->log->log_level == 0) { |
| 265 | cycle->log->log_level = NGX_LOG_ERR; |
| 266 | } |
| 267 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 268 | if (!failed) { |
| 269 | if (old_cycle->listening.nelts) { |
| 270 | ls = old_cycle->listening.elts; |
| 271 | for (i = 0; i < old_cycle->listening.nelts; i++) { |
| 272 | ls[i].remain = 0; |
| 273 | } |
| 274 | |
| 275 | nls = cycle->listening.elts; |
| 276 | for (n = 0; n < cycle->listening.nelts; n++) { |
| 277 | for (i = 0; i < old_cycle->listening.nelts; i++) { |
| 278 | if (ls[i].ignore) { |
| 279 | continue; |
| 280 | } |
| 281 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 282 | if (ngx_memcmp(nls[n].sockaddr, |
| 283 | ls[i].sockaddr, ls[i].socklen) == 0) |
| 284 | { |
| 285 | fd = ls[i].fd; |
| 286 | #if (WIN32) |
| 287 | /* |
| 288 | * Winsock assignes a socket number divisible by 4 so |
| 289 | * to find a connection we divide a socket number by 4. |
| 290 | */ |
| 291 | |
| 292 | fd /= 4; |
| 293 | #endif |
| 294 | if (fd >= (ngx_socket_t) cycle->connection_n) { |
| 295 | ngx_log_error(NGX_LOG_EMERG, log, 0, |
| 296 | "%d connections is not enough to hold " |
| 297 | "an open listening socket on %s, " |
| 298 | "required at least %d connections", |
| 299 | cycle->connection_n, |
| 300 | ls[i].addr_text.data, fd); |
| 301 | failed = 1; |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | nls[n].fd = ls[i].fd; |
| 306 | nls[i].remain = 1; |
| 307 | ls[i].remain = 1; |
| 308 | break; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (nls[n].fd == -1) { |
| 313 | nls[n].new = 1; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | } else { |
| 318 | ls = cycle->listening.elts; |
| 319 | for (i = 0; i < cycle->listening.nelts; i++) { |
| 320 | ls[i].new = 1; |
| 321 | } |
| 322 | } |
| 323 | |
Igor Sysoev | 630ad0c | 2004-04-16 05:14:16 +0000 | [diff] [blame] | 324 | if (!ngx_test_config && !failed) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 325 | if (ngx_open_listening_sockets(cycle) == NGX_ERROR) { |
| 326 | failed = 1; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | if (failed) { |
| 332 | |
| 333 | /* rollback the new cycle configuration */ |
| 334 | |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 335 | part = &cycle->open_files.part; |
| 336 | file = part->elts; |
| 337 | |
| 338 | for (i = 0; /* void */ ; i++) { |
| 339 | |
| 340 | if (i >= part->nelts) { |
| 341 | if (part->next == NULL) { |
| 342 | break; |
| 343 | } |
| 344 | part = part->next; |
| 345 | file = part->elts; |
| 346 | i = 0; |
| 347 | } |
| 348 | |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 349 | if (file[i].fd == NGX_INVALID_FILE |
| 350 | || file[i].fd == ngx_stderr_fileno) |
| 351 | { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 352 | continue; |
| 353 | } |
| 354 | |
| 355 | if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { |
| 356 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 357 | ngx_close_file_n " \"%s\" failed", |
| 358 | file[i].name.data); |
| 359 | } |
| 360 | } |
| 361 | |
Igor Sysoev | 9bfb434 | 2004-04-18 19:06:02 +0000 | [diff] [blame] | 362 | if (ngx_test_config) { |
| 363 | ngx_destroy_pool(pool); |
| 364 | return NULL; |
| 365 | } |
| 366 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 367 | ls = cycle->listening.elts; |
| 368 | for (i = 0; i < cycle->listening.nelts; i++) { |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 369 | if (ls[i].fd == -1 || !ls[i].new) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 370 | continue; |
| 371 | } |
| 372 | |
| 373 | if (ngx_close_socket(ls[i].fd) == -1) { |
| 374 | ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
| 375 | ngx_close_socket_n " %s failed", |
| 376 | ls[i].addr_text.data); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | ngx_destroy_pool(pool); |
| 381 | return NULL; |
| 382 | } |
| 383 | |
Igor Sysoev | 25b36fe | 2004-02-03 16:43:54 +0000 | [diff] [blame] | 384 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 385 | /* commit the new cycle configuration */ |
| 386 | |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 387 | #if !(WIN32) |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 388 | |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 389 | if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { |
| 390 | |
| 391 | ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, |
| 392 | "dup2: %0X %d \"%s\"", |
| 393 | cycle->log->file, |
| 394 | cycle->log->file->fd, cycle->log->file->name.data); |
| 395 | |
| 396 | if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { |
| 397 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 398 | "dup2(STDERR) failed"); |
| 399 | /* fatal */ |
| 400 | exit(1); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | #endif |
| 405 | |
| 406 | pool->log = cycle->log; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 407 | |
| 408 | for (i = 0; ngx_modules[i]; i++) { |
| 409 | if (ngx_modules[i]->init_module) { |
| 410 | if (ngx_modules[i]->init_module(cycle) == NGX_ERROR) { |
| 411 | /* fatal */ |
| 412 | exit(1); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /* close and delete stuff that lefts from an old cycle */ |
| 418 | |
| 419 | /* close the unneeded listening sockets */ |
| 420 | |
| 421 | ls = old_cycle->listening.elts; |
| 422 | for (i = 0; i < old_cycle->listening.nelts; i++) { |
| 423 | if (ls[i].remain) { |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | if (ngx_close_socket(ls[i].fd) == -1) { |
| 428 | ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
| 429 | ngx_close_socket_n " %s failed", |
| 430 | ls[i].addr_text.data); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | |
| 435 | /* close the unneeded open files */ |
| 436 | |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 437 | part = &old_cycle->open_files.part; |
| 438 | file = part->elts; |
| 439 | |
| 440 | for (i = 0; /* void */ ; i++) { |
| 441 | |
| 442 | if (i >= part->nelts) { |
| 443 | if (part->next == NULL) { |
| 444 | break; |
| 445 | } |
| 446 | part = part->next; |
| 447 | file = part->elts; |
| 448 | i = 0; |
| 449 | } |
| 450 | |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 451 | if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 452 | continue; |
| 453 | } |
| 454 | |
| 455 | if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { |
| 456 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| 457 | ngx_close_file_n " \"%s\" failed", |
| 458 | file[i].name.data); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | if (old_cycle->connections == NULL) { |
| 463 | /* an old cycle is an init cycle */ |
| 464 | ngx_destroy_pool(old_cycle->pool); |
| 465 | return cycle; |
| 466 | } |
| 467 | |
Igor Sysoev | 3d58f8c | 2004-01-08 08:47:17 +0000 | [diff] [blame] | 468 | if (ngx_process == NGX_PROCESS_MASTER) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 469 | ngx_destroy_pool(old_cycle->pool); |
| 470 | return cycle; |
| 471 | } |
| 472 | |
| 473 | if (ngx_temp_pool == NULL) { |
| 474 | ngx_temp_pool = ngx_create_pool(128, cycle->log); |
| 475 | if (ngx_temp_pool == NULL) { |
| 476 | ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
| 477 | "can not create ngx_temp_pool"); |
| 478 | exit(1); |
| 479 | } |
| 480 | |
| 481 | n = 10; |
| 482 | ngx_old_cycles.elts = ngx_pcalloc(ngx_temp_pool, |
| 483 | n * sizeof(ngx_cycle_t *)); |
| 484 | if (ngx_old_cycles.elts == NULL) { |
| 485 | exit(1); |
| 486 | } |
| 487 | ngx_old_cycles.nelts = 0; |
| 488 | ngx_old_cycles.size = sizeof(ngx_cycle_t *); |
| 489 | ngx_old_cycles.nalloc = n; |
| 490 | ngx_old_cycles.pool = ngx_temp_pool; |
| 491 | |
| 492 | ngx_cleaner_event.event_handler = ngx_clean_old_cycles; |
| 493 | ngx_cleaner_event.log = cycle->log; |
| 494 | ngx_cleaner_event.data = &dumb; |
| 495 | dumb.fd = (ngx_socket_t) -1; |
| 496 | } |
| 497 | |
| 498 | ngx_temp_pool->log = cycle->log; |
| 499 | |
| 500 | old = ngx_push_array(&ngx_old_cycles); |
| 501 | if (old == NULL) { |
| 502 | exit(1); |
| 503 | } |
| 504 | *old = old_cycle; |
| 505 | |
| 506 | if (!ngx_cleaner_event.timer_set) { |
| 507 | ngx_add_timer(&ngx_cleaner_event, 30000); |
| 508 | ngx_cleaner_event.timer_set = 1; |
| 509 | } |
| 510 | |
| 511 | return cycle; |
| 512 | } |
| 513 | |
| 514 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 515 | #if !(WIN32) |
| 516 | |
| 517 | ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 518 | { |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 519 | ngx_uint_t trunc; |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 520 | size_t len; |
| 521 | u_char *name, pid[NGX_INT64_LEN + 1]; |
| 522 | ngx_file_t file; |
| 523 | ngx_core_conf_t *ccf, *old_ccf; |
| 524 | |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 525 | if (!ngx_test_config && old_cycle && old_cycle->conf_ctx == NULL) { |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 526 | |
| 527 | /* |
| 528 | * do not create the pid file in the first ngx_init_cycle() call |
| 529 | * because we need to write the demonized process pid |
| 530 | */ |
| 531 | |
| 532 | return NGX_OK; |
| 533 | } |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 534 | |
| 535 | ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
| 536 | |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 537 | if (!ngx_test_config && old_cycle) { |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 538 | old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx, |
| 539 | ngx_core_module); |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 540 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 541 | if (ccf->pid.len == old_ccf->pid.len |
| 542 | && ngx_strcmp(ccf->pid.data, old_ccf->pid.data) == 0) |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 543 | { |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 544 | |
| 545 | /* pid file name is the same */ |
| 546 | |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 547 | return NGX_OK; |
| 548 | } |
| 549 | } |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 550 | |
| 551 | len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 552 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 553 | ngx_memzero(&file, sizeof(ngx_file_t)); |
| 554 | file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; |
| 555 | file.log = cycle->log; |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 556 | |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 557 | trunc = ngx_test_config ? 0: NGX_FILE_TRUNCATE; |
| 558 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 559 | file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR, |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 560 | NGX_FILE_CREATE_OR_OPEN|trunc); |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 561 | |
| 562 | if (file.fd == NGX_INVALID_FILE) { |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 563 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 564 | ngx_open_file_n " \"%s\" failed", file.name.data); |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 565 | return NGX_ERROR; |
| 566 | } |
| 567 | |
Igor Sysoev | 090849d | 2004-05-18 20:28:54 +0000 | [diff] [blame] | 568 | if (!ngx_test_config) { |
| 569 | if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { |
| 570 | return NGX_ERROR; |
| 571 | } |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 574 | if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 575 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 576 | ngx_close_file_n " \"%s\" failed", file.name.data); |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 579 | ngx_delete_pidfile(old_cycle); |
| 580 | |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 581 | return NGX_OK; |
| 582 | } |
| 583 | |
| 584 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 585 | void ngx_delete_pidfile(ngx_cycle_t *cycle) |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 586 | { |
| 587 | u_char *name; |
| 588 | ngx_core_conf_t *ccf; |
| 589 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 590 | if (cycle == NULL || cycle->conf_ctx == NULL) { |
| 591 | return; |
| 592 | } |
| 593 | |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 594 | ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
| 595 | |
| 596 | if (ngx_inherited && getppid() > 1) { |
| 597 | name = ccf->newpid.data; |
| 598 | |
| 599 | } else { |
| 600 | name = ccf->pid.data; |
| 601 | } |
| 602 | |
| 603 | if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
| 604 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
| 605 | ngx_delete_file_n " \"%s\" failed", name); |
| 606 | } |
| 607 | } |
| 608 | |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 609 | #endif |
| 610 | |
Igor Sysoev | 076498e | 2004-04-12 06:10:53 +0000 | [diff] [blame] | 611 | |
Igor Sysoev | a536298 | 2004-03-04 07:04:55 +0000 | [diff] [blame] | 612 | void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 613 | { |
| 614 | ngx_fd_t fd; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 615 | ngx_uint_t i; |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 616 | ngx_list_part_t *part; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 617 | ngx_open_file_t *file; |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame^] | 618 | #if !(WIN32) |
| 619 | ngx_file_info_t fi; |
| 620 | #endif |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 621 | |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 622 | part = &cycle->open_files.part; |
| 623 | file = part->elts; |
| 624 | |
| 625 | for (i = 0; /* void */ ; i++) { |
| 626 | |
| 627 | if (i >= part->nelts) { |
| 628 | if (part->next == NULL) { |
| 629 | break; |
| 630 | } |
| 631 | part = part->next; |
| 632 | i = 0; |
| 633 | } |
| 634 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 635 | if (file[i].name.data == NULL) { |
| 636 | continue; |
| 637 | } |
| 638 | |
| 639 | fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR, |
| 640 | NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); |
| 641 | |
| 642 | ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
| 643 | "reopen file \"%s\", old:%d new:%d", |
| 644 | file[i].name.data, file[i].fd, fd); |
| 645 | |
| 646 | if (fd == NGX_INVALID_FILE) { |
| 647 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 648 | ngx_open_file_n " \"%s\" failed", file[i].name.data); |
| 649 | continue; |
| 650 | } |
| 651 | |
| 652 | #if (WIN32) |
| 653 | if (ngx_file_append_mode(fd) == NGX_ERROR) { |
| 654 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 655 | ngx_file_append_mode_n " \"%s\" failed", |
| 656 | file[i].name.data); |
| 657 | |
| 658 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 659 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 660 | ngx_close_file_n " \"%s\" failed", |
| 661 | file[i].name.data); |
| 662 | } |
| 663 | |
| 664 | continue; |
| 665 | } |
Igor Sysoev | 0911f77 | 2004-01-14 18:19:42 +0000 | [diff] [blame] | 666 | #else |
Igor Sysoev | a536298 | 2004-03-04 07:04:55 +0000 | [diff] [blame] | 667 | if (user != (ngx_uid_t) -1) { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 668 | if (chown((const char *) file[i].name.data, user, -1) == -1) { |
Igor Sysoev | a536298 | 2004-03-04 07:04:55 +0000 | [diff] [blame] | 669 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 670 | "chown \"%s\" failed", file[i].name.data); |
| 671 | |
| 672 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 673 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 674 | ngx_close_file_n " \"%s\" failed", |
| 675 | file[i].name.data); |
| 676 | } |
| 677 | } |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame^] | 678 | |
| 679 | if (ngx_file_info((const char *) file[i].name.data, &fi) == -1) { |
| 680 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 681 | ngx_file_info_n " \"%s\" failed", |
| 682 | file[i].name.data); |
| 683 | |
| 684 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 685 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 686 | ngx_close_file_n " \"%s\" failed", |
| 687 | file[i].name.data); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | if ((fi.st_mode & (S_IRUSR|S_IWUSR)) != (S_IRUSR|S_IWUSR)) { |
| 692 | |
| 693 | fi.st_mode |= (S_IRUSR|S_IWUSR); |
| 694 | |
| 695 | if (chmod((const char *) file[i].name.data, fi.st_mode) == -1) { |
| 696 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 697 | "chmod \"%s\" failed", |
| 698 | file[i].name.data); |
| 699 | |
| 700 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 701 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 702 | ngx_close_file_n " \"%s\" failed", |
| 703 | file[i].name.data); |
| 704 | } |
| 705 | } |
| 706 | } |
Igor Sysoev | a536298 | 2004-03-04 07:04:55 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Igor Sysoev | 0911f77 | 2004-01-14 18:19:42 +0000 | [diff] [blame] | 709 | if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { |
| 710 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 711 | "fcntl(FD_CLOEXEC) \"%s\" failed", |
| 712 | file[i].name.data); |
| 713 | |
| 714 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 715 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 716 | ngx_close_file_n " \"%s\" failed", |
| 717 | file[i].name.data); |
| 718 | } |
| 719 | |
| 720 | continue; |
| 721 | } |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 722 | #endif |
| 723 | |
| 724 | if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { |
| 725 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 726 | ngx_close_file_n " \"%s\" failed", |
| 727 | file[i].name.data); |
| 728 | } |
| 729 | |
| 730 | file[i].fd = fd; |
| 731 | } |
Igor Sysoev | 25b36fe | 2004-02-03 16:43:54 +0000 | [diff] [blame] | 732 | |
Igor Sysoev | a893eab | 2004-03-11 21:34:52 +0000 | [diff] [blame] | 733 | #if !(WIN32) |
| 734 | |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 735 | if (cycle->log->file->fd != STDERR_FILENO) { |
| 736 | if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { |
| 737 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| 738 | "dup2(STDERR) failed"); |
| 739 | } |
Igor Sysoev | 25b36fe | 2004-02-03 16:43:54 +0000 | [diff] [blame] | 740 | } |
Igor Sysoev | a893eab | 2004-03-11 21:34:52 +0000 | [diff] [blame] | 741 | |
Igor Sysoev | a536298 | 2004-03-04 07:04:55 +0000 | [diff] [blame] | 742 | #endif |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 746 | static void ngx_clean_old_cycles(ngx_event_t *ev) |
| 747 | { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 748 | ngx_uint_t i, n, found, live; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 749 | ngx_log_t *log; |
| 750 | ngx_cycle_t **cycle; |
| 751 | |
| 752 | log = ngx_cycle->log; |
| 753 | ngx_temp_pool->log = log; |
| 754 | |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 755 | ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "clean old cycles"); |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 756 | |
| 757 | live = 0; |
| 758 | |
| 759 | cycle = ngx_old_cycles.elts; |
| 760 | for (i = 0; i < ngx_old_cycles.nelts; i++) { |
| 761 | |
| 762 | if (cycle[i] == NULL) { |
| 763 | continue; |
| 764 | } |
| 765 | |
| 766 | found = 0; |
| 767 | |
| 768 | for (n = 0; n < cycle[i]->connection_n; n++) { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 769 | if (cycle[i]->connections[n].fd != (ngx_socket_t) -1) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 770 | found = 1; |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 771 | |
| 772 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "live fd:%d", n); |
| 773 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | if (found) { |
| 779 | live = 1; |
| 780 | continue; |
| 781 | } |
| 782 | |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 783 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "clean old cycle: %d", i); |
| 784 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 785 | ngx_destroy_pool(cycle[i]->pool); |
| 786 | cycle[i] = NULL; |
| 787 | } |
| 788 | |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 789 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "old cycles status: %d", live); |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 790 | |
| 791 | if (live) { |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 792 | ngx_add_timer(ev, 30000); |
| 793 | |
| 794 | } else { |
| 795 | ngx_destroy_pool(ngx_temp_pool); |
| 796 | ngx_temp_pool = NULL; |
| 797 | ngx_old_cycles.nelts = 0; |
| 798 | } |
| 799 | } |