diff --git a/src/dll/eventlog.c b/src/dll/eventlog.c index fb992e9b..c8f3cd0c 100644 --- a/src/dll/eventlog.c +++ b/src/dll/eventlog.c @@ -40,12 +40,51 @@ FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap) WCHAR Buf[1024], *Strings[1]; /* wvsprintfW is only safe with a 1024 WCHAR buffer */ + DWORD EventId; wvsprintfW(Buf, Format, ap); Buf[(sizeof Buf / sizeof Buf[0]) - 1] = L'\0'; - Strings[0] = Buf; - ReportEventW(FspEventLogHandle, (WORD)Type, 0, 1, 0, 1, 0, Strings, 0); + + /* + * Event Identifier Format: + * + * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +---+-+-+-----------------------+-------------------------------+ + * |Sev|C|R| Facility | Code | + * +---+-+-+-----------------------+-------------------------------+ + * + * Sev - Severity: + * 00 - Success + * 01 - Informational + * 10 - Warning + * 11 - Error + * + * C - Customer: + * 0 - System code + * 1 - Customer code + * + * R - Reserved + * + * See https://msdn.microsoft.com/en-us/library/windows/desktop/aa363651(v=vs.85).aspx + */ + switch (Type) + { + case EVENTLOG_ERROR_TYPE: + EventId = 0xd0000001; + break; + case EVENTLOG_WARNING_TYPE: + EventId = 0xc0000001; + break; + case EVENTLOG_INFORMATION_TYPE: + case EVENTLOG_SUCCESS: + default: + EventId = 0x60000001; + break; + } + + ReportEventW(FspEventLogHandle, (WORD)Type, 0, EventId, 0, 1, 0, Strings, 0); } static BOOL WINAPI FspEventLogRegisterEventSource( diff --git a/src/dll/service.c b/src/dll/service.c index 6f163611..00cfe103 100644 --- a/src/dll/service.c +++ b/src/dll/service.c @@ -17,9 +17,6 @@ #include -// !!!: NOTIMPLEMENTED -#define FspEventLog(Type, Message, ...) - enum { SetStatus_ServiceType = 0x0001, @@ -252,6 +249,9 @@ FSP_API VOID FspServiceStop(FSP_SERVICE *Service) ServiceStatus.dwWin32ExitCode = Service->ExitCode; FspServiceSetStatus(Service, SetStatus_CurrentState | SetStatus_Win32ExitCode, &ServiceStatus); + + FspEventLog(EVENTLOG_INFORMATION_TYPE, + L"The service %s has been stopped.", Service->ServiceName); } else { @@ -259,6 +259,9 @@ FSP_API VOID FspServiceStop(FSP_SERVICE *Service) FspServiceSetStatus(Service, SetStatus_CurrentState | SetStatus_CheckPoint | SetStatus_WaitHint, &ServiceStatus); + + FspEventLog(EVENTLOG_ERROR_TYPE, + L"The service %s has failed to stop (Status=%lx).", Service->ServiceName, Result); } } @@ -309,6 +312,9 @@ static VOID FspServiceMain(FSP_SERVICE *Service, DWORD Argc, PWSTR *Argv) ServiceStatus.dwControlsAccepted = Service->AcceptControl; FspServiceSetStatus(Service, SetStatus_CurrentState | SetStatus_ControlsAccepted, &ServiceStatus); + + FspEventLog(EVENTLOG_INFORMATION_TYPE, + L"The service %s has been started.", Service->ServiceName); } else { @@ -316,6 +322,9 @@ static VOID FspServiceMain(FSP_SERVICE *Service, DWORD Argc, PWSTR *Argv) ServiceStatus.dwWin32ExitCode = FspWin32FromNtStatus(Result); FspServiceSetStatus(Service, SetStatus_CurrentState | SetStatus_Win32ExitCode, &ServiceStatus); + + FspEventLog(EVENTLOG_ERROR_TYPE, + L"The service %s has failed to start (Status=%lx).", Service->ServiceName, Result); } }