To: vim_dev@googlegroups.com Subject: Patch 8.0.0054 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0054 (after 8.0.0051) 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) Files: src/os_win32.c *** ../vim-8.0.0053/src/os_win32.c 2016-10-27 21:13:04.882665596 +0200 --- src/os_win32.c 2016-10-29 14:52:48.832914391 +0200 *************** *** 50,55 **** --- 50,59 ---- # endif #endif + #ifdef FEAT_JOB_CHANNEL + # include + #endif + #ifdef __MINGW32__ # ifndef FROM_LEFT_1ST_BUTTON_PRESSED # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 *************** *** 5020,5025 **** --- 5024,5071 ---- return NULL; } + static BOOL + terminate_all(HANDLE process, int code) + { + PROCESSENTRY32 pe; + HANDLE h = INVALID_HANDLE_VALUE; + DWORD pid = GetProcessId(process); + + if (pid != 0) + { + h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (h != INVALID_HANDLE_VALUE) + { + pe.dwSize = sizeof(PROCESSENTRY32); + if (!Process32First(h, &pe)) + goto theend; + + do + { + if (pe.th32ParentProcessID == pid) + { + HANDLE ph = OpenProcess( + PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); + if (ph != NULL) + { + terminate_all(ph, code); + CloseHandle(ph); + } + } + } while (Process32Next(h, &pe)); + + CloseHandle(h); + } + } + + theend: + return TerminateProcess(process, code); + } + + /* + * Send a (deadly) signal to "job". + * Return FAIL if it didn't work. + */ int mch_stop_job(job_T *job, char_u *how) { *************** *** 5027,5036 **** if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) { if (job->jv_job_object != NULL) return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; ! else ! return TerminateProcess(job->jv_proc_info.hProcess, 0) ? OK : FAIL; } if (!AttachConsole(job->jv_proc_info.dwProcessId)) --- 5073,5082 ---- if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) { + /* deadly signal */ if (job->jv_job_object != NULL) return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; ! return terminate_all(job->jv_proc_info.hProcess, 0) ? OK : FAIL; } if (!AttachConsole(job->jv_proc_info.dwProcessId)) *** ../vim-8.0.0053/src/version.c 2016-10-29 14:37:51.970378370 +0200 --- src/version.c 2016-10-29 14:54:23.980334722 +0200 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 54, /**/ -- OLD WOMAN: Well, how did you become king, then? ARTHUR: The Lady of the Lake, her arm clad in the purest shimmering samite, held Excalibur aloft from the bosom of the water to signify by Divine Providence ... that I, Arthur, was to carry Excalibur ... That is why I am your king! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///