From 3e3594e3aadd4c97187b7b85236b1616c43ef38e Mon Sep 17 00:00:00 2001 From: Serge Gautherie Date: Tue, 27 Feb 2024 22:42:54 +0100 Subject: [PATCH] [KILL] ExecuteKill(): Return '1' on failures and add a related 'CloseHandle()' call. Also, enforce PID 'unsigned' type. --- modules/rosapps/applications/sysutils/kill/kill.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/rosapps/applications/sysutils/kill/kill.c b/modules/rosapps/applications/sysutils/kill/kill.c index 153cfe3905f..170cfd8c8a3 100644 --- a/modules/rosapps/applications/sysutils/kill/kill.c +++ b/modules/rosapps/applications/sysutils/kill/kill.c @@ -35,25 +35,26 @@ #include 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);