Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 5053:004af18ddb86 stable-1.2
Merge of r4985, r4986, r4987, r4988, r4989, r5002: access_log gzip.
*) Access log: fixed redundant buffer reallocation. Previously a new
buffer was allocated for every "access_log" directive with the same
file path and "buffer=" parameters, while only one buffer per file
is used.
*) 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..
*) Access log: the "flush" parameter of the "access_log" directive.
*) Configure: added the NGX_ZLIB define. This was introduced for
conditional compilation of the code that requires the zlib library.
*) Access log: the "gzip" parameter of the "access_log" directive.
Note: this requires zlib version 1.2.0.4 or above to work.
*) The data pointer in ngx_open_file_t objects must be initialized.
Uninitialized pointer may result in arbitrary segfaults if access_log
is used without buffer and without variables in file path.
Patch by Tatsuhiko Kubo (ticket #268).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 11 Feb 2013 14:34:00 +0000 |
parents | f4809ba58b15 |
children | c0497468f521 |
comparison
equal
deleted
inserted
replaced
5052:f2dcb25987df | 5053:004af18ddb86 |
---|---|
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 file->data = NULL; | |
949 | 950 |
950 return file; | 951 return file; |
951 } | 952 } |
952 | 953 |
953 | 954 |
954 static void | 955 static void |
955 ngx_conf_flush_files(ngx_cycle_t *cycle) | 956 ngx_conf_flush_files(ngx_cycle_t *cycle) |
956 { | 957 { |
957 ssize_t n, len; | |
958 ngx_uint_t i; | 958 ngx_uint_t i; |
959 ngx_list_part_t *part; | 959 ngx_list_part_t *part; |
960 ngx_open_file_t *file; | 960 ngx_open_file_t *file; |
961 | 961 |
962 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files"); | 962 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files"); |
973 part = part->next; | 973 part = part->next; |
974 file = part->elts; | 974 file = part->elts; |
975 i = 0; | 975 i = 0; |
976 } | 976 } |
977 | 977 |
978 len = file[i].pos - file[i].buffer; | 978 if (file[i].flush) { |
979 | 979 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 } | 980 } |
996 } | 981 } |
997 } | 982 } |
998 | 983 |
999 | 984 |