From 2346676408481a1836d7796061ac900f734410f3 Mon Sep 17 00:00:00 2001
From: Nikola Knezevic <nikola.knezevic@epfl.ch>
Date: Sun, 29 Aug 2010 11:34:04 +0200
Subject: [PATCH 2/2] 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 |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/os_unix.c b/src/os_unix.c
index 2d02a02..afa6b9f 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4154,7 +4154,6 @@ mch_call_shell(cmd, options)
 # ifdef FEAT_GUI
 		if (pty_master_fd >= 0)
 		{
-		    close(pty_slave_fd);	/* close slave side of pty */
 		    fromshell_fd = pty_master_fd;
 		    toshell_fd = dup(pty_master_fd);
 		}
@@ -4627,6 +4626,10 @@ finished:
 		    break;
 	    }
 
+#ifdef FEAT_GUI
+	    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)
-- 
1.7.2.2

