comparison src/core/ngx_cycle.c @ 414:388a842cbbe1

nginx-0.0.10-2004-09-03-19:50:30 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 03 Sep 2004 15:50:30 +0000
parents 02a511569afb
children 3c56e834be46
comparison
equal deleted inserted replaced
413:de9d4726e28a 414:388a842cbbe1
32 ngx_log_t *log; 32 ngx_log_t *log;
33 ngx_conf_t conf; 33 ngx_conf_t conf;
34 ngx_pool_t *pool; 34 ngx_pool_t *pool;
35 ngx_cycle_t *cycle, **old; 35 ngx_cycle_t *cycle, **old;
36 ngx_socket_t fd; 36 ngx_socket_t fd;
37 ngx_list_part_t *part;
37 ngx_open_file_t *file; 38 ngx_open_file_t *file;
38 ngx_listening_t *ls, *nls; 39 ngx_listening_t *ls, *nls;
39 ngx_core_module_t *module; 40 ngx_core_module_t *module;
40 41
41 log = old_cycle->log; 42 log = old_cycle->log;
66 cycle->pathes.size = sizeof(ngx_path_t *); 67 cycle->pathes.size = sizeof(ngx_path_t *);
67 cycle->pathes.nalloc = n; 68 cycle->pathes.nalloc = n;
68 cycle->pathes.pool = pool; 69 cycle->pathes.pool = pool;
69 70
70 71
72 if (old_cycle->open_files.part.nelts) {
73 n = old_cycle->open_files.part.nelts;
74 for (part = old_cycle->open_files.part.next; part; part = part->next) {
75 n += part->nelts;
76 }
77
78 } else {
79 n = 20;
80 }
81
82 cycle->open_files.part.elts = ngx_palloc(pool, n * sizeof(ngx_open_file_t));
83 if (cycle->open_files.part.elts == NULL) {
84 ngx_destroy_pool(pool);
85 return NULL;
86 }
87 cycle->open_files.part.nelts = 0;
88 cycle->open_files.part.next = NULL;
89 cycle->open_files.last = &cycle->open_files.part;
90 cycle->open_files.size = sizeof(ngx_open_file_t);
91 cycle->open_files.nalloc = n;
92 cycle->open_files.pool = pool;
93
94
95 #if 0
71 n = old_cycle->open_files.nelts ? old_cycle->open_files.nelts : 20; 96 n = old_cycle->open_files.nelts ? old_cycle->open_files.nelts : 20;
72 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); 97 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
73 if (cycle->open_files.elts == NULL) { 98 if (cycle->open_files.elts == NULL) {
74 ngx_destroy_pool(pool); 99 ngx_destroy_pool(pool);
75 return NULL; 100 return NULL;
76 } 101 }
77 cycle->open_files.nelts = 0; 102 cycle->open_files.nelts = 0;
78 cycle->open_files.size = sizeof(ngx_open_file_t); 103 cycle->open_files.size = sizeof(ngx_open_file_t);
79 cycle->open_files.nalloc = n; 104 cycle->open_files.nalloc = n;
80 cycle->open_files.pool = pool; 105 cycle->open_files.pool = pool;
106 #endif
81 107
82 108
83 if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) { 109 if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
84 ngx_destroy_pool(pool); 110 ngx_destroy_pool(pool);
85 return NULL; 111 return NULL;
178 } 204 }
179 #endif 205 #endif
180 206
181 207
182 if (!failed) { 208 if (!failed) {
209
210 part = &cycle->open_files.part;
211 file = part->elts;
212
213 for (i = 0; /* void */ ; i++) {
214
215 if (i >= part->nelts) {
216 if (part->next == NULL) {
217 break;
218 }
219 part = part->next;
220 file = part->elts;
221 i = 0;
222 }
223
224 #if 0
183 file = cycle->open_files.elts; 225 file = cycle->open_files.elts;
184 for (i = 0; i < cycle->open_files.nelts; i++) { 226 for (i = 0; i < cycle->open_files.nelts; i++) {
227 #endif
228
185 if (file[i].name.data == NULL) { 229 if (file[i].name.data == NULL) {
186 continue; 230 continue;
187 } 231 }
188 232
189 file[i].fd = ngx_open_file(file[i].name.data, 233 file[i].fd = ngx_open_file(file[i].name.data,
190 NGX_FILE_RDWR, 234 NGX_FILE_RDWR,
191 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); 235 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
236
237 log->log_level = NGX_LOG_DEBUG_ALL;
238 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
239 "log: %0X %d \"%s\"",
240 &file[i], file[i].fd, file[i].name.data);
192 241
193 if (file[i].fd == NGX_INVALID_FILE) { 242 if (file[i].fd == NGX_INVALID_FILE) {
194 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 243 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
195 ngx_open_file_n " \"%s\" failed", 244 ngx_open_file_n " \"%s\" failed",
196 file[i].name.data); 245 file[i].name.data);
285 } 334 }
286 335
287 #if !(WIN32) 336 #if !(WIN32)
288 337
289 if (!failed && !ngx_test_config) { 338 if (!failed && !ngx_test_config) {
339
340 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
341 "dup2: %0X %d \"%s\"",
342 cycle->log->file,
343 cycle->log->file->fd, cycle->log->file->name.data);
344
290 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { 345 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
291 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 346 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
292 "dup2(STDERR) failed"); 347 "dup2(STDERR) failed");
293 failed = 1; 348 failed = 1;
294 } 349 }
298 353
299 if (failed) { 354 if (failed) {
300 355
301 /* rollback the new cycle configuration */ 356 /* rollback the new cycle configuration */
302 357
358 part = &cycle->open_files.part;
359 file = part->elts;
360
361 for (i = 0; /* void */ ; i++) {
362
363 if (i >= part->nelts) {
364 if (part->next == NULL) {
365 break;
366 }
367 part = part->next;
368 file = part->elts;
369 i = 0;
370 }
371
372 #if 0
303 file = cycle->open_files.elts; 373 file = cycle->open_files.elts;
304 for (i = 0; i < cycle->open_files.nelts; i++) { 374 for (i = 0; i < cycle->open_files.nelts; i++) {
375 #endif
376
305 if (file[i].fd == NGX_INVALID_FILE) { 377 if (file[i].fd == NGX_INVALID_FILE) {
306 continue; 378 continue;
307 } 379 }
308 380
309 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 381 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
318 return NULL; 390 return NULL;
319 } 391 }
320 392
321 ls = cycle->listening.elts; 393 ls = cycle->listening.elts;
322 for (i = 0; i < cycle->listening.nelts; i++) { 394 for (i = 0; i < cycle->listening.nelts; i++) {
323 if (ls[i].new && ls[i].fd == -1) { 395 if (ls[i].fd == -1 || !ls[i].new) {
324 continue; 396 continue;
325 } 397 }
326 398
327 if (ngx_close_socket(ls[i].fd) == -1) { 399 if (ngx_close_socket(ls[i].fd) == -1) {
328 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, 400 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
368 } 440 }
369 441
370 442
371 /* close the unneeded open files */ 443 /* close the unneeded open files */
372 444
445 part = &old_cycle->open_files.part;
446 file = part->elts;
447
448 for (i = 0; /* void */ ; i++) {
449
450 if (i >= part->nelts) {
451 if (part->next == NULL) {
452 break;
453 }
454 part = part->next;
455 file = part->elts;
456 i = 0;
457 }
458
459 #if 0
373 file = old_cycle->open_files.elts; 460 file = old_cycle->open_files.elts;
374 for (i = 0; i < old_cycle->open_files.nelts; i++) { 461 for (i = 0; i < old_cycle->open_files.nelts; i++) {
462 #endif
463
375 if (file[i].fd == NGX_INVALID_FILE) { 464 if (file[i].fd == NGX_INVALID_FILE) {
376 continue; 465 continue;
377 } 466 }
378 467
379 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 468 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
532 621
533 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) 622 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
534 { 623 {
535 ngx_fd_t fd; 624 ngx_fd_t fd;
536 ngx_uint_t i; 625 ngx_uint_t i;
626 ngx_list_part_t *part;
537 ngx_open_file_t *file; 627 ngx_open_file_t *file;
538 628
629 part = &cycle->open_files.part;
630 file = part->elts;
631
632 for (i = 0; /* void */ ; i++) {
633
634 if (i >= part->nelts) {
635 if (part->next == NULL) {
636 break;
637 }
638 part = part->next;
639 i = 0;
640 }
641
642 #if 0
539 file = cycle->open_files.elts; 643 file = cycle->open_files.elts;
540 for (i = 0; i < cycle->open_files.nelts; i++) { 644 for (i = 0; i < cycle->open_files.nelts; i++) {
645 #endif
646
541 if (file[i].name.data == NULL) { 647 if (file[i].name.data == NULL) {
542 continue; 648 continue;
543 } 649 }
544 650
545 fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR, 651 fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,