Mercurial > vim
comparison src/os_unix.c @ 11919:cca097489de5 v8.0.0839
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
commit https://github.com/vim/vim/commit/fae428354213b54626ff9e29faa5fd86161da942
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 1 22:24:26 2017 +0200
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Problem: Cannot kill a job in a terminal with CTRL-C.
Solution: Set the controlling tty and send SIGINT. (closes https://github.com/vim/vim/issues/1910)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 01 Aug 2017 22:30:04 +0200 |
parents | 1e8d353cb827 |
children | fe6675d67a10 |
comparison
equal
deleted
inserted
replaced
11918:7075721ff284 | 11919:cca097489de5 |
---|---|
4191 *pty_master_fd = -1; | 4191 *pty_master_fd = -1; |
4192 } | 4192 } |
4193 } | 4193 } |
4194 } | 4194 } |
4195 #endif | 4195 #endif |
4196 | |
4197 /* | |
4198 * Send SIGINT to a child process if "c" is an interrupt character. | |
4199 */ | |
4200 void | |
4201 may_send_sigint(int c UNUSED, pid_t pid UNUSED, pid_t wpid UNUSED) | |
4202 { | |
4203 # ifdef SIGINT | |
4204 if (c == Ctrl_C || c == intr_char) | |
4205 { | |
4206 # ifdef HAVE_SETSID | |
4207 kill(-pid, SIGINT); | |
4208 # else | |
4209 kill(0, SIGINT); | |
4210 # endif | |
4211 if (wpid > 0) | |
4212 kill(wpid, SIGINT); | |
4213 } | |
4214 # endif | |
4215 } | |
4196 | 4216 |
4197 int | 4217 int |
4198 mch_call_shell( | 4218 mch_call_shell( |
4199 char_u *cmd, | 4219 char_u *cmd, |
4200 int options) /* SHELL_*, see vim.h */ | 4220 int options) /* SHELL_*, see vim.h */ |
4763 * Check for CTRL-C: send interrupt signal to child. | 4783 * Check for CTRL-C: send interrupt signal to child. |
4764 * Check for CTRL-D: EOF, close pipe to child. | 4784 * Check for CTRL-D: EOF, close pipe to child. |
4765 */ | 4785 */ |
4766 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | 4786 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) |
4767 { | 4787 { |
4768 # ifdef SIGINT | |
4769 /* | 4788 /* |
4770 * Send SIGINT to the child's group or all | 4789 * Send SIGINT to the child's group or all |
4771 * processes in our group. | 4790 * processes in our group. |
4772 */ | 4791 */ |
4773 if (ta_buf[ta_len] == Ctrl_C | 4792 may_send_sigint(ta_buf[ta_len], pid, wpid); |
4774 || ta_buf[ta_len] == intr_char) | 4793 |
4775 { | |
4776 # ifdef HAVE_SETSID | |
4777 kill(-pid, SIGINT); | |
4778 # else | |
4779 kill(0, SIGINT); | |
4780 # endif | |
4781 if (wpid > 0) | |
4782 kill(wpid, SIGINT); | |
4783 } | |
4784 # endif | |
4785 if (pty_master_fd < 0 && toshell_fd >= 0 | 4794 if (pty_master_fd < 0 && toshell_fd >= 0 |
4786 && ta_buf[ta_len] == Ctrl_D) | 4795 && ta_buf[ta_len] == Ctrl_D) |
4787 { | 4796 { |
4788 close(toshell_fd); | 4797 close(toshell_fd); |
4789 toshell_fd = -1; | 4798 toshell_fd = -1; |
5358 } | 5367 } |
5359 | 5368 |
5360 if (null_fd >= 0) | 5369 if (null_fd >= 0) |
5361 close(null_fd); | 5370 close(null_fd); |
5362 | 5371 |
5372 if (pty_slave_fd >= 0) | |
5373 { | |
5374 /* push stream discipline modules */ | |
5375 SetupSlavePTY(pty_slave_fd); | |
5376 # ifdef TIOCSCTTY | |
5377 /* Try to become controlling tty (probably doesn't work, | |
5378 * unless run by root) */ | |
5379 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
5380 # endif | |
5381 } | |
5382 | |
5363 /* See above for type of argv. */ | 5383 /* See above for type of argv. */ |
5364 execvp(argv[0], argv); | 5384 execvp(argv[0], argv); |
5365 | 5385 |
5366 if (stderr_works) | 5386 if (stderr_works) |
5367 perror("executing job failed"); | 5387 perror("executing job failed"); |
5368 #ifdef EXITFREE | 5388 # ifdef EXITFREE |
5369 /* calling free_all_mem() here causes problems. Ignore valgrind | 5389 /* calling free_all_mem() here causes problems. Ignore valgrind |
5370 * reporting possibly leaked memory. */ | 5390 * reporting possibly leaked memory. */ |
5371 #endif | 5391 # endif |
5372 _exit(EXEC_FAILED); /* exec failed, return failure code */ | 5392 _exit(EXEC_FAILED); /* exec failed, return failure code */ |
5373 } | 5393 } |
5374 | 5394 |
5375 /* parent */ | 5395 /* parent */ |
5376 UNBLOCK_SIGNALS(&curset); | 5396 UNBLOCK_SIGNALS(&curset); |