Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
5c851451
Commit
5c851451
authored
Mar 28, 2023
by
Paul Gofman
Committed by
Alexandre Julliard
Mar 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
taskkill: Mark processes for termination in main().
parent
6cca1f50
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
30 deletions
+52
-30
taskkill.c
programs/taskkill/taskkill.c
+52
-30
No files found.
programs/taskkill/taskkill.c
View file @
5c851451
...
...
@@ -37,6 +37,7 @@ static struct
{
PROCESSENTRY32W
p
;
BOOL
matched
;
BOOL
is_numeric
;
}
*
process_list
;
static
unsigned
int
process_count
;
...
...
@@ -151,6 +152,7 @@ static BOOL enumerate_processes(void)
do
{
process_list
[
process_count
].
is_numeric
=
FALSE
;
process_list
[
process_count
++
].
matched
=
FALSE
;
if
(
process_count
==
alloc_count
)
{
...
...
@@ -166,40 +168,42 @@ static BOOL enumerate_processes(void)
return
TRUE
;
}
static
BOOL
get_task_pid
(
const
WCHAR
*
str
,
BOOL
*
is_numeric
,
WCHAR
*
process_name
,
int
*
status_code
,
DWORD
*
pid
)
static
void
mark_task_process
(
const
WCHAR
*
str
,
int
*
status_code
)
{
DWORD
self_pid
=
GetCurrentProcessId
();
const
WCHAR
*
p
=
str
;
BOOL
is_numeric
;
unsigned
int
i
;
DWORD
pid
;
*
is_numeric
=
TRUE
;
is_numeric
=
TRUE
;
while
(
*
p
)
{
if
(
!
iswdigit
(
*
p
++
))
{
*
is_numeric
=
FALSE
;
is_numeric
=
FALSE
;
break
;
}
}
if
(
*
is_numeric
)
if
(
is_numeric
)
{
*
pid
=
wcstol
(
str
,
NULL
,
10
);
pid
=
wcstol
(
str
,
NULL
,
10
);
for
(
i
=
0
;
i
<
process_count
;
++
i
)
{
if
(
process_list
[
i
].
p
.
th32ProcessID
==
*
pid
)
if
(
process_list
[
i
].
p
.
th32ProcessID
==
pid
)
break
;
}
if
(
i
==
process_count
||
process_list
[
i
].
matched
)
goto
not_found
;
process_list
[
i
].
matched
=
TRUE
;
if
(
*
pid
==
self_pid
)
process_list
[
i
].
is_numeric
=
TRUE
;
if
(
pid
==
self_pid
)
{
taskkill_message
(
STRING_SELF_TERMINATION
);
*
status_code
=
1
;
return
FALSE
;
}
return
TRUE
;
return
;
}
for
(
i
=
0
;
i
<
process_count
;
++
i
)
...
...
@@ -211,18 +215,27 @@ static BOOL get_task_pid(const WCHAR *str, BOOL *is_numeric, WCHAR *process_name
{
taskkill_message
(
STRING_SELF_TERMINATION
);
*
status_code
=
1
;
return
FALSE
;
}
*
pid
=
process_list
[
i
].
p
.
th32ProcessID
;
wcscpy
(
process_name
,
process_list
[
i
].
p
.
szExeFile
);
return
TRUE
;
return
;
}
}
not_found:
taskkill_message_printfW
(
STRING_SEARCH_FAILED
,
str
);
*
status_code
=
128
;
return
FALSE
;
}
static
void
taskkill_message_print_process
(
int
msg
,
unsigned
int
index
)
{
WCHAR
pid_str
[
16
];
if
(
!
process_list
[
index
].
is_numeric
)
{
taskkill_message_printfW
(
msg
,
process_list
[
index
].
p
.
szExeFile
);
return
;
}
wsprintfW
(
pid_str
,
L"%lu"
,
process_list
[
index
].
p
.
th32ProcessID
);
taskkill_message_printfW
(
msg
,
pid_str
);
}
/* The implemented task enumeration and termination behavior does not
...
...
@@ -241,28 +254,28 @@ not_found:
* system processes. */
static
int
send_close_messages
(
void
)
{
WCHAR
process_name
[
MAX_PATH
]
;
const
WCHAR
*
process_name
;
struct
pid_close_info
info
;
unsigned
int
i
;
int
status_code
=
0
;
BOOL
is_numeric
;
for
(
i
=
0
;
i
<
task_count
;
i
++
)
{
if
(
!
get_task_pid
(
task_list
[
i
],
&
is_numeric
,
process_name
,
&
status_code
,
&
info
.
pid
)
)
if
(
!
process_list
[
i
].
matched
)
continue
;
info
.
pid
=
process_list
[
i
].
p
.
th32ProcessID
;
process_name
=
process_list
[
i
].
p
.
szExeFile
;
info
.
found
=
FALSE
;
EnumWindows
(
pid_enum_proc
,
(
LPARAM
)
&
info
);
if
(
info
.
found
)
{
if
(
is_numeric
)
if
(
process_list
[
i
].
is_numeric
)
taskkill_message_printfW
(
STRING_CLOSE_PID_SEARCH
,
info
.
pid
);
else
taskkill_message_printfW
(
STRING_CLOSE_PROC_SRCH
,
process_name
,
info
.
pid
);
continue
;
}
taskkill_message_print
fW
(
STRING_SEARCH_FAILED
,
task_list
[
i
]
);
taskkill_message_print
_process
(
STRING_SEARCH_FAILED
,
i
);
status_code
=
128
;
}
...
...
@@ -271,36 +284,37 @@ static int send_close_messages(void)
static
int
terminate_processes
(
void
)
{
WCHAR
process_name
[
MAX_PATH
]
;
const
WCHAR
*
process_name
;
unsigned
int
i
;
int
status_code
=
0
;
BOOL
is_numeric
;
HANDLE
process
;
DWORD
pid
;
for
(
i
=
0
;
i
<
task
_count
;
i
++
)
for
(
i
=
0
;
i
<
process
_count
;
i
++
)
{
if
(
!
get_task_pid
(
task_list
[
i
],
&
is_numeric
,
process_name
,
&
status_code
,
&
pid
)
)
if
(
!
process_list
[
i
].
matched
)
continue
;
pid
=
process_list
[
i
].
p
.
th32ProcessID
;
process_name
=
process_list
[
i
].
p
.
szExeFile
;
process
=
OpenProcess
(
PROCESS_TERMINATE
,
FALSE
,
pid
);
if
(
!
process
)
{
taskkill_message_print
fW
(
STRING_SEARCH_FAILED
,
task_list
[
i
]
);
taskkill_message_print
_process
(
STRING_SEARCH_FAILED
,
i
);
status_code
=
128
;
continue
;
}
if
(
!
TerminateProcess
(
process
,
1
))
{
taskkill_message_print
fW
(
STRING_TERMINATE_FAILED
,
task_list
[
i
]
);
taskkill_message_print
_process
(
STRING_TERMINATE_FAILED
,
i
);
status_code
=
1
;
CloseHandle
(
process
);
continue
;
}
if
(
is_numeric
)
if
(
process_list
[
i
].
is_numeric
)
taskkill_message_printfW
(
STRING_TERM_PID_SEARCH
,
pid
);
else
taskkill_message_printfW
(
STRING_TERM_PROC_SEARCH
,
task_list
[
i
]
,
pid
);
taskkill_message_printfW
(
STRING_TERM_PROC_SEARCH
,
process_name
,
pid
);
CloseHandle
(
process
);
}
return
status_code
;
...
...
@@ -414,6 +428,9 @@ static BOOL process_arguments(int argc, WCHAR *argv[])
int
__cdecl
wmain
(
int
argc
,
WCHAR
*
argv
[])
{
int
search_status
=
0
,
terminate_status
;
unsigned
int
i
;
if
(
!
process_arguments
(
argc
,
argv
))
return
1
;
...
...
@@ -423,7 +440,12 @@ int __cdecl wmain(int argc, WCHAR *argv[])
return
1
;
}
for
(
i
=
0
;
i
<
task_count
;
++
i
)
mark_task_process
(
task_list
[
i
],
&
search_status
);
if
(
force_termination
)
return
terminate_processes
();
return
send_close_messages
();
terminate_status
=
terminate_processes
();
else
terminate_status
=
send_close_messages
();
return
search_status
?
search_status
:
terminate_status
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment