[KILL] ExecuteKill(): Return '1' on failures

and add a related 'CloseHandle()' call.

Also, enforce PID 'unsigned' type.
This commit is contained in:
Serge Gautherie 2024-02-27 22:42:54 +01:00 committed by Hermès BÉLUSCA - MAÏTO
parent 5a30c71e70
commit 3e3594e3aa

View file

@ -35,25 +35,26 @@
#include <stdlib.h>
int
ExecuteKill(char *lpPid)
ExecuteKill(const char *lpPid)
{
HANDLE hProcess;
DWORD dwProcessId;
dwProcessId = (DWORD)atol(lpPid);
fprintf(stderr, "Killing PID %ld...\n", dwProcessId);
dwProcessId = strtoul(lpPid, NULL, 10);
fprintf(stderr, "Killing the process with PID %lu...\n", dwProcessId);
hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
if (hProcess == NULL)
{
fprintf(stderr, "Could not open the process with PID = %ld\n", dwProcessId);
return 0;
fprintf(stderr, "Could not open the process with PID %lu\n", dwProcessId);
return 1;
}
if (!TerminateProcess(hProcess, 0))
{
fprintf(stderr, "Could not terminate the process with PID = %ld\n", dwProcessId);
return 0;
fprintf(stderr, "Could not terminate the process with PID %lu\n", dwProcessId);
CloseHandle(hProcess);
return 1;
}
CloseHandle(hProcess);