Skip to content

Commit 8f13e4d

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 97a42c8 + 31cef14 commit 8f13e4d

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
@@ -557,6 +557,12 @@ core.unsetenvvars::
557557
Defaults to `PERL5LIB` to account for the fact that Git for
558558
Windows insists on using its own Perl interpreter.
559559

560+
core.restrictinheritedhandles::
561+
Windows-only: override whether spawned processes inherit only standard
562+
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
563+
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
564+
Windows 7 and later, and `false` on older Windows versions.
565+
560566
core.createObject::
561567
You can set this to 'link', in which case a hardlink followed by
562568
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
@@ -225,6 +225,7 @@ enum hide_dotfiles_type {
225225
HIDE_DOTFILES_DOTGITONLY
226226
};
227227

228+
static int core_restrict_inherited_handles = -1;
228229
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
229230
static char *unset_environment_variables;
230231

@@ -244,6 +245,15 @@ int mingw_core_config(const char *var, const char *value, void *cb)
244245
return 0;
245246
}
246247

248+
if (!strcmp(var, "core.restrictinheritedhandles")) {
249+
if (value && !strcasecmp(value, "auto"))
250+
core_restrict_inherited_handles = -1;
251+
else
252+
core_restrict_inherited_handles =
253+
git_config_bool(var, value);
254+
return 0;
255+
}
256+
247257
return 0;
248258
}
249259

@@ -1422,7 +1432,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14221432
const char *dir,
14231433
int prepend_cmd, int fhin, int fhout, int fherr)
14241434
{
1425-
static int restrict_handle_inheritance = 1;
1435+
static int restrict_handle_inheritance = -1;
14261436
STARTUPINFOEXW si;
14271437
PROCESS_INFORMATION pi;
14281438
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1438,6 +1448,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14381448
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
14391449
const char *strace_env;
14401450

1451+
if (restrict_handle_inheritance < 0)
1452+
restrict_handle_inheritance = core_restrict_inherited_handles;
1453+
/*
1454+
* The following code to restrict which handles are inherited seems
1455+
* to work properly only on Windows 7 and later, so let's disable it
1456+
* on Windows Vista and 2008.
1457+
*/
1458+
if (restrict_handle_inheritance < 0)
1459+
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1460+
14411461
do_unset_environment_variables();
14421462

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

0 commit comments

Comments
 (0)