Make EventLog and Spooler services report their status to the SCM.
authorEric Kohl <eric.kohl@reactos.org>
Sat, 20 Feb 2010 12:59:53 +0000 (12:59 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 20 Feb 2010 12:59:53 +0000 (12:59 +0000)
svn path=/trunk/; revision=45632

reactos/base/services/eventlog/eventlog.c
reactos/base/services/spoolsv/spoolsv.c

index 9a2ddab..4f0120a 100644 (file)
 
 /* GLOBALS ******************************************************************/
 
-VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv);
-
-SERVICE_TABLE_ENTRY ServiceTable[2] =
+static VOID CALLBACK ServiceMain(DWORD, LPWSTR *);
+static WCHAR ServiceName[] = L"EventLog";
+static SERVICE_TABLE_ENTRYW ServiceTable[2] =
 {
-    { L"EventLog", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
+    { ServiceName, ServiceMain },
     { NULL, NULL }
 };
 
@@ -26,7 +26,20 @@ HANDLE MyHeap = NULL;
 
 /* FUNCTIONS ****************************************************************/
 
-VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv)
+static DWORD WINAPI
+ServiceControlHandler(DWORD dwControl,
+                      DWORD dwEventType,
+                      LPVOID lpEventData,
+                      LPVOID lpContext)
+{
+    /* FIXME */
+    DPRINT1("ServiceControlHandler() called (control code %lu)\n", dwControl);
+    return ERROR_SUCCESS;
+}
+
+
+static DWORD
+ServiceInit(VOID)
 {
     HANDLE hThread;
 
@@ -39,7 +52,10 @@ VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv)
                            NULL);
 
     if (!hThread)
+    {
         DPRINT("Can't create PortThread\n");
+        return GetLastError();
+    }
     else
         CloseHandle(hThread);
 
@@ -52,11 +68,69 @@ VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv)
                            NULL);
 
     if (!hThread)
+    {
         DPRINT("Can't create RpcThread\n");
+        return GetLastError();
+    }
     else
         CloseHandle(hThread);
+
+    return ERROR_SUCCESS;
+}
+
+
+static VOID CALLBACK
+ServiceMain(DWORD argc,
+            LPWSTR *argv)
+{
+    SERVICE_STATUS ServiceStatus;
+    SERVICE_STATUS_HANDLE ServiceStatusHandle;
+    DWORD dwError;
+
+    UNREFERENCED_PARAMETER(argc);
+    UNREFERENCED_PARAMETER(argv);
+
+    DPRINT("ServiceMain() called\n");
+
+    ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
+                                                        ServiceControlHandler,
+                                                        NULL);
+    if (!ServiceStatusHandle)
+    {
+        dwError = GetLastError();
+        DPRINT1("RegisterServiceCtrlHandlerW() failed! (Error %lu)\n", dwError);
+        return;
+    }
+
+    ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+    ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
+    ServiceStatus.dwControlsAccepted = 0;
+    ServiceStatus.dwWin32ExitCode = NO_ERROR;
+    ServiceStatus.dwServiceSpecificExitCode = 0;
+    ServiceStatus.dwCheckPoint = 0;
+    ServiceStatus.dwWaitHint = 2000;
+
+    SetServiceStatus(ServiceStatusHandle,
+                     &ServiceStatus);
+
+    dwError = ServiceInit();
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Service stopped\n");
+        ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+    }
+    else
+    {
+        ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+    }
+
+    SetServiceStatus(ServiceStatusHandle,
+                     &ServiceStatus);
+
+    DPRINT("ServiceMain() done\n");
 }
 
+
 BOOL LoadLogFile(HKEY hKey, WCHAR * LogName)
 {
     DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
index 98b890d..398e565 100644 (file)
@@ -18,7 +18,13 @@ WINE_DEFAULT_DEBUG_CHANNEL(spoolsv);
 
 /* GLOBALS ******************************************************************/
 
-#define SERVICE_NAME TEXT("Spooler")
+static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
+static WCHAR ServiceName[] = L"Spooler";
+static SERVICE_TABLE_ENTRYW ServiceTable[] =
+{
+    {ServiceName, ServiceMain},
+    {NULL, NULL}
+};
 
 SERVICE_STATUS_HANDLE ServiceStatusHandle;
 SERVICE_STATUS ServiceStatus;
@@ -100,14 +106,14 @@ ServiceControlHandler(DWORD dwControl,
 
 
 static VOID CALLBACK
-ServiceMain(DWORD argc, LPTSTR *argv)
+ServiceMain(DWORD argc, LPWSTR *argv)
 {
     UNREFERENCED_PARAMETER(argc);
     UNREFERENCED_PARAMETER(argv);
 
     TRACE("ServiceMain() called\n");
 
-    ServiceStatusHandle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
+    ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
                                                         ServiceControlHandler,
                                                         NULL);
 
@@ -123,12 +129,6 @@ ServiceMain(DWORD argc, LPTSTR *argv)
 int
 wmain(int argc, WCHAR *argv[])
 {
-    SERVICE_TABLE_ENTRY ServiceTable[2] =
-    {
-        {SERVICE_NAME, ServiceMain},
-        {NULL, NULL}
-    };
-
     UNREFERENCED_PARAMETER(argc);
     UNREFERENCED_PARAMETER(argv);
 
@@ -138,8 +138,6 @@ wmain(int argc, WCHAR *argv[])
 
     TRACE("Spoolsv: main() done\n");
 
-    ExitThread(0);
-
     return 0;
 }