From f4e9d096f28b055839a24df57e8b46a0897ba45b Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Sun, 29 Aug 2010 11:34:04 +0200 Subject: [PATCH] Fix Vim hanging when using zsh+git This fixes the problem explained in [2]. Essentially, when executing external program, where default shell is zsh, Vim would hang. This behaviour does not occur with bash, or other shells. Problem: When Vim executes an external program from GUI (MacVim in this case), it opens PTYs. Parent passes information to the child via these PTYs. Savvy implementation closes all unused filehandles, so slave PTY fd is closed in the parent immediately after fork(). This causes problems on MacVim, due to [1]. In a nutshell, on BSD-like systems, write operations on PTY would block until one side reads or exits. If a child tries to write on a PTY, which is closed in parent, that would block the child, and stop further progress. Resolution: Instead of closing child's fd in the parent immediately after fork(), close it after child exits. [1] http://osdir.com/ml/darwin-kernel/2010-04/msg00025.html [2] http://groups.google.com/group/vim_mac/browse_thread/thread/78b18ce8cc15557d --- src/os_unix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/os_unix.c b/src/os_unix.c index 2d02a024ec..515ad61496 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4154,7 +4154,9 @@ mch_call_shell(cmd, options) # ifdef FEAT_GUI if (pty_master_fd >= 0) { - close(pty_slave_fd); /* close slave side of pty */ +# ifndef FEAT_GUI_MACVIM + close(pty_slave_fd); /* close slave side of pty */ +# endif fromshell_fd = pty_master_fd; toshell_fd = dup(pty_master_fd); } @@ -4627,6 +4629,10 @@ finished: break; } +#ifdef FEAT_GUI_MACVIM + if (pty_slave_fd >= 0) + close(pty_slave_fd); /* close slave side of pty */ +#endif /* Make sure the child that writes to the external program is * dead. */ if (wpid > 0)