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
This commit is contained in:
Nikola Knezevic
2010-08-29 11:34:04 +02:00
committed by Bjorn Winckler
parent daa43ff96d
commit f4e9d096f2
+7 -1
View File
@@ -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)