From 0cad27b1f1a766f7e5bf53b17d94d3b2648a3710 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 7 Mar 2018 15:24:47 +0100 Subject: [PATCH] fixup! mingw: spawned processes need to inherit only standard handles We should really only warn that we failed to restrict the file handle inheritance if we actually failed to create the process *without* restricting the file handles. This fixes https://github.com/git-for-windows/git/issues/1539 Signed-off-by: Johannes Schindelin --- compat/mingw.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 5ce7604e8c..93f30782c7 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1752,6 +1752,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen */ if (!ret && restrict_handle_inheritance && stdhandles_count) { DWORD err = GetLastError(); + struct strbuf buf = STRBUF_INIT; + if (err != ERROR_NO_SYSTEM_RESOURCES && /* * On Windows 7 and earlier, handles on pipes and character @@ -1765,7 +1767,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen !(err == ERROR_INVALID_PARAMETER && GetVersion() >> 16 < 9200) && !getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) { - struct strbuf buf = STRBUF_INIT; DWORD fl; int i; @@ -1786,15 +1787,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen "the environment variable\n\n" "\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1" "\n"); - warning("failed to restrict file handles (%ld)\n\n%s", - err, buf.buf); - strbuf_release(&buf); } restrict_handle_inheritance = 0; flags &= ~EXTENDED_STARTUPINFO_PRESENT; ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE, flags, wenvblk, dir ? wdir : NULL, &si.StartupInfo, &pi); + if (ret) + warning("failed to restrict file handles (%ld)\n\n%s", + err, buf.buf); + strbuf_release(&buf); } if (!ret)