mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 01:15:42 +00:00
[TASKKILL] Merge our updated terminate_processes() function with the one
from Wine, using __REACTOS__ defines to separate the changes. We note that in effect it completely contains the functionality of Wine's send_close_messages(), so we keep that latter disabled.
This commit is contained in:
parent
e6f83a91b8
commit
a5d599505d
1 changed files with 52 additions and 153 deletions
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright 2008 Andrew Riedi
|
* Copyright 2008 Andrew Riedi
|
||||||
* Copyright 2010 Andrew Nguyen
|
* Copyright 2010 Andrew Nguyen
|
||||||
|
* Copyright 2020 He Yang
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -52,7 +53,7 @@ static PWCHAR opList[] = {opForceTerminate, opImage, opPID, opHelp, opTerminateC
|
||||||
#define OP_PARAM_HELP 3
|
#define OP_PARAM_HELP 3
|
||||||
#define OP_PARAM_TERMINATE_CHILD 4
|
#define OP_PARAM_TERMINATE_CHILD 4
|
||||||
|
|
||||||
#endif
|
#endif // __REACTOS__
|
||||||
|
|
||||||
struct pid_close_info
|
struct pid_close_info
|
||||||
{
|
{
|
||||||
|
@ -229,151 +230,7 @@ static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
|
||||||
* A PID of zero causes taskkill to warn about the inability to terminate
|
* A PID of zero causes taskkill to warn about the inability to terminate
|
||||||
* system processes. */
|
* system processes. */
|
||||||
|
|
||||||
|
#ifndef __REACTOS__
|
||||||
#ifdef __REACTOS__
|
|
||||||
|
|
||||||
static int terminate_processes(BOOL force_termination)
|
|
||||||
{
|
|
||||||
DWORD *pid_list, pid_list_size;
|
|
||||||
DWORD self_pid = GetCurrentProcessId();
|
|
||||||
unsigned int i;
|
|
||||||
int status_code = 0;
|
|
||||||
|
|
||||||
pid_list = enumerate_processes(&pid_list_size);
|
|
||||||
if (!pid_list)
|
|
||||||
{
|
|
||||||
taskkill_message(STRING_ENUM_FAILED);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < task_count; i++)
|
|
||||||
{
|
|
||||||
WCHAR *p = task_list[i];
|
|
||||||
BOOL is_numeric = TRUE;
|
|
||||||
|
|
||||||
/* Determine whether the string is not numeric. */
|
|
||||||
while (*p)
|
|
||||||
{
|
|
||||||
if (!isdigitW(*p++))
|
|
||||||
{
|
|
||||||
is_numeric = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_numeric)
|
|
||||||
{
|
|
||||||
DWORD pid = atoiW(task_list[i]);
|
|
||||||
|
|
||||||
if (pid == self_pid)
|
|
||||||
{
|
|
||||||
taskkill_message(STRING_SELF_TERMINATION);
|
|
||||||
status_code = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force_termination)
|
|
||||||
{
|
|
||||||
HANDLE process;
|
|
||||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
|
||||||
if (!process)
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
||||||
status_code = 128;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TerminateProcess(process, 0))
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_TERMINATE_FAILED, task_list[i]);
|
|
||||||
status_code = 1;
|
|
||||||
CloseHandle(process);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
taskkill_message_printfW(STRING_TERM_PID_SEARCH, pid);
|
|
||||||
CloseHandle(process);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct pid_close_info info = {pid};
|
|
||||||
|
|
||||||
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
|
||||||
if (info.found)
|
|
||||||
taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
||||||
status_code = 128;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DWORD index;
|
|
||||||
BOOL found_process = FALSE;
|
|
||||||
|
|
||||||
for (index = 0; index < pid_list_size; index++)
|
|
||||||
{
|
|
||||||
WCHAR process_name[MAX_PATH];
|
|
||||||
|
|
||||||
if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
|
|
||||||
!strcmpiW(process_name, task_list[i]))
|
|
||||||
{
|
|
||||||
found_process = TRUE;
|
|
||||||
|
|
||||||
if (pid_list[index] == self_pid)
|
|
||||||
{
|
|
||||||
taskkill_message(STRING_SELF_TERMINATION);
|
|
||||||
status_code = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force_termination)
|
|
||||||
{
|
|
||||||
HANDLE process;
|
|
||||||
|
|
||||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
|
|
||||||
if (!process)
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
||||||
status_code = 128;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TerminateProcess(process, 0))
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_TERMINATE_FAILED, task_list[i]);
|
|
||||||
status_code = 1;
|
|
||||||
CloseHandle(process);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
taskkill_message_printfW(STRING_TERM_PROC_SEARCH, task_list[i], pid_list[index]);
|
|
||||||
CloseHandle(process);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct pid_close_info info = {pid_list[index]};
|
|
||||||
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
|
||||||
taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_process)
|
|
||||||
{
|
|
||||||
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
||||||
status_code = 128;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, pid_list);
|
|
||||||
return status_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static int send_close_messages(void)
|
static int send_close_messages(void)
|
||||||
{
|
{
|
||||||
|
@ -464,7 +321,13 @@ static int send_close_messages(void)
|
||||||
return status_code;
|
return status_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // __REACTOS__
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
static int terminate_processes(BOOL force_termination)
|
||||||
|
#else
|
||||||
static int terminate_processes(void)
|
static int terminate_processes(void)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
DWORD *pid_list, pid_list_size;
|
DWORD *pid_list, pid_list_size;
|
||||||
DWORD self_pid = GetCurrentProcessId();
|
DWORD self_pid = GetCurrentProcessId();
|
||||||
|
@ -496,7 +359,9 @@ static int terminate_processes(void)
|
||||||
if (is_numeric)
|
if (is_numeric)
|
||||||
{
|
{
|
||||||
DWORD pid = atoiW(task_list[i]);
|
DWORD pid = atoiW(task_list[i]);
|
||||||
|
#ifndef __REACTOS__
|
||||||
HANDLE process;
|
HANDLE process;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pid == self_pid)
|
if (pid == self_pid)
|
||||||
{
|
{
|
||||||
|
@ -505,6 +370,11 @@ static int terminate_processes(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
if (force_termination)
|
||||||
|
{
|
||||||
|
HANDLE process;
|
||||||
|
#endif
|
||||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
if (!process)
|
if (!process)
|
||||||
{
|
{
|
||||||
|
@ -523,6 +393,22 @@ static int terminate_processes(void)
|
||||||
|
|
||||||
taskkill_message_printfW(STRING_TERM_PID_SEARCH, pid);
|
taskkill_message_printfW(STRING_TERM_PID_SEARCH, pid);
|
||||||
CloseHandle(process);
|
CloseHandle(process);
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct pid_close_info info = { pid };
|
||||||
|
|
||||||
|
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
||||||
|
if (info.found)
|
||||||
|
taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
||||||
|
status_code = 128;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -536,7 +422,11 @@ static int terminate_processes(void)
|
||||||
if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
|
if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
|
||||||
!strcmpiW(process_name, task_list[i]))
|
!strcmpiW(process_name, task_list[i]))
|
||||||
{
|
{
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
found_process = TRUE;
|
||||||
|
#else
|
||||||
HANDLE process;
|
HANDLE process;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pid_list[index] == self_pid)
|
if (pid_list[index] == self_pid)
|
||||||
{
|
{
|
||||||
|
@ -545,6 +435,11 @@ static int terminate_processes(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
if (force_termination)
|
||||||
|
{
|
||||||
|
HANDLE process;
|
||||||
|
#endif
|
||||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
|
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
|
||||||
if (!process)
|
if (!process)
|
||||||
{
|
{
|
||||||
|
@ -561,9 +456,20 @@ static int terminate_processes(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __REACTOS__
|
||||||
found_process = TRUE;
|
found_process = TRUE;
|
||||||
|
#endif
|
||||||
taskkill_message_printfW(STRING_TERM_PROC_SEARCH, task_list[i], pid_list[index]);
|
taskkill_message_printfW(STRING_TERM_PROC_SEARCH, task_list[i], pid_list[index]);
|
||||||
CloseHandle(process);
|
CloseHandle(process);
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct pid_close_info info = { pid_list[index] };
|
||||||
|
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
||||||
|
taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,9 +485,6 @@ static int terminate_processes(void)
|
||||||
return status_code;
|
return status_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __REACTOS__
|
|
||||||
|
|
||||||
|
|
||||||
static BOOL add_to_task_list(WCHAR *name)
|
static BOOL add_to_task_list(WCHAR *name)
|
||||||
{
|
{
|
||||||
static unsigned int list_size = 16;
|
static unsigned int list_size = 16;
|
||||||
|
@ -849,16 +752,12 @@ int wmain(int argc, WCHAR *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
|
|
||||||
status_code = terminate_processes(force_termination);
|
status_code = terminate_processes(force_termination);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (force_termination)
|
if (force_termination)
|
||||||
status_code = terminate_processes();
|
status_code = terminate_processes();
|
||||||
else
|
else
|
||||||
status_code = send_close_messages();
|
status_code = send_close_messages();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, task_list);
|
HeapFree(GetProcessHeap(), 0, task_list);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue