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