You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pc...@hyperreal.org on 1997/12/07 16:48:01 UTC
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 Changes Path
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.c 1997/11/06 21:54:08 1.43
+++ http_log.c 1997/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.h 1997/10/22 20:29:39 1.19
+++ http_log.h 1997/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