]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mingw: restrict file handle inheritance only on Windows 7 and later
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 22 Nov 2019 14:41:05 +0000 (14:41 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Nov 2019 02:17:01 +0000 (11:17 +0900)
Turns out that it don't work so well on Vista, see
https://github.com/git-for-windows/git/issues/1742 for details.

According to https://devblogs.microsoft.com/oldnewthing/?p=8873, it
*should* work on Windows Vista and later.

But apparently there are issues on Windows Vista when pipes are
involved. Given that Windows Vista is past its end of life (official
support ended on April 11th, 2017), let's not spend *too* much time on
this issue and just disable the file handle inheritance restriction on
any Windows version earlier than Windows 7.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/core.txt
compat/mingw.c

index 852d2ba37a1204e0e210e9abf671d7f0c9c850d8..ad4fa4dccdeb99325a87efe4dca63895d0ffad8c 100644 (file)
@@ -559,6 +559,12 @@ core.unsetenvvars::
        Defaults to `PERL5LIB` to account for the fact that Git for
        Windows insists on using its own Perl interpreter.
 
+core.restrictinheritedhandles::
+       Windows-only: override whether spawned processes inherit only standard
+       file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
+       `auto`, `true` or `false`. Defaults to `auto`, which means `true` on
+       Windows 7 and later, and `false` on older Windows versions.
+
 core.createObject::
        You can set this to 'link', in which case a hardlink followed by
        a delete of the source are used to make sure that object creation
index cac18cc3daaa093788348d3dadafb67dcc3e8ddb..2b6eca2f56784aee87db7fc35d81fbb5036ad212 100644 (file)
@@ -212,6 +212,7 @@ enum hide_dotfiles_type {
        HIDE_DOTFILES_DOTGITONLY
 };
 
+static int core_restrict_inherited_handles = -1;
 static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
 static char *unset_environment_variables;
 
@@ -231,6 +232,15 @@ int mingw_core_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "core.restrictinheritedhandles")) {
+               if (value && !strcasecmp(value, "auto"))
+                       core_restrict_inherited_handles = -1;
+               else
+                       core_restrict_inherited_handles =
+                               git_config_bool(var, value);
+               return 0;
+       }
+
        return 0;
 }
 
@@ -1398,7 +1408,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
                              const char *dir,
                              int prepend_cmd, int fhin, int fhout, int fherr)
 {
-       static int restrict_handle_inheritance = 1;
+       static int restrict_handle_inheritance = -1;
        STARTUPINFOEXW si;
        PROCESS_INFORMATION pi;
        LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1413,6 +1423,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
        const char *(*quote_arg)(const char *arg) =
                is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
 
+       if (restrict_handle_inheritance < 0)
+               restrict_handle_inheritance = core_restrict_inherited_handles;
+       /*
+        * The following code to restrict which handles are inherited seems
+        * to work properly only on Windows 7 and later, so let's disable it
+        * on Windows Vista and 2008.
+        */
+       if (restrict_handle_inheritance < 0)
+               restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
+
        do_unset_environment_variables();
 
        /* Determine whether or not we are associated to a console */