Skip to content

Commit ebed925

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 7b21ff8 + aaa78a7 commit ebed925

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
@@ -247,7 +247,6 @@ enum hide_dotfiles_type {
247247
HIDE_DOTFILES_DOTGITONLY
248248
};
249249

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

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

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

@@ -1784,7 +1774,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17841774
const char *dir,
17851775
int prepend_cmd, int fhin, int fhout, int fherr)
17861776
{
1787-
static int restrict_handle_inheritance = -1;
17881777
STARTUPINFOEXW si;
17891778
PROCESS_INFORMATION pi;
17901779
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1804,16 +1793,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18041793
/* Make sure to override previous errors, if any */
18051794
errno = 0;
18061795

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

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

19171896
memset(&pi, 0, sizeof(pi));
1918-
if (restrict_handle_inheritance && stdhandles_count &&
1897+
if (stdhandles_count &&
19191898
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
19201899
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
19211900
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1936,52 +1915,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19361915
&si.StartupInfo, &pi);
19371916

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

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

0 commit comments

Comments
 (0)