Author: tkreuzer Date: Wed Oct 12 14:26:01 2011 New Revision: 54095
URL: http://svn.reactos.org/svn/reactos?rev=54095&view=rev Log: [SERVICES] - Do not keep the process handle of a started process open - when sending a STOP command to a process failed, then succeed and mark the process as stopped. Fixes ghost processes, when terminating a service with taskmgr and allows to restart services that got terminated or possibly crashed.
Modified: trunk/reactos/base/system/services/database.c
Modified: trunk/reactos/base/system/services/database.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/databa... ============================================================================== --- trunk/reactos/base/system/services/database.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/database.c [iso-8859-1] Wed Oct 12 14:26:01 2011 @@ -202,7 +202,6 @@
pServiceImage->dwImageRunCount = 1; pServiceImage->hControlPipe = INVALID_HANDLE_VALUE; - pServiceImage->hProcess = INVALID_HANDLE_VALUE;
/* Set the image path */ wcscpy(pServiceImage->szImagePath, @@ -264,10 +263,6 @@ /* Close the control pipe */ if (pServiceImage->hControlPipe != INVALID_HANDLE_VALUE) CloseHandle(pServiceImage->hControlPipe); - - /* Close the process handle */ - if (pServiceImage->hProcess != INVALID_HANDLE_VALUE) - CloseHandle(pServiceImage->hProcess);
/* Release the service image */ HeapFree(GetProcessHeap(), 0, pServiceImage); @@ -656,7 +651,7 @@ HeapFree(GetProcessHeap(), 0, CurrentService); } } - + if (dwError != ERROR_SUCCESS) DPRINT1("Delete service failed: %S\n", CurrentService->lpServiceName); } @@ -1085,6 +1080,16 @@ { dwError = GetLastError(); DPRINT("WriteFile() failed (Error %lu)\n", dwError); + + if ((dwError == ERROR_GEN_FAILURE) && + (dwControl == SERVICE_CONTROL_STOP)) + { + /* Service is already terminated */ + Service->Status.dwCurrentState = SERVICE_STOPPED; + Service->Status.dwControlsAccepted = 0; + Service->Status.dwWin32ExitCode = ERROR_SERVICE_NOT_ACTIVE; + dwError = ERROR_SUCCESS; + } goto Done; }
@@ -1572,7 +1577,6 @@
/* Get process handle and id */ Service->lpImage->dwProcessId = ProcessInformation.dwProcessId; - Service->lpImage->hProcess = ProcessInformation.hProcess;
/* Resume Thread */ ResumeThread(ProcessInformation.hThread); @@ -1590,12 +1594,11 @@ { DPRINT1("Connecting control pipe failed! (Error %lu)\n", dwError); Service->lpImage->dwProcessId = 0; - Service->lpImage->hProcess = NULL; - CloseHandle(ProcessInformation.hProcess); - } - - /* Close thread handle */ + } + + /* Close thread and process handle */ CloseHandle(ProcessInformation.hThread); + CloseHandle(ProcessInformation.hProcess);
return dwError; }