Skip to content

Commit e810ee5

Browse files
committed
Drop support for core.restrictInheritedHandles, as it targeted Windows 7 and earlier (#5460)
There has been a slow but steady stream of bug reports triggered by the warning included in ac33519. Since introducing the escape hatch for Windows 7 in that same patch, however, I have not seen a single report that pointed to the kind of bug I anticipated when writing that warning message. Let's drop this warning, as well as the escape hatch: Git for Windows dropped supporting Windows 7 (and Windows 8) directly after Git for Windows v2.46.2. For full details, see https://gitforwindows.org/requirements#windows-version. For good measure, let's keep the fall-back, though: It sometimes helps work around issues (e.g. when Defender still holds a handle on a file that Git wants to write out).
2 parents c19467a + 9db3a65 commit e810ee5

File tree

2 files changed

+4
-70
lines changed

2 files changed

+4
-70
lines changed

Documentation/config/core.adoc

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

699-
core.restrictinheritedhandles::
700-
Windows-only: override whether spawned processes inherit only standard
701-
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
702-
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
703-
Windows 7 and later, and `false` on older Windows versions.
704-
705699
core.createObject::
706700
You can set this to 'link', in which case a hardlink followed by
707701
a delete of the source are used to make sure that object creation

compat/mingw.c

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ enum hide_dotfiles_type {
246246
HIDE_DOTFILES_DOTGITONLY
247247
};
248248

249-
static int core_restrict_inherited_handles = -1;
250249
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
251250
static char *unset_environment_variables;
252251

@@ -270,15 +269,6 @@ int mingw_core_config(const char *var, const char *value,
270269
return 0;
271270
}
272271

273-
if (!strcmp(var, "core.restrictinheritedhandles")) {
274-
if (value && !strcasecmp(value, "auto"))
275-
core_restrict_inherited_handles = -1;
276-
else
277-
core_restrict_inherited_handles =
278-
git_config_bool(var, value);
279-
return 0;
280-
}
281-
282272
return 0;
283273
}
284274

@@ -1783,7 +1773,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17831773
const char *dir,
17841774
int prepend_cmd, int fhin, int fhout, int fherr)
17851775
{
1786-
static int restrict_handle_inheritance = -1;
17871776
STARTUPINFOEXW si;
17881777
PROCESS_INFORMATION pi;
17891778
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1803,16 +1792,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18031792
/* Make sure to override previous errors, if any */
18041793
errno = 0;
18051794

1806-
if (restrict_handle_inheritance < 0)
1807-
restrict_handle_inheritance = core_restrict_inherited_handles;
1808-
/*
1809-
* The following code to restrict which handles are inherited seems
1810-
* to work properly only on Windows 7 and later, so let's disable it
1811-
* on Windows Vista and 2008.
1812-
*/
1813-
if (restrict_handle_inheritance < 0)
1814-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1815-
18161795
do_unset_environment_variables();
18171796

18181797
/* Determine whether or not we are associated to a console */
@@ -1914,7 +1893,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19141893
wenvblk = make_environment_block(deltaenv);
19151894

19161895
memset(&pi, 0, sizeof(pi));
1917-
if (restrict_handle_inheritance && stdhandles_count &&
1896+
if (stdhandles_count &&
19181897
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
19191898
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
19201899
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1935,52 +1914,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19351914
&si.StartupInfo, &pi);
19361915

19371916
/*
1938-
* On Windows 2008 R2, it seems that specifying certain types of handles
1939-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1940-
* error. Rather than playing finicky and fragile games, let's just try
1941-
* to detect this situation and simply try again without restricting any
1942-
* handle inheritance. This is still better than failing to create
1943-
* processes.
1917+
* On the off-chance that something with the file handle restriction
1918+
* went wrong, silently fall back to trying without it.
19441919
*/
1945-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
1920+
if (!ret && stdhandles_count) {
19461921
DWORD err = GetLastError();
19471922
struct strbuf buf = STRBUF_INIT;
19481923

1949-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
1950-
/*
1951-
* On Windows 7 and earlier, handles on pipes and character
1952-
* devices are inherited automatically, and cannot be
1953-
* specified in the thread handle list. Rather than trying
1954-
* to catch each and every corner case (and running the
1955-
* chance of *still* forgetting a few), let's just fall
1956-
* back to creating the process without trying to limit the
1957-
* handle inheritance.
1958-
*/
1959-
!(err == ERROR_INVALID_PARAMETER &&
1960-
GetVersion() >> 16 < 9200) &&
1961-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
1962-
DWORD fl = 0;
1963-
int i;
1964-
1965-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
1966-
1967-
for (i = 0; i < stdhandles_count; i++) {
1968-
HANDLE h = stdhandles[i];
1969-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
1970-
"handle info (%d) %lx\n", i, h,
1971-
GetFileType(h),
1972-
GetHandleInformation(h, &fl),
1973-
fl);
1974-
}
1975-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
1976-
"at\nhttps://github.com/git-for-windows/"
1977-
"git/issues/new\n\n"
1978-
"To suppress this warning, please set "
1979-
"the environment variable\n\n"
1980-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1981-
"\n");
1982-
}
1983-
restrict_handle_inheritance = 0;
19841924
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
19851925
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
19861926
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)