Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 2638:a3f062177dba stable-0.6
r2336, r2337, r2339, r2390 merge:
bugfixes in error logging:
*) ngx_strerror_r() style and size == 0 bug fix
*) increase ngx_conf_log_error() buffer
*) always log an error code
*) fix segfault on close error
*) compact win32 errno logging
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 01 Apr 2009 15:47:12 +0000 |
parents | 0ebecd0c3410 |
children |
comparison
equal
deleted
inserted
replaced
2637:8e4450668968 | 2638:a3f062177dba |
---|---|
199 done: | 199 done: |
200 | 200 |
201 if (filename) { | 201 if (filename) { |
202 ngx_free(cf->conf_file->buffer->start); | 202 ngx_free(cf->conf_file->buffer->start); |
203 | 203 |
204 cf->conf_file = prev; | |
205 | |
206 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 204 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
207 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, | 205 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
208 ngx_close_file_n " %s failed", | 206 ngx_close_file_n " %s failed", |
209 cf->conf_file->file.name.data); | 207 cf->conf_file->file.name.data); |
210 return NGX_CONF_ERROR; | 208 return NGX_CONF_ERROR; |
211 } | 209 } |
210 | |
211 cf->conf_file = prev; | |
212 } | 212 } |
213 | 213 |
214 if (rc == NGX_ERROR) { | 214 if (rc == NGX_ERROR) { |
215 return NGX_CONF_ERROR; | 215 return NGX_CONF_ERROR; |
216 } | 216 } |
851 | 851 |
852 void ngx_cdecl | 852 void ngx_cdecl |
853 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, | 853 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, |
854 char *fmt, ...) | 854 char *fmt, ...) |
855 { | 855 { |
856 u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; | 856 u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last; |
857 va_list args; | 857 va_list args; |
858 | 858 |
859 last = errstr + NGX_MAX_CONF_ERRSTR; | 859 last = errstr + NGX_MAX_CONF_ERRSTR; |
860 | 860 |
861 va_start(args, fmt); | 861 va_start(args, fmt); |
862 buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); | 862 p = ngx_vsnprintf(errstr, last - errstr, fmt, args); |
863 va_end(args); | 863 va_end(args); |
864 | 864 |
865 *buf = '\0'; | |
866 | |
867 if (err) { | 865 if (err) { |
868 buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err); | 866 |
869 buf = ngx_strerror_r(err, buf, last - buf - 1); | 867 if (p > last - 50) { |
870 *buf++ = ')'; | 868 |
871 *buf = '\0'; | 869 /* leave a space for an error code */ |
870 | |
871 p = last - 50; | |
872 *p++ = '.'; | |
873 *p++ = '.'; | |
874 *p++ = '.'; | |
875 } | |
876 | |
877 #if (NGX_WIN32) | |
878 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) | |
879 ? " (%d: " : " (%Xd: ", err); | |
880 #else | |
881 p = ngx_snprintf(p, last - p, " (%d: ", err); | |
882 #endif | |
883 | |
884 p = ngx_strerror_r(err, p, last - p); | |
885 | |
886 *p++ = ')'; | |
872 } | 887 } |
873 | 888 |
874 if (cf->conf_file == NULL) { | 889 if (cf->conf_file == NULL) { |
875 ngx_log_error(level, cf->log, 0, "%s", errstr); | 890 ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr); |
876 return; | 891 return; |
877 } | 892 } |
878 | 893 |
879 ngx_log_error(level, cf->log, 0, "%s in %s:%ui", | 894 ngx_log_error(level, cf->log, 0, "%*s in %s:%ui", |
880 errstr, cf->conf_file->file.name.data, cf->conf_file->line); | 895 p - errstr, errstr, |
896 cf->conf_file->file.name.data, cf->conf_file->line); | |
881 } | 897 } |
882 | 898 |
883 | 899 |
884 char * | 900 char * |
885 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 901 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |