[SERVICES]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 28 Sep 2014 14:10:16 +0000 (14:10 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 28 Sep 2014 14:10:16 +0000 (14:10 +0000)
Log service start, control and status change events.

svn path=/trunk/; revision=64364

reactos/base/system/services/database.c
reactos/base/system/services/rpcserver.c
reactos/base/system/services/services.c
reactos/base/system/services/services.h

index e4202a7..4ae8473 100644 (file)
@@ -1456,6 +1456,19 @@ ScmWaitForServiceConnect(PSERVICE Service)
             return dwError;
         }
     }
             return dwError;
         }
     }
+    else
+    {
+        if (dwProcessId != Service->lpImage->dwProcessId)
+        {
+/*
+            LPWSTR Strings[3]
+
+            ScmLogError(EVENT_SERVICE_DIFFERENT_PID_CONNECTED,
+                        3,
+                        lpStrings);
+*/
+        }
+    }
 
     DPRINT("ScmWaitForServiceConnect() done\n");
 
 
     DPRINT("ScmWaitForServiceConnect() done\n");
 
@@ -1578,7 +1591,7 @@ ScmLoadService(PSERVICE Service,
 {
     PSERVICE_GROUP Group = Service->lpGroup;
     DWORD dwError = ERROR_SUCCESS;
 {
     PSERVICE_GROUP Group = Service->lpGroup;
     DWORD dwError = ERROR_SUCCESS;
-    LPCWSTR ErrorLogStrings[2];
+    LPCWSTR lpErrorStrings[2];
     WCHAR szErrorBuffer[32];
 
     DPRINT("ScmLoadService() called\n");
     WCHAR szErrorBuffer[32];
 
     DPRINT("ScmLoadService() called\n");
@@ -1633,6 +1646,14 @@ ScmLoadService(PSERVICE Service,
         {
             Group->ServicesRunning = TRUE;
         }
         {
             Group->ServicesRunning = TRUE;
         }
+
+        /* Log a successful service start */
+        lpErrorStrings[0] = Service->lpDisplayName;
+        lpErrorStrings[1] = L"start";
+        ScmLogEvent(EVENT_SERVICE_CONTROL_SUCCESS,
+                    EVENTLOG_INFORMATION_TYPE,
+                    2,
+                    lpErrorStrings);
     }
     else
     {
     }
     else
     {
@@ -1640,11 +1661,12 @@ ScmLoadService(PSERVICE Service,
         {
             /* Log a failed service start */
             swprintf(szErrorBuffer, L"%lu", dwError);
         {
             /* Log a failed service start */
             swprintf(szErrorBuffer, L"%lu", dwError);
-            ErrorLogStrings[0] = Service->lpServiceName;
-            ErrorLogStrings[1] = szErrorBuffer;
-            ScmLogError(EVENT_SERVICE_START_FAILED,
+            lpErrorStrings[0] = Service->lpServiceName;
+            lpErrorStrings[1] = szErrorBuffer;
+            ScmLogEvent(EVENT_SERVICE_START_FAILED,
+                        EVENTLOG_ERROR_TYPE,
                         2,
                         2,
-                        ErrorLogStrings);
+                        lpErrorStrings);
         }
 
 #if 0
         }
 
 #if 0
index 692628a..08f5336 100644 (file)
@@ -1085,6 +1085,7 @@ DWORD RControlService(
     DWORD dwControlsAccepted;
     DWORD dwCurrentState;
     HKEY hServicesKey = NULL;
     DWORD dwControlsAccepted;
     DWORD dwCurrentState;
     HKEY hServicesKey = NULL;
+    LPCWSTR lpErrorStrings[2];
 
     DPRINT("RControlService() called\n");
 
 
     DPRINT("RControlService() called\n");
 
@@ -1242,6 +1243,39 @@ DWORD RControlService(
                       sizeof(SERVICE_STATUS));
     }
 
                       sizeof(SERVICE_STATUS));
     }
 
+    if (dwError == ERROR_SUCCESS)
+    {
+            if (dwControl != SERVICE_CONTROL_INTERROGATE)
+            {
+                /* Log a sucessful send control */
+                lpErrorStrings[0] = lpService->lpDisplayName;
+
+                switch(dwControl)
+                {
+                    case SERVICE_CONTROL_STOP:
+                        lpErrorStrings[1] = L"stop";
+                        break;
+
+                    case SERVICE_CONTROL_PAUSE:
+                        lpErrorStrings[1] = L"pause";
+                        break;
+
+                    case SERVICE_CONTROL_CONTINUE:
+                        lpErrorStrings[1] = L"continue";
+                        break;
+
+                    default:
+                        lpErrorStrings[1] = L"other";
+                        break;
+                }
+
+                ScmLogEvent(EVENT_SERVICE_CONTROL_SUCCESS,
+                            EVENTLOG_INFORMATION_TYPE,
+                            2,
+                            lpErrorStrings);
+            }
+    }
+
     return dwError;
 }
 
     return dwError;
 }
 
@@ -1691,20 +1725,47 @@ DWORD RSetServiceStatus(
     /* Unlock the service database */
     ScmUnlockDatabase();
 
     /* Unlock the service database */
     ScmUnlockDatabase();
 
-    /* Log a failed service stop */
     if ((lpServiceStatus->dwCurrentState == SERVICE_STOPPED) &&
     if ((lpServiceStatus->dwCurrentState == SERVICE_STOPPED) &&
-        (dwPreviousState != SERVICE_STOPPED))
+        (dwPreviousState != SERVICE_STOPPED) &&
+        (lpServiceStatus->dwWin32ExitCode != ERROR_SUCCESS))
+    {
+        /* Log a failed service stop */
+        swprintf(szErrorBuffer, L"%lu", lpServiceStatus->dwWin32ExitCode);
+        lpErrorStrings[0] = lpService->lpDisplayName;
+        lpErrorStrings[1] = szErrorBuffer;
+
+        ScmLogEvent(EVENT_SERVICE_EXIT_FAILED,
+                    EVENTLOG_ERROR_TYPE,
+                    2,
+                    lpErrorStrings);
+    }
+    else if (lpServiceStatus->dwCurrentState != dwPreviousState &&
+             (lpServiceStatus->dwCurrentState == SERVICE_STOPPED ||
+              lpServiceStatus->dwCurrentState == SERVICE_RUNNING ||
+              lpServiceStatus->dwCurrentState == SERVICE_PAUSED))
     {
     {
-        if (lpServiceStatus->dwWin32ExitCode != ERROR_SUCCESS)
+        /* Log a successful service status change */
+        lpErrorStrings[0] = lpService->lpDisplayName;
+
+        switch(lpServiceStatus->dwCurrentState)
         {
         {
-            swprintf(szErrorBuffer, L"%lu", lpServiceStatus->dwWin32ExitCode);
-            lpErrorStrings[0] = lpService->lpDisplayName;
-            lpErrorStrings[1] = szErrorBuffer;
+            case SERVICE_STOPPED:
+                lpErrorStrings[1] = L"stopped";
+                break;
 
 
-            ScmLogError(EVENT_SERVICE_EXIT_FAILED,
-                        2,
-                        lpErrorStrings);
+            case SERVICE_RUNNING:
+                lpErrorStrings[1] = L"running";
+                break;
+
+            case SERVICE_PAUSED:
+                lpErrorStrings[1] = L"paused";
+                break;
         }
         }
+
+        ScmLogEvent(EVENT_SERVICE_STATUS_SUCCESS,
+                    EVENTLOG_INFORMATION_TYPE,
+                    2,
+                    lpErrorStrings);
     }
 
     DPRINT("Set %S to %lu\n", lpService->lpDisplayName, lpService->Status.dwCurrentState);
     }
 
     DPRINT("Set %S to %lu\n", lpService->lpDisplayName, lpService->Status.dwCurrentState);
index a288baf..9290c59 100644 (file)
@@ -53,7 +53,8 @@ PrintString(LPCSTR fmt, ...)
 
 
 VOID
 
 
 VOID
-ScmLogError(DWORD dwEventId,
+ScmLogEvent(DWORD dwEventId,
+            WORD wType,
             WORD wStrings,
             LPCWSTR *lpStrings)
 {
             WORD wStrings,
             LPCWSTR *lpStrings)
 {
@@ -68,10 +69,10 @@ ScmLogError(DWORD dwEventId,
     }
 
     if (!ReportEventW(hLog,
     }
 
     if (!ReportEventW(hLog,
-                      EVENTLOG_ERROR_TYPE,
+                      wType,
                       0,
                       dwEventId,
                       0,
                       dwEventId,
-                      NULL, // Sid,
+                      NULL,
                       wStrings,
                       0,
                       lpStrings,
                       wStrings,
                       0,
                       lpStrings,
index 2eac817..604e7e4 100644 (file)
@@ -175,6 +175,7 @@ DWORD ScmSetServiceGroup(PSERVICE lpService,
 
 
 /* lock.c */
 
 
 /* lock.c */
+
 DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController,
                                  OUT LPSC_RPC_LOCK lpLock);
 DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock);
 DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController,
                                  OUT LPSC_RPC_LOCK lpLock);
 DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock);
@@ -190,7 +191,8 @@ VOID ScmStartRpcServer(VOID);
 /* services.c */
 
 VOID PrintString(LPCSTR fmt, ...);
 /* services.c */
 
 VOID PrintString(LPCSTR fmt, ...);
-VOID ScmLogError(DWORD dwEventId,
+VOID ScmLogEvent(DWORD dwEventId,
+                 WORD wType,
                  WORD wStrings,
                  LPCWSTR *lpStrings);
 VOID ScmWaitForLsa(VOID);
                  WORD wStrings,
                  LPCWSTR *lpStrings);
 VOID ScmWaitForLsa(VOID);