Update of /cvsroot/pywin32/pywin32/isapi/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28773
Modified Files:
PythonEng.cpp Utils.cpp Utils.h
Added Files:
.cvsignore pyISAPI_messages.mc
Log Message:
Write filter and extension errors to the event log - ones that happen
while Python is initializing are otherwise impossible to debug
--- NEW FILE: .cvsignore ---
pyISAPI_messages.h
Index: Utils.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/Utils.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Utils.cpp 26 Oct 2004 01:30:57 -0000 1.2
--- Utils.cpp 17 Jan 2007 04:40:12 -0000 1.3
***************
*** 29,32 ****
--- 29,36 ----
extern HINSTANCE g_hInstance;
+ static bool g_bRegisteredEventSource = false;
+
+ static WCHAR *source_name = L"ISAPI Filter or Extension";
+
// returns the pathname of this module
***************
*** 91,92 ****
--- 95,162 ----
return result;
}
+
+ // register the event source with the event log.
+ static void CheckRegisterEventSourceFile()
+ {
+ WCHAR mod_name[MAX_PATH] = L"";
+ if (g_bRegisteredEventSource)
+ return;
+
+ GetModuleFileNameW(g_hInstance, mod_name,
+ sizeof mod_name/sizeof WCHAR);
+ if (!mod_name[0]) {
+ OutputDebugString("GetModuleFileNameW failed!");
+ return;
+ }
+
+ HKEY hkey;
+ WCHAR keyName[MAX_PATH];
+
+ wcscpy(keyName, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+ wcscat(keyName, source_name);
+
+ BOOL rc = FALSE;
+ if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+ keyName,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL,
+ &hkey,
+ NULL) == ERROR_SUCCESS) {
+ RegSetValueExW(hkey, L"EventMessageFile", 0, REG_SZ,
+ (const BYTE *)mod_name,
+ wcslen(mod_name)*sizeof(WCHAR));
+ DWORD types = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+ RegSetValueExW(hkey, L"TypesSupported", 0, REG_DWORD,
+ (const BYTE *)&types, sizeof(types));
+ RegCloseKey(hkey);
+ }
+ g_bRegisteredEventSource = true;
+ }
+
+ // Write stuff to the event log.
+ BOOL WriteEventLogMessage(WORD eventType, DWORD eventID, WORD num_inserts,
+ const char **inserts)
+ {
+ BOOL ok = FALSE;
+ HANDLE hEventSource;
+
+ CheckRegisterEventSourceFile();
+
+ hEventSource = RegisterEventSourceW(NULL, source_name);
+ if (hEventSource) {
+ ReportEvent(hEventSource, // handle of event source
+ eventType, // event type
+ 0, // event category
+ eventID, // event ID
+ NULL, // current user's SID
+ num_inserts, // strings in lpszStrings
+ 0, // no bytes of raw data
+ inserts, // array of error strings
+ NULL); // no raw data
+ DeregisterEventSource(hEventSource);
+ ok = TRUE;
+ }
+ return ok;
+ }
Index: PythonEng.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/PythonEng.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PythonEng.cpp 11 Oct 2006 07:55:10 -0000 1.4
--- PythonEng.cpp 17 Jan 2007 04:40:12 -0000 1.5
***************
*** 32,35 ****
--- 32,36 ----
#include "pyExtensionObjects.h"
#include "pyFilterObjects.h"
+ #include "pyISAPI_messages.h"
extern HINSTANCE g_hInstance;
***************
*** 375,378 ****
--- 376,382 ----
}
}
+ const char *inserts[] = {errmsg, windows_error ? windows_error : "n/a"};
+ WriteEventLogMessage(EVENTLOG_ERROR_TYPE, E_PYISAPI_EXTENSION_FAILED,
+ 2, inserts);
if (windows_error)
free(windows_error);
***************
*** 381,384 ****
--- 385,391 ----
void FilterError(CFilterContext *pfc, LPCTSTR errmsg)
{
+ char *windows_error = ::GetLastError() ?
+ ::FormatSysError(::GetLastError()) : NULL;
+
CEnterLeavePython celp;
PySys_WriteStderr("Internal Filter Error: %s\n", errmsg);
***************
*** 387,390 ****
--- 394,402 ----
PyErr_Clear();
}
+ const char *inserts[] = {errmsg, windows_error ? windows_error : "n/a"};
+ WriteEventLogMessage(EVENTLOG_ERROR_TYPE, E_PYISAPI_FILTER_FAILED,
+ 2, inserts);
+ if (windows_error)
+ free(windows_error);
// what else to do here? AddResponseHeaders->WriteClient?
}
--- NEW FILE: pyISAPI_messages.mc ---
; /*
MessageIdTypedef=DWORD
;-------------------------------------------------------------------------
; MESSAGE DEFINITION SECTION
;
; Following the header section is the body of the Message Compiler
; source file. The body consists of zero or more message definitions.
; Each message definition begins with one or more of the following
; statements:
;
; MessageId = [number|+number]
; Severity = severity_name
; Facility = facility_name
; SymbolicName = name
;
; The MessageId statement marks the beginning of the message
; definition. A MessageID statement is required for each message,
; although the value is optional. If no value is specified, the value
; used is the previous value for the facility plus one. If the value
; is specified as +number then the value used is the previous value
; for the facility, plus the number after the plus sign. Otherwise, if
; a numeric value is given, that value is used. Any MessageId value
; that does not fit in 16 bits is an error.
;
; The Severity and Facility statements are optional. These statements
; specify additional bits to OR into the final 32-bit message code. If
; not specified they default to the value last specified for a message
; definition. The initial values prior to processing the first message
; definition are:
;
; Severity=Success
; Facility=Application
;
; The value associated with Severity and Facility must match one of
; the names given in the FacilityNames and SeverityNames statements in
; the header section. The SymbolicName statement allows you to
; associate a C/C++ symbolic constant with the final 32-bit message
; code.
; */
; // For the sake of keeping common message-IDs with the pywin32 service
; // modules etc, we keep these generic messages
MessageId=0xFF
Severity=Error
SymbolicName=PYS_E_GENERIC_ERROR
Language=English
%1
.
MessageId=0xFF
Severity=Warning
SymbolicName=PYS_E_GENERIC_WARNING
Language=English
%1
.
MessageId=0x1000
Severity=Error
SymbolicName=E_PYISAPI_FILTER_FAILED
Language=English
The pyISAPI filter encountered an error.
%n%1
%nThe last windows error was: %2
.
MessageId=0x1001
Severity=Error
SymbolicName=E_PYISAPI_EXTENSION_FAILED
Language=English
The pyISAPI extension encountered an error.
%n%1
%nThe last windows error was: %2
.
; // A nod to py2exe or similar tools
MessageId=0x1100
Severity=Error
SymbolicName=E_PYISAPI_STARTUP_FAILED
Language=English
The pyISAPI extension failed to initialize.
%n%1
%nThe last windows error was: %2
.
Index: Utils.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/Utils.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Utils.h 6 Oct 2004 05:11:54 -0000 1.1
--- Utils.h 17 Jan 2007 04:40:12 -0000 1.2
***************
*** 58,61 ****
char *GetModulePath(void);
! #endif // __UTILS_H
\ No newline at end of file
--- 58,64 ----
char *GetModulePath(void);
+ // Write entry to the event log
+ BOOL WriteEventLogMessage(WORD eventType, DWORD eventID, WORD num_inserts,
+ const char **inserts);
! #endif // __UTILS_H
|