From e7af79862b136efb414ac545f282939e2d290e3e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 23 Mar 2014 14:28:01 -0500 Subject: [PATCH] Detach Git Bash When called from the Windows Explorer, we must not wait for the stdout/stderr of Git Bash. A recent change made for FarManager makes Git Cheetah capture stderr/stdout even when we are not interested in it, to avoid cluttering FarManager's precious console. Due to this workaround, Git Bash makes the Explorer -- Git Cheetah's primary intended consumer -- hang. Since Git Bash does not output anything to the calling console, let's just force the detached mode by avoiding the FarManager workaround *just* for Git Bash. Thanks to John Stevenson for catching a bug in an earlier version of this commit. Signed-off-by: Johannes Schindelin --- common/cheetahmenu.c | 2 +- common/exec.c | 9 +++++---- common/exec.h | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/common/cheetahmenu.c b/common/cheetahmenu.c index 8b75c62..a6aa0ef 100644 --- a/common/cheetahmenu.c +++ b/common/cheetahmenu.c @@ -149,7 +149,7 @@ static int menu_bash(struct git_data *this_, UINT id) return 0; } - exec_program_v(wd, NULL, NULL, NORMALMODE, argv); + exec_program_v(wd, NULL, NULL, DETACHMODE, argv); if (argv_free) argv_free(argv_data); diff --git a/common/exec.c b/common/exec.c index 5213e87..c59934e 100644 --- a/common/exec.c +++ b/common/exec.c @@ -54,7 +54,7 @@ int exec_program_v(const char *working_directory, return -1; } - if (!output || !error_output) + if ((!output || !error_output) && !(DETACHMODE & flags)) devnull = open("/dev/null", O_WRONLY); s1 = dup(1); @@ -65,7 +65,7 @@ int exec_program_v(const char *working_directory, dup2(fdout[1], 1); flags |= WAITMODE; - } else { + } else if (devnull >= 0) { dup2(devnull, 1); } @@ -79,10 +79,11 @@ int exec_program_v(const char *working_directory, dup2(fderr[1], 2); flags |= WAITMODE; - } else { + } else if (devnull >= 0) { dup2(devnull, 2); } - close(devnull); + if (devnull >= 0) + close(devnull); pid = fork_process(argv[0], argv, working_directory); diff --git a/common/exec.h b/common/exec.h index d856cad..0bd1cf2 100644 --- a/common/exec.h +++ b/common/exec.h @@ -2,6 +2,7 @@ #define NORMALMODE (0) #define HIDDENMODE (1 << 0) /* hide any windows, opened by execution */ #define WAITMODE (1 << 1) /* wait for execution to complete */ +#define DETACHMODE (1 << 2) /* do *not* wait for execution to complete */ #define QUIETMODE (1 << 7) /* don't report any errors to user */ enum { -- 2.11.4.GIT