comparison src/core/ngx_cycle.c @ 415:3c56e834be46

nginx-0.0.10-2004-09-05-23:54:02 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 05 Sep 2004 19:54:02 +0000
parents 388a842cbbe1
children b9bd635011de
comparison
equal deleted inserted replaced
414:388a842cbbe1 415:3c56e834be46
21 21
22 22
23 /* STUB NAME */ 23 /* STUB NAME */
24 static ngx_connection_t dumb; 24 static ngx_connection_t dumb;
25 /* STUB */ 25 /* STUB */
26
27 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
26 28
27 29
28 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 30 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
29 { 31 {
30 void *rv; 32 void *rv;
77 79
78 } else { 80 } else {
79 n = 20; 81 n = 20;
80 } 82 }
81 83
82 cycle->open_files.part.elts = ngx_palloc(pool, n * sizeof(ngx_open_file_t)); 84 if (ngx_init_list(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
83 if (cycle->open_files.part.elts == NULL) { 85 == NGX_ERROR)
84 ngx_destroy_pool(pool); 86 {
85 return NULL; 87 ngx_destroy_pool(pool);
86 } 88 return NULL;
87 cycle->open_files.part.nelts = 0; 89 }
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
96 n = old_cycle->open_files.nelts ? old_cycle->open_files.nelts : 20;
97 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
98 if (cycle->open_files.elts == NULL) {
99 ngx_destroy_pool(pool);
100 return NULL;
101 }
102 cycle->open_files.nelts = 0;
103 cycle->open_files.size = sizeof(ngx_open_file_t);
104 cycle->open_files.nalloc = n;
105 cycle->open_files.pool = pool;
106 #endif
107 90
108 91
109 if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) { 92 if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
110 ngx_destroy_pool(pool); 93 ngx_destroy_pool(pool);
111 return NULL; 94 return NULL;
112 } 95 }
96
97 cycle->new_log->file->name = error_log;
113 98
114 99
115 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10; 100 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
116 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); 101 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
117 if (cycle->listening.elts == NULL) { 102 if (cycle->listening.elts == NULL) {
219 part = part->next; 204 part = part->next;
220 file = part->elts; 205 file = part->elts;
221 i = 0; 206 i = 0;
222 } 207 }
223 208
224 #if 0
225 file = cycle->open_files.elts;
226 for (i = 0; i < cycle->open_files.nelts; i++) {
227 #endif
228
229 if (file[i].name.data == NULL) { 209 if (file[i].name.data == NULL) {
230 continue; 210 continue;
231 } 211 }
232 212
233 file[i].fd = ngx_open_file(file[i].name.data, 213 file[i].fd = ngx_open_file(file[i].name.data,
234 NGX_FILE_RDWR, 214 NGX_FILE_RDWR,
235 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); 215 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
236 216
217 #if 0
237 log->log_level = NGX_LOG_DEBUG_ALL; 218 log->log_level = NGX_LOG_DEBUG_ALL;
219 #endif
238 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, 220 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
239 "log: %0X %d \"%s\"", 221 "log: %0X %d \"%s\"",
240 &file[i], file[i].fd, file[i].name.data); 222 &file[i], file[i].fd, file[i].name.data);
241 223
242 if (file[i].fd == NGX_INVALID_FILE) { 224 if (file[i].fd == NGX_INVALID_FILE) {
267 } 249 }
268 } 250 }
269 251
270 cycle->log = cycle->new_log; 252 cycle->log = cycle->new_log;
271 pool->log = cycle->new_log; 253 pool->log = cycle->new_log;
254
255 if (cycle->log->log_level == 0) {
256 cycle->log->log_level = NGX_LOG_ERR;
257 }
272 258
273 if (!failed) { 259 if (!failed) {
274 if (old_cycle->listening.nelts) { 260 if (old_cycle->listening.nelts) {
275 ls = old_cycle->listening.elts; 261 ls = old_cycle->listening.elts;
276 for (i = 0; i < old_cycle->listening.nelts; i++) { 262 for (i = 0; i < old_cycle->listening.nelts; i++) {
333 } 319 }
334 } 320 }
335 321
336 #if !(WIN32) 322 #if !(WIN32)
337 323
338 if (!failed && !ngx_test_config) { 324 if (!failed && !ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
339 325
340 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, 326 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
341 "dup2: %0X %d \"%s\"", 327 "dup2: %0X %d \"%s\"",
342 cycle->log->file, 328 cycle->log->file,
343 cycle->log->file->fd, cycle->log->file->name.data); 329 cycle->log->file->fd, cycle->log->file->name.data);
367 part = part->next; 353 part = part->next;
368 file = part->elts; 354 file = part->elts;
369 i = 0; 355 i = 0;
370 } 356 }
371 357
372 #if 0
373 file = cycle->open_files.elts;
374 for (i = 0; i < cycle->open_files.nelts; i++) {
375 #endif
376
377 if (file[i].fd == NGX_INVALID_FILE) { 358 if (file[i].fd == NGX_INVALID_FILE) {
378 continue; 359 continue;
379 } 360 }
380 361
381 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 362 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
453 } 434 }
454 part = part->next; 435 part = part->next;
455 file = part->elts; 436 file = part->elts;
456 i = 0; 437 i = 0;
457 } 438 }
458
459 #if 0
460 file = old_cycle->open_files.elts;
461 for (i = 0; i < old_cycle->open_files.nelts; i++) {
462 #endif
463 439
464 if (file[i].fd == NGX_INVALID_FILE) { 440 if (file[i].fd == NGX_INVALID_FILE) {
465 continue; 441 continue;
466 } 442 }
467 443
637 } 613 }
638 part = part->next; 614 part = part->next;
639 i = 0; 615 i = 0;
640 } 616 }
641 617
642 #if 0
643 file = cycle->open_files.elts;
644 for (i = 0; i < cycle->open_files.nelts; i++) {
645 #endif
646
647 if (file[i].name.data == NULL) { 618 if (file[i].name.data == NULL) {
648 continue; 619 continue;
649 } 620 }
650 621
651 fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR, 622 fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,
713 file[i].fd = fd; 684 file[i].fd = fd;
714 } 685 }
715 686
716 #if !(WIN32) 687 #if !(WIN32)
717 688
718 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { 689 if (cycle->log->file->fd != STDERR_FILENO) {
719 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 690 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
720 "dup2(STDERR) failed"); 691 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
692 "dup2(STDERR) failed");
693 }
721 } 694 }
722 695
723 #endif 696 #endif
724 } 697 }
725 698