cvs commit: apachen/src/main http_log.c http_log.h
pcs 98/01/04 08:35:29 Modified:src/main http_log.c http_log.h Log: Fix removing errno from APLOG_WIN32ERROR error messages. Revision ChangesPath 1.46 +5 -1 apachen/src/main/http_log.c Index: http_log.c === RCS file: /export/home/cvs/apachen/src/main/http_log.c,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- http_log.c1998/01/03 00:18:38 1.45 +++ http_log.c1998/01/04 16:35:28 1.46 @@ -315,7 +315,11 @@ len += ap_snprintf(errstr + len, sizeof(errstr) - len, %s(%d): , file, line); } -if (!(level APLOG_NOERRNO)) { +if (!(level APLOG_NOERRNO) +#ifdef WIN32 + !(level APLOG_WIN32ERROR) +#endif + ) { len += ap_snprintf(errstr + len, sizeof(errstr) - len, (%d)%s: , save_errno, strerror(save_errno)); } 1.22 +1 -1 apachen/src/main/http_log.h Index: http_log.h === RCS file: /export/home/cvs/apachen/src/main/http_log.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- http_log.h1998/01/04 14:21:55 1.21 +++ http_log.h1998/01/04 16:35:28 1.22 @@ -84,7 +84,7 @@ #ifdef WIN32 /* Set to indicate that error msg should come from Win32's GetLastError(), * not errno. */ -#define APLOG_WIN32ERROR ((APLOG_LEVELMASK+1) * 2|APLOG_NOERRNO) +#define APLOG_WIN32ERROR ((APLOG_LEVELMASK+1) * 2) #endif #ifndef DEFAULT_LOGLEVEL
cvs commit: apachen/src/main http_log.c http_log.h
pcs 97/12/07 07:48:01 Modified:src/main http_log.c http_log.h Log: The current aplog_error() function cannot report on errors returned by Win32 functions. These functions do not bother setting errno - instead, you have to make a call to GetLastError() to get the error code, then call FormatMessage() to get the corresponding string. I already added code to do this in os/win32/service.c, but this was specific to reporting errors to standard error during apache -i or -u calls. The patch below updates aplog_error() to enable generic logging of Win32 errors to the same place as other errors. It adds a new flag, APLOG_WIN32ERROR which if given in the _second_ argument to aplog_error() causes the Win32 error code and error string to be logged. Here is an example call (this is from worker_main()): if (SetEvent(ev[i]) == 0) aplog_error(APLOG_MARK,APLOG_WIN32ERROR, server_conf, SetEvent for child process in slot #%d, i); Reviewed by: Ben Laurie, Martin Kraemer Revision ChangesPath 1.44 +43 -0 apachen/src/main/http_log.c Index: http_log.c === RCS file: /export/home/cvs/apachen/src/main/http_log.c,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- http_log.c1997/11/06 21:54:08 1.43 +++ http_log.c1997/12/07 15:47:59 1.44 @@ -319,6 +319,49 @@ len += ap_snprintf(errstr + len, sizeof(errstr) - len, (%d)%s: , save_errno, strerror(save_errno)); } +#ifdef WIN32 +if (level APLOG_WIN32ERROR) { + int nChars; + int nErrorCode; + + nErrorCode = GetLastError(); + len += ap_snprintf(errstr + len, sizeof(errstr) - len, + (%d), nErrorCode); + + nChars = FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + nErrorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) errstr + len, + sizeof(errstr) - len, + NULL + ); + len += nChars; + if (nChars == 0) { + /* Um, error occurred, but we can't recurse to log it again + * (and it would probably only fail anyway), so lets just + * log the numeric value. + */ + nErrorCode = GetLastError(); + len += ap_snprintf(errstr + len, sizeof(errstr) - len, + (FormatMessage failed with code %d): , nErrorCode); + } + else { + /* FormatMessage put the message in the buffer, but it may + * have appended a newline (\r\n). So remove it and use + * : instead like the Unix errors. The error may also + * end with a . before the return - if so, trash it. + */ + if (len 1 errstr[len-2] == '\r' errstr[len-1] == '\n') { + if (len 2 errstr[len-3] == '.') + len--; + errstr[len-2] = ':'; + errstr[len-1] = ' '; + } + } +} +#endif va_start(args, fmt); len += ap_vsnprintf(errstr + len, sizeof(errstr) - len, fmt, args); 1.20 +5 -0 apachen/src/main/http_log.h Index: http_log.h === RCS file: /export/home/cvs/apachen/src/main/http_log.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- http_log.h1997/10/22 20:29:39 1.19 +++ http_log.h1997/12/07 15:48:00 1.20 @@ -81,6 +81,11 @@ #endif #define APLOG_NOERRNO(APLOG_LEVELMASK + 1) +#ifdef WIN32 +/* Set to indicate that error msg should come from Win32's GetLastError(), + * not errno. */ +#define APLOG_WIN32ERROR ((APLOG_LEVELMASK+1) * 2) +#endif #ifndef DEFAULT_LOGLEVEL #define DEFAULT_LOGLEVEL APLOG_ERR
cvs commit: apachen/src/main http_log.c http_log.h http_main.c
fielding97/10/05 00:47:48 Modified:src CHANGES src/main http_log.c http_log.h http_main.c Log: Reduce what is written by aplog_error() by excluding filename if it is NULL, line number if it is -, and errno if the new APLOG_NOERRNO bit is set in level parameter. Do it all with a lot less string copying -- use snprintf incrementally to build up the entire buffer. When server_conf is NULL use stderr, since that is necessary to do some things during startup and other odd cases (i.e. SEGV). Fixed a buffer overflow with syslog stuff using sprintf(). Submitted by: Ken Coar and Dean Gaudet Reviewed by: Roy Fielding Revision ChangesPath 1.457 +3 -0 apachen/src/CHANGES Index: CHANGES === RCS file: /export/home/cvs/apachen/src/CHANGES,v retrieving revision 1.456 retrieving revision 1.457 diff -u -r1.456 -r1.457 --- CHANGES 1997/10/05 02:22:22 1.456 +++ CHANGES 1997/10/05 07:47:41 1.457 @@ -168,6 +168,9 @@ on a per-server basis using the LogLevel directive. Conversion of log_*() in progress. [Randy Terbush] + *) Further enhance aplog_error() to not log filename, line number, and + errno information when it isn't applicable. [Ken Coar, Dean Gaudet] + *) Canonicalise filenames under Win32. Short filenames are converted to long ones. Backslashes are converted to forward slashes. Case is converted to lower. Parts of URLs that do not 1.36 +37 -29apachen/src/main/http_log.c Index: http_log.c === RCS file: /export/home/cvs/apachen/src/main/http_log.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- http_log.c1997/10/02 05:10:34 1.35 +++ http_log.c1997/10/05 07:47:45 1.36 @@ -280,48 +280,56 @@ va_list args; char errstr[MAX_STRING_LEN]; static TRANS *pname = priorities; - +size_t len; +int save_errno = errno; +FILE *logf; -if (level s-loglevel) +if (s (level APLOG_LEVELMASK) s-loglevel) return; -switch (s-loglevel) { -case APLOG_DEBUG: - ap_snprintf(errstr, sizeof(errstr), [%s] %d: %s: %s: %d: , - pname[level].t_name, errno, strerror(errno), file, line); - break; -case APLOG_EMERG: -case APLOG_CRIT: -case APLOG_ALERT: - ap_snprintf(errstr, sizeof(errstr), [%s] %d: %s: , - pname[level].t_name, errno, strerror(errno)); - break; -case APLOG_INFO: -case APLOG_ERR: -case APLOG_WARNING: -case APLOG_NOTICE: - ap_snprintf(errstr, sizeof(errstr), [%s] , pname[level].t_name); - break; +if (!s) { + logf = stderr; +} else if (s s-error_log) { + logf = s-error_log; +} else { + logf = NULL; +} + +if (logf) { + len = ap_snprintf(errstr, sizeof(errstr), [%s] , get_time()); +} else { + len = 0; +} + +len += ap_snprintf(errstr + len, sizeof(errstr) - len, + [%s] , pname[level APLOG_LEVELMASK].t_name); + +if (!(level APLOG_NOERRNO)) { + len += ap_snprintf(errstr + len, sizeof(errstr) - len, + %d: %s: , save_errno, strerror(save_errno)); } - +if (file (level APLOG_LEVELMASK) == APLOG_DEBUG) { + len += ap_snprintf(errstr + len, sizeof(errstr) - len, + %s: %d: , file, line); +} + va_start(args, fmt); +len += ap_vsnprintf(errstr + len, sizeof(errstr) - len, fmt, args); +va_end(args); /* NULL if we are logging to syslog */ -if (s-error_log) { - fprintf(s-error_log, [%s] %s, get_time(), errstr); - vfprintf(s-error_log, fmt, args); - fprintf(s-error_log, \n); - fflush(s-error_log); +if (logf) { + fputs(errstr, logf); + fputc('\n', logf); + fflush(logf); } #ifdef HAVE_SYSLOG else { - vsprintf(errstr + strlen(errstr), fmt, args); - syslog(level, %s, errstr); + syslog(level APLOG_LEVELMASK, %s, errstr); } #endif - -va_end(args); } + void log_pid (pool *p, char *pid_fname) { 1.14 +2 -0 apachen/src/main/http_log.h Index: http_log.h === RCS file: /export/home/cvs/apachen/src/main/http_log.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- http_log.h1997/09/12 20:13:08 1.13 +++ http_log.h1997/10/05 07:47:45 1.14 @@ -59,6 +59,8 @@ #define APLOG_INFO 6 /* informational */ #define APLOG_DEBUG 7 /* debug-level messages */ #define DEFAULT_LOGLEVEL APLOG_ERR