Skip to content

Commit

Permalink
[SERVICES] Terminate the service image process when its reference cou…
Browse files Browse the repository at this point in the history
…nt reaches zero (reactos#7402)

Addendum to commit 1dfbed9
Supplement for PR reactos#7375
CORE-12413
  • Loading branch information
HBelusca committed Oct 11, 2024
1 parent 84f423f commit 65b872d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion base/system/services/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,50 @@ ScmCreateOrReferenceServiceImage(PSERVICE pService)
VOID
ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage)
{
DWORD dwError;

DPRINT1("ScmRemoveServiceImage() called\n");

/* FIXME: Terminate the process */
/*
* No services are running in this image anymore.
* Tell the service dispatcher to exit now, and wait
* for the process to cleanly terminate.
*/
// FIXME: Re-enable here and remove the L"" SERVICE_CONTROL_STOP call in rpcserver.c
#if 0
dwError = ScmControlService(pServiceImage->hControlPipe,
L"",
SERVICE_CONTROL_STOP, // Windows: use SERVICE_STOP
NULL);
if (dwError == ERROR_SUCCESS)
#endif
{
dwError = WaitForSingleObject(pServiceImage->hProcess, 20000);
if (dwError != WAIT_OBJECT_0)
DPRINT1("WaitForSingleObject failed, going to kill the process.\n");
}
#if 0
else
{
DPRINT1("ScmControlService failed, going to kill the process.\n");
}
#endif

if (dwError != ERROR_SUCCESS || dwError != WAIT_OBJECT_0)
{
/* If the control or the wait failed, kill the host process
* (asynchronously), unless it is ourselves (case of services.exe
* hosting services) */
if (pServiceImage->hProcess != GetCurrentProcess())
{
TerminateProcess(pServiceImage->hProcess, 0);

/* Be sure the process really terminates */
dwError = WaitForSingleObject(pServiceImage->hProcess, 20000);
}
if (dwError != WAIT_OBJECT_0)
DPRINT1("WaitForSingleObject failed, the process cannot be killed.\n");
}

/* Remove the service image from the list */
RemoveEntryList(&pServiceImage->ImageListEntry);
Expand Down

0 comments on commit 65b872d

Please sign in to comment.