*) increase ngx_conf_log_error() buffer

*) always log an error code
This commit is contained in:
Igor Sysoev 2008-11-25 13:00:53 +00:00
parent 33930d82ce
commit ecbb69ad7f
2 changed files with 28 additions and 12 deletions

View File

@ -959,31 +959,47 @@ void ngx_cdecl
ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...) char *fmt, ...)
{ {
u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
va_list args; va_list args;
last = errstr + NGX_MAX_CONF_ERRSTR; last = errstr + NGX_MAX_CONF_ERRSTR;
va_start(args, fmt); va_start(args, fmt);
buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); p = ngx_vsnprintf(errstr, last - errstr, fmt, args);
va_end(args); va_end(args);
*buf = '\0';
if (err) { if (err) {
buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
buf = ngx_strerror_r(err, buf, last - buf - 1); if (p > last - 50) {
*buf++ = ')';
*buf = '\0'; /* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
#if (NGX_WIN32)
p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_snprintf(p, last - p, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
*p++ = ')';
} }
if (cf->conf_file == NULL) { if (cf->conf_file == NULL) {
ngx_log_error(level, cf->log, 0, "%s", errstr); ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
return; return;
} }
ngx_log_error(level, cf->log, 0, "%s in %s:%ui", ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
errstr, cf->conf_file->file.name.data, cf->conf_file->line); p - errstr, errstr,
cf->conf_file->file.name.data, cf->conf_file->line);
} }

View File

@ -71,7 +71,7 @@
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */ #define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
#define NGX_MAX_CONF_ERRSTR 256 #define NGX_MAX_CONF_ERRSTR 1024
struct ngx_command_s { struct ngx_command_s {