comparison src/core/ngx_cycle.c @ 278:0ba4821f4460

nginx-0.0.2-2004-03-04-10:04:55 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 04 Mar 2004 07:04:55 +0000
parents 70e1c7d2b83d
children 30310107dbc9
comparison
equal deleted inserted replaced
277:e91499541410 278:0ba4821f4460
22 22
23 23
24 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 24 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
25 { 25 {
26 ngx_int_t i, n, failed; 26 ngx_int_t i, n, failed;
27 ngx_str_t conf_file;
28 ngx_log_t *log; 27 ngx_log_t *log;
29 ngx_conf_t conf; 28 ngx_conf_t conf;
30 ngx_pool_t *pool; 29 ngx_pool_t *pool;
31 ngx_cycle_t *cycle, **old; 30 ngx_cycle_t *cycle, **old;
32 ngx_socket_t fd; 31 ngx_socket_t fd;
225 failed = 1; 224 failed = 1;
226 } 225 }
227 } 226 }
228 } 227 }
229 228
230 /* TODO: Win32 DuplicateHandle ? */ 229 #if (WIN32)
231 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { 230 /* TODO: TEST */
231 CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
232 SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd);
233 #else
234 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
232 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 235 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
233 "dup2(STDERR) failed"); 236 "dup2(STDERR) failed");
234 failed = 1; 237 failed = 1;
235 } 238 }
236 239 #endif
237 240
238 if (failed) { 241 if (failed) {
239 242
240 /* rollback the new cycle configuration */ 243 /* rollback the new cycle configuration */
241 244
368 371
369 return cycle; 372 return cycle;
370 } 373 }
371 374
372 375
373 void ngx_reopen_files(ngx_cycle_t *cycle, uid_t user) 376 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
374 { 377 {
375 ngx_fd_t fd; 378 ngx_fd_t fd;
376 ngx_int_t i; 379 ngx_int_t i;
377 ngx_open_file_t *file; 380 ngx_open_file_t *file;
378 381
393 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 396 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
394 ngx_open_file_n " \"%s\" failed", file[i].name.data); 397 ngx_open_file_n " \"%s\" failed", file[i].name.data);
395 continue; 398 continue;
396 } 399 }
397 400
398 if (user != (uid_t) -1) { 401 #if (WIN32)
402 if (ngx_file_append_mode(fd) == NGX_ERROR) {
403 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
404 ngx_file_append_mode_n " \"%s\" failed",
405 file[i].name.data);
406
407 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
408 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
409 ngx_close_file_n " \"%s\" failed",
410 file[i].name.data);
411 }
412
413 continue;
414 }
415 #else
416 if (user != (ngx_uid_t) -1) {
399 if (chown(file[i].name.data, user, -1) == -1) { 417 if (chown(file[i].name.data, user, -1) == -1) {
400 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 418 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
401 "chown \"%s\" failed", file[i].name.data); 419 "chown \"%s\" failed", file[i].name.data);
402 420
403 if (ngx_close_file(fd) == NGX_FILE_ERROR) { 421 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
406 file[i].name.data); 424 file[i].name.data);
407 } 425 }
408 } 426 }
409 } 427 }
410 428
411 #if (WIN32) 429 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
412 if (ngx_file_append_mode(fd) == NGX_ERROR) {
413 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 430 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
414 ngx_file_append_mode_n " \"%s\" failed", 431 "fcntl(FD_CLOEXEC) \"%s\" failed",
415 file[i].name.data); 432 file[i].name.data);
416 433
417 if (ngx_close_file(fd) == NGX_FILE_ERROR) { 434 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
418 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 435 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
419 ngx_close_file_n " \"%s\" failed", 436 ngx_close_file_n " \"%s\" failed",
420 file[i].name.data); 437 file[i].name.data);
421 } 438 }
422 439
423 continue; 440 continue;
424 } 441 }
425 #else
426 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
427 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
428 "fcntl(FD_CLOEXEC) \"%s\" failed",
429 file[i].name.data);
430
431 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
432 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
433 ngx_close_file_n " \"%s\" failed",
434 file[i].name.data);
435 }
436
437 continue;
438 }
439 #endif 442 #endif
440 443
441 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { 444 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
442 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 445 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
443 ngx_close_file_n " \"%s\" failed", 446 ngx_close_file_n " \"%s\" failed",
445 } 448 }
446 449
447 file[i].fd = fd; 450 file[i].fd = fd;
448 } 451 }
449 452
450 /* TODO: Win32 DuplicateHandle ? */ 453 #if (WIN32)
454 /* TODO: TEST */
455 CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
456 SetStdHandle(STD_ERROR_HANDLE, cycle->log->file->fd);
457 #else
451 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { 458 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
452 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 459 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
453 "dup2(STDERR) failed"); 460 "dup2(STDERR) failed");
454 } 461 }
462 #endif
455 } 463 }
456 464
457 465
458 static void ngx_clean_old_cycles(ngx_event_t *ev) 466 static void ngx_clean_old_cycles(ngx_event_t *ev)
459 { 467 {