Skip to content

Commit fb63090

Browse files
committed
patch 8.0.0054
Problem: On Windows job_stop() stops cmd.exe, not the processes it runs. (Linwei) Solution: Iterate over all processes and terminate the one where the parent is the job process. Now only when there is no job object. (Yasuhiro Matsumoto, closes #1203)
1 parent 60ef3e8 commit fb63090

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/os_win32.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
# endif
5151
#endif
5252

53+
#ifdef FEAT_JOB_CHANNEL
54+
# include <tlhelp32.h>
55+
#endif
56+
5357
#ifdef __MINGW32__
5458
# ifndef FROM_LEFT_1ST_BUTTON_PRESSED
5559
# define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001
@@ -5020,17 +5024,59 @@ mch_detect_ended_job(job_T *job_list)
50205024
return NULL;
50215025
}
50225026

5027+
static BOOL
5028+
terminate_all(HANDLE process, int code)
5029+
{
5030+
PROCESSENTRY32 pe;
5031+
HANDLE h = INVALID_HANDLE_VALUE;
5032+
DWORD pid = GetProcessId(process);
5033+
5034+
if (pid != 0)
5035+
{
5036+
h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
5037+
if (h != INVALID_HANDLE_VALUE)
5038+
{
5039+
pe.dwSize = sizeof(PROCESSENTRY32);
5040+
if (!Process32First(h, &pe))
5041+
goto theend;
5042+
5043+
do
5044+
{
5045+
if (pe.th32ParentProcessID == pid)
5046+
{
5047+
HANDLE ph = OpenProcess(
5048+
PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
5049+
if (ph != NULL)
5050+
{
5051+
terminate_all(ph, code);
5052+
CloseHandle(ph);
5053+
}
5054+
}
5055+
} while (Process32Next(h, &pe));
5056+
5057+
CloseHandle(h);
5058+
}
5059+
}
5060+
5061+
theend:
5062+
return TerminateProcess(process, code);
5063+
}
5064+
5065+
/*
5066+
* Send a (deadly) signal to "job".
5067+
* Return FAIL if it didn't work.
5068+
*/
50235069
int
50245070
mch_stop_job(job_T *job, char_u *how)
50255071
{
50265072
int ret;
50275073

50285074
if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL)
50295075
{
5076+
/* deadly signal */
50305077
if (job->jv_job_object != NULL)
50315078
return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL;
5032-
else
5033-
return TerminateProcess(job->jv_proc_info.hProcess, 0) ? OK : FAIL;
5079+
return terminate_all(job->jv_proc_info.hProcess, 0) ? OK : FAIL;
50345080
}
50355081

50365082
if (!AttachConsole(job->jv_proc_info.dwProcessId))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
54,
767769
/**/
768770
53,
769771
/**/

0 commit comments

Comments
 (0)