comparison src/core/ngx_conf_file.c @ 4985:a0599b56e748

Reopening log files code moved to a separate function. The code refactored in a way to call custom handler that can do appropriate cleanup work (if any), like flushing buffers, finishing compress streams, finalizing connections to log daemon, etc..
author Valentin Bartenev <vbart@nginx.com>
date Sun, 23 Dec 2012 15:36:52 +0000
parents c821975c9068
children c37b9a17514d
comparison
equal deleted inserted replaced
4984:7737f0d788c1 4985:a0599b56e748
943 } else { 943 } else {
944 file->fd = ngx_stderr; 944 file->fd = ngx_stderr;
945 file->name = *name; 945 file->name = *name;
946 } 946 }
947 947
948 file->buffer = NULL; 948 file->flush = NULL;
949 949
950 return file; 950 return file;
951 } 951 }
952 952
953 953
954 static void 954 static void
955 ngx_conf_flush_files(ngx_cycle_t *cycle) 955 ngx_conf_flush_files(ngx_cycle_t *cycle)
956 { 956 {
957 ssize_t n, len;
958 ngx_uint_t i; 957 ngx_uint_t i;
959 ngx_list_part_t *part; 958 ngx_list_part_t *part;
960 ngx_open_file_t *file; 959 ngx_open_file_t *file;
961 960
962 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files"); 961 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files");
973 part = part->next; 972 part = part->next;
974 file = part->elts; 973 file = part->elts;
975 i = 0; 974 i = 0;
976 } 975 }
977 976
978 len = file[i].pos - file[i].buffer; 977 if (file[i].flush) {
979 978 file[i].flush(&file[i], cycle->log);
980 if (file[i].buffer == NULL || len == 0) {
981 continue;
982 }
983
984 n = ngx_write_fd(file[i].fd, file[i].buffer, len);
985
986 if (n == -1) {
987 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
988 ngx_write_fd_n " to \"%s\" failed",
989 file[i].name.data);
990
991 } else if (n != len) {
992 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
993 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
994 file[i].name.data, n, len);
995 } 979 }
996 } 980 }
997 } 981 }
998 982
999 983