From: Eric Kohl Date: Mon, 12 Feb 2018 13:58:02 +0000 (+0100) Subject: [SERVICES] Fix the initial service status X-Git-Tag: 0.4.9-dev~27 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=e917471e0457e949800f4246a6465b4fa735af48 [SERVICES] Fix the initial service status - The initial dwWin32ExitCode for a disabled service is ERROR_SERVICE_DISABLED and ERROR_SRVICE_NEVER_STARTED for non-disabled services. - The initial dwWaitHint is 2000 (2 seconds) for (user-mode) services and 0 for drivers. - Move all driver-related code to driver.c. --- diff --git a/base/system/services/database.c b/base/system/services/database.c index 19c4e05724e..b450fe486d4 100644 --- a/base/system/services/database.c +++ b/base/system/services/database.c @@ -559,7 +559,9 @@ ScmGetServiceEntryByResumeCount(DWORD dwResumeCount) DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName, - PSERVICE* lpServiceRecord) + PSERVICE *lpServiceRecord, + DWORD dwServiceType, + DWORD dwStartType) { PSERVICE lpService = NULL; @@ -579,6 +581,9 @@ ScmCreateNewServiceRecord(LPCWSTR lpServiceName, lpService->lpServiceName = lpService->szServiceName; lpService->lpDisplayName = lpService->lpServiceName; + /* Set the start type */ + lpService->dwStartType = dwStartType; + /* Set the resume count */ lpService->dwResumeCount = ResumeCount++; @@ -587,12 +592,15 @@ ScmCreateNewServiceRecord(LPCWSTR lpServiceName, &lpService->ServiceListEntry); /* Initialize the service status */ + lpService->Status.dwServiceType = dwServiceType; lpService->Status.dwCurrentState = SERVICE_STOPPED; lpService->Status.dwControlsAccepted = 0; - lpService->Status.dwWin32ExitCode = ERROR_SERVICE_NEVER_STARTED; + lpService->Status.dwWin32ExitCode = + (dwStartType == SERVICE_DISABLED) ? ERROR_SERVICE_DISABLED : ERROR_SERVICE_NEVER_STARTED; lpService->Status.dwServiceSpecificExitCode = 0; lpService->Status.dwCheckPoint = 0; - lpService->Status.dwWaitHint = 2000; /* 2 seconds */ + lpService->Status.dwWaitHint = + (dwServiceType & SERVICE_DRIVER) ? 0 : 2000; /* 2 seconds */ return ERROR_SUCCESS; } @@ -719,12 +727,12 @@ CreateServiceListEntry(LPCWSTR lpServiceName, DPRINT("Display name: %S\n", lpDisplayName); dwError = ScmCreateNewServiceRecord(lpServiceName, - &lpService); + &lpService, + dwServiceType, + dwStartType); if (dwError != ERROR_SUCCESS) goto done; - lpService->Status.dwServiceType = dwServiceType; - lpService->dwStartType = dwStartType; lpService->dwErrorControl = dwErrorControl; lpService->dwTag = dwTagId; @@ -1801,13 +1809,8 @@ ScmLoadService(PSERVICE Service, if (Service->Status.dwServiceType & SERVICE_DRIVER) { - /* Load driver */ - dwError = ScmLoadDriver(Service); - if (dwError == ERROR_SUCCESS) - { - Service->Status.dwCurrentState = SERVICE_RUNNING; - Service->Status.dwControlsAccepted = SERVICE_ACCEPT_STOP; - } + /* Start the driver */ + dwError = ScmStartDriver(Service); } else // if (Service->Status.dwServiceType & (SERVICE_WIN32 | SERVICE_INTERACTIVE_PROCESS)) { diff --git a/base/system/services/driver.c b/base/system/services/driver.c index de8bfc1aa3e..819183e5c04 100644 --- a/base/system/services/driver.c +++ b/base/system/services/driver.c @@ -19,6 +19,7 @@ /* FUNCTIONS ****************************************************************/ +static DWORD ScmLoadDriver(PSERVICE lpService) { @@ -70,7 +71,7 @@ done: return RtlNtStatusToDosError(Status); } - +static DWORD ScmUnloadDriver(PSERVICE lpService) { @@ -123,6 +124,7 @@ done: } +static DWORD ScmGetDriverStatus(PSERVICE lpService, LPSERVICE_STATUS lpServiceStatus) @@ -285,6 +287,27 @@ ScmGetDriverStatus(PSERVICE lpService, } +DWORD +ScmStartDriver(PSERVICE pService) +{ + DWORD dwError; + + DPRINT("ScmStartDriver(%p)\n", pService); + + dwError = ScmLoadDriver(pService); + if (dwError == ERROR_SUCCESS) + { + pService->Status.dwCurrentState = SERVICE_RUNNING; + pService->Status.dwControlsAccepted = SERVICE_ACCEPT_STOP; + pService->Status.dwWin32ExitCode = ERROR_SUCCESS; + } + + DPRINT("ScmStartDriver returns %lu\n", dwError); + + return dwError; +} + + DWORD ScmControlDriver(PSERVICE lpService, DWORD dwControl, @@ -328,7 +351,7 @@ ScmControlDriver(PSERVICE lpService, dwError = ERROR_INVALID_SERVICE_CONTROL; } -done:; +done: DPRINT("ScmControlDriver() done (Erorr: %lu)\n", dwError); return dwError; diff --git a/base/system/services/rpcserver.c b/base/system/services/rpcserver.c index f1ce146a926..a4718aa15f2 100644 --- a/base/system/services/rpcserver.c +++ b/base/system/services/rpcserver.c @@ -2279,13 +2279,13 @@ RCreateServiceW( /* Allocate a new service entry */ dwError = ScmCreateNewServiceRecord(lpServiceName, - &lpService); + &lpService, + dwServiceType, + dwStartType); if (dwError != ERROR_SUCCESS) goto done; /* Fill the new service entry */ - lpService->Status.dwServiceType = dwServiceType; - lpService->dwStartType = dwStartType; lpService->dwErrorControl = dwErrorControl; /* Fill the display name */ diff --git a/base/system/services/services.h b/base/system/services/services.h index 1d20f120d1d..0f038499670 100644 --- a/base/system/services/services.h +++ b/base/system/services/services.h @@ -168,7 +168,9 @@ PSERVICE ScmGetServiceEntryByName(LPCWSTR lpServiceName); PSERVICE ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName); PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount); DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName, - PSERVICE *lpServiceRecord); + PSERVICE *lpServiceRecord, + DWORD dwServiceType, + DWORD dwStartType); VOID ScmDeleteServiceRecord(PSERVICE lpService); DWORD ScmMarkServiceForDelete(PSERVICE pService); @@ -185,8 +187,7 @@ VOID ScmDeleteNamedPipeCriticalSection(VOID); /* driver.c */ -DWORD ScmLoadDriver(PSERVICE lpService); -DWORD ScmUnloadDriver(PSERVICE lpService); +DWORD ScmStartDriver(PSERVICE lpService); DWORD ScmControlDriver(PSERVICE lpService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus);