Index: base/system/services/database.c =================================================================== --- base/system/services/database.c (révision 56862) +++ base/system/services/database.c (copie de travail) @@ -1116,8 +1116,8 @@ DPRINT("ScmSendStartCommand() called\n"); /* Calculate the total length of the start command line */ - PacketSize = sizeof(SCM_CONTROL_PACKET); - PacketSize += (wcslen(Service->lpServiceName) + 1) * sizeof(WCHAR); + PacketSize = sizeof(SCM_CONTROL_PACKET) + + (wcslen(Service->lpServiceName) + 1) * sizeof(WCHAR); /* Calculate the required packet size for the start arguments */ if (argc > 0 && argv != NULL) @@ -1140,7 +1140,9 @@ return ERROR_NOT_ENOUGH_MEMORY; ControlPacket->dwSize = PacketSize; - ControlPacket->dwControl = SERVICE_CONTROL_START; + ControlPacket->dwControl = ( (Service->Status.dwServiceType & SERVICE_WIN32_OWN_PROCESS) + ? SERVICE_CONTROL_START_OWN + : SERVICE_CONTROL_START_SHARE ); ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service; ControlPacket->dwServiceNameOffset = sizeof(SCM_CONTROL_PACKET); Index: dll/win32/advapi32/service/sctrl.c =================================================================== --- dll/win32/advapi32/service/sctrl.c (révision 56862) +++ dll/win32/advapi32/service/sctrl.c (copie de travail) @@ -47,6 +47,7 @@ LPHANDLER_FUNCTION_EX HandlerFunctionEx; LPVOID HandlerContext; BOOL bUnicode; + BOOL bOwnProcess; } ACTIVE_SERVICE, *PACTIVE_SERVICE; @@ -142,6 +143,9 @@ TRACE("ScLookupServiceByServiceName(%S) called\n", lpServiceName); + if (lpActiveServices[0].bOwnProcess) + return &lpActiveServices[0]; + for (i = 0; i < dwActiveServiceCount; i++) { TRACE("Checking %S\n", lpActiveServices[i].ServiceName.Buffer); @@ -488,10 +492,9 @@ static BOOL ScServiceDispatcher(HANDLE hPipe, - PUCHAR lpBuffer, + PSCM_CONTROL_PACKET ControlPacket, DWORD dwBufferSize) { - PSCM_CONTROL_PACKET ControlPacket; DWORD Count; BOOL bResult; DWORD dwRunningServices = 0; @@ -502,18 +505,12 @@ TRACE("ScDispatcherLoop() called\n"); - ControlPacket = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - 1024); - if (ControlPacket == NULL) - return FALSE; - while (TRUE) { /* Read command from the control pipe */ bResult = ReadFile(hPipe, ControlPacket, - 1024, + dwBufferSize, &Count, NULL); if (bResult == FALSE) @@ -525,6 +522,9 @@ lpServiceName = (LPWSTR)((PBYTE)ControlPacket + ControlPacket->dwServiceNameOffset); TRACE("Service: %S\n", lpServiceName); + if (ControlPacket->dwControl == SERVICE_CONTROL_START_OWN) + lpActiveServices[0].bOwnProcess = TRUE; + lpService = ScLookupServiceByServiceName(lpServiceName); if (lpService != NULL) { @@ -532,6 +532,8 @@ switch (ControlPacket->dwControl) { case SERVICE_CONTROL_START: // Not used anymore + case SERVICE_CONTROL_START_SHARE: + case SERVICE_CONTROL_START_OWN: TRACE("Start command - recieved SERVICE_CONTROL_START\n"); dwError = ScStartService(lpService, ControlPacket); if (dwError == ERROR_SUCCESS) @@ -834,10 +836,12 @@ BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA * lpServiceStartTable) { + BOOL bRet = TRUE; ULONG i; HANDLE hPipe; DWORD dwError; - PUCHAR lpMessageBuffer; + PSCM_CONTROL_PACKET ControlPacket; + DWORD dwBufSize; TRACE("StartServiceCtrlDispatcherA() called\n"); @@ -864,50 +868,41 @@ lpActiveServices[i].ThreadParams.A.lpServiceMain = lpServiceStartTable[i].lpServiceProc; lpActiveServices[i].hServiceStatus = 0; lpActiveServices[i].bUnicode = FALSE; + lpActiveServices[i].bOwnProcess = FALSE; } dwError = ScConnectControlPipe(&hPipe); if (dwError != ERROR_SUCCESS) { - /* Free the service table */ - for (i = 0; i < dwActiveServiceCount; i++) - { - RtlFreeUnicodeString(&lpActiveServices[i].ServiceName); - } - RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices); - lpActiveServices = NULL; - dwActiveServiceCount = 0; - return FALSE; + bRet = FALSE; + goto Done; } - lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(), - HEAP_ZERO_MEMORY, - 256); - if (lpMessageBuffer == NULL) + dwBufSize = sizeof(SCM_CONTROL_PACKET) + + (MAX_SERVICE_NAME_LENGTH + 1) * sizeof(WCHAR); + + ControlPacket = (PSCM_CONTROL_PACKET)RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + dwBufSize); + if (ControlPacket == NULL) { - /* Free the service table */ - for (i = 0; i < dwActiveServiceCount; i++) - { - RtlFreeUnicodeString(&lpActiveServices[i].ServiceName); - } - RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices); - lpActiveServices = NULL; - dwActiveServiceCount = 0; CloseHandle(hPipe); - return FALSE; + bRet = FALSE; + goto Done; } ScCreateStatusBinding(); - ScServiceDispatcher(hPipe, lpMessageBuffer, 256); + ScServiceDispatcher(hPipe, ControlPacket, dwBufSize); ScDestroyStatusBinding(); CloseHandle(hPipe); /* Free the message buffer */ - RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer); + RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket); +Done: /* Free the service table */ for (i = 0; i < dwActiveServiceCount; i++) { @@ -917,7 +912,7 @@ lpActiveServices = NULL; dwActiveServiceCount = 0; - return TRUE; + return bRet; } @@ -929,10 +924,12 @@ BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW * lpServiceStartTable) { + BOOL bRet = TRUE; ULONG i; HANDLE hPipe; DWORD dwError; - PUCHAR lpMessageBuffer; + PSCM_CONTROL_PACKET ControlPacket; + DWORD dwBufSize; TRACE("StartServiceCtrlDispatcherW() called\n"); @@ -959,50 +956,41 @@ lpActiveServices[i].ThreadParams.W.lpServiceMain = lpServiceStartTable[i].lpServiceProc; lpActiveServices[i].hServiceStatus = 0; lpActiveServices[i].bUnicode = TRUE; + lpActiveServices[i].bOwnProcess = FALSE; } dwError = ScConnectControlPipe(&hPipe); if (dwError != ERROR_SUCCESS) { - /* Free the service table */ - for (i = 0; i < dwActiveServiceCount; i++) - { - RtlFreeUnicodeString(&lpActiveServices[i].ServiceName); - } - RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices); - lpActiveServices = NULL; - dwActiveServiceCount = 0; - return FALSE; + bRet = FALSE; + goto Done; } - lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(), - HEAP_ZERO_MEMORY, - 256); - if (lpMessageBuffer == NULL) + dwBufSize = sizeof(SCM_CONTROL_PACKET) + + (MAX_SERVICE_NAME_LENGTH + 1) * sizeof(WCHAR); + + ControlPacket = (PSCM_CONTROL_PACKET)RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + dwBufSize); + if (ControlPacket == NULL) { - /* Free the service table */ - for (i = 0; i < dwActiveServiceCount; i++) - { - RtlFreeUnicodeString(&lpActiveServices[i].ServiceName); - } - RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices); - lpActiveServices = NULL; - dwActiveServiceCount = 0; CloseHandle(hPipe); - return FALSE; + bRet = FALSE; + goto Done; } ScCreateStatusBinding(); - ScServiceDispatcher(hPipe, lpMessageBuffer, 256); + ScServiceDispatcher(hPipe, ControlPacket, dwBufSize); ScDestroyStatusBinding(); CloseHandle(hPipe); /* Free the message buffer */ - RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer); + RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket); +Done: /* Free the service table */ for (i = 0; i < dwActiveServiceCount; i++) { @@ -1012,7 +1000,7 @@ lpActiveServices = NULL; dwActiveServiceCount = 0; - return TRUE; + return bRet; } /* EOF */ Index: include/reactos/services/services.h =================================================================== --- include/reactos/services/services.h (révision 56862) +++ include/reactos/services/services.h (copie de travail) @@ -9,7 +9,14 @@ #ifndef __SERVICES_SERVICES_H__ #define __SERVICES_SERVICES_H__ -#define SERVICE_CONTROL_START 0 +/* + * Internal controls. + * Not in the range of public controls (1-10 and 11-14 or 16 or 32 or 64) + * nor in the range of user-defined controls (128-255). + */ +#define SERVICE_CONTROL_START 0 // Not used anymore +#define SERVICE_CONTROL_START_SHARE 80 /* Start a service that shares a process with other services */ +#define SERVICE_CONTROL_START_OWN 81 /* Start a service which owns its process */ typedef struct _SCM_CONTROL_PACKET {