Skip to content

Commit b26034f

Browse files
committed
Merge branch 'dont-restrict-handles-on-vista'
It seems that our feature to restrict file handle inheritance to let spawned processes inherit only the standard handles is a bit broken on Vista. This closes #1742 Signed-off-by: Johannes Schindelin <[email protected]>
2 parents acdae51 + 7999d34 commit b26034f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Documentation/config/core.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ core.unsetenvvars::
570570
Defaults to `PERL5LIB` to account for the fact that Git for
571571
Windows insists on using its own Perl interpreter.
572572

573+
core.restrictinheritedhandles::
574+
Windows-only: override whether spawned processes inherit only standard
575+
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
576+
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
577+
Windows 7 and later, and `false` on older Windows versions.
578+
573579
core.createObject::
574580
You can set this to 'link', in which case a hardlink followed by
575581
a delete of the source are used to make sure that object creation

compat/mingw.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
259259
static char *unset_environment_variables;
260260
int core_fscache;
261261
int core_long_paths;
262+
int core_restrict_inherited_handles = -1;
262263

263264
int mingw_core_config(const char *var, const char *value, void *cb)
264265
{
@@ -286,6 +287,15 @@ int mingw_core_config(const char *var, const char *value, void *cb)
286287
return 0;
287288
}
288289

290+
if (!strcmp(var, "core.restrictinheritedhandles")) {
291+
if (value && !strcasecmp(value, "auto"))
292+
core_restrict_inherited_handles = -1;
293+
else
294+
core_restrict_inherited_handles =
295+
git_config_bool(var, value);
296+
return 0;
297+
}
298+
289299
return 0;
290300
}
291301

@@ -1674,7 +1684,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16741684
const char *dir, const char *prepend_cmd,
16751685
int fhin, int fhout, int fherr)
16761686
{
1677-
static int restrict_handle_inheritance = 1;
1687+
static int restrict_handle_inheritance = -1;
16781688
STARTUPINFOEXW si;
16791689
PROCESS_INFORMATION pi;
16801690
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1690,6 +1700,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16901700
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
16911701
const char *strace_env;
16921702

1703+
if (restrict_handle_inheritance < 0)
1704+
restrict_handle_inheritance = core_restrict_inherited_handles;
1705+
/*
1706+
* The following code to restrict which handles are inherited seems
1707+
* to work properly only on Windows 7 and later, so let's disable it
1708+
* on Windows Vista and 2008.
1709+
*/
1710+
if (restrict_handle_inheritance < 0)
1711+
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1712+
16931713
do_unset_environment_variables();
16941714

16951715
/* Determine whether or not we are associated to a console */

0 commit comments

Comments
 (0)