comparison src/core/ngx_conf_file.c @ 2336:81d506883bba

*) increase ngx_conf_log_error() buffer *) always log an error code
author Igor Sysoev <igor@sysoev.ru>
date Tue, 25 Nov 2008 13:00:53 +0000
parents 2abf14c952a2
children 5cbf2da3a324
comparison
equal deleted inserted replaced
2335:3d8ab5957202 2336:81d506883bba
957 957
958 void ngx_cdecl 958 void ngx_cdecl
959 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, 959 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
960 char *fmt, ...) 960 char *fmt, ...)
961 { 961 {
962 u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; 962 u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
963 va_list args; 963 va_list args;
964 964
965 last = errstr + NGX_MAX_CONF_ERRSTR; 965 last = errstr + NGX_MAX_CONF_ERRSTR;
966 966
967 va_start(args, fmt); 967 va_start(args, fmt);
968 buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); 968 p = ngx_vsnprintf(errstr, last - errstr, fmt, args);
969 va_end(args); 969 va_end(args);
970 970
971 *buf = '\0';
972
973 if (err) { 971 if (err) {
974 buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err); 972
975 buf = ngx_strerror_r(err, buf, last - buf - 1); 973 if (p > last - 50) {
976 *buf++ = ')'; 974
977 *buf = '\0'; 975 /* leave a space for an error code */
976
977 p = last - 50;
978 *p++ = '.';
979 *p++ = '.';
980 *p++ = '.';
981 }
982
983 #if (NGX_WIN32)
984 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
985 ? " (%d: " : " (%Xd: ", err);
986 #else
987 p = ngx_snprintf(p, last - p, " (%d: ", err);
988 #endif
989
990 p = ngx_strerror_r(err, p, last - p);
991
992 *p++ = ')';
978 } 993 }
979 994
980 if (cf->conf_file == NULL) { 995 if (cf->conf_file == NULL) {
981 ngx_log_error(level, cf->log, 0, "%s", errstr); 996 ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
982 return; 997 return;
983 } 998 }
984 999
985 ngx_log_error(level, cf->log, 0, "%s in %s:%ui", 1000 ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
986 errstr, cf->conf_file->file.name.data, cf->conf_file->line); 1001 p - errstr, errstr,
1002 cf->conf_file->file.name.data, cf->conf_file->line);
987 } 1003 }
988 1004
989 1005
990 char * 1006 char *
991 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1007 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)