Skip to content

Commit d5ba87c

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 a9e9fbd + f21432b commit d5ba87c

File tree

2 files changed

+4
-70
lines changed

2 files changed

+4
-70
lines changed

Documentation/config/core.adoc

-6
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,6 @@ core.unsetenvvars::
691691
Defaults to `PERL5LIB` to account for the fact that Git for
692692
Windows insists on using its own Perl interpreter.
693693

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

compat/mingw.c

+4-64
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ enum hide_dotfiles_type {
243243
HIDE_DOTFILES_DOTGITONLY
244244
};
245245

246-
static int core_restrict_inherited_handles = -1;
247246
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
248247
static char *unset_environment_variables;
249248

@@ -267,15 +266,6 @@ int mingw_core_config(const char *var, const char *value,
267266
return 0;
268267
}
269268

270-
if (!strcmp(var, "core.restrictinheritedhandles")) {
271-
if (value && !strcasecmp(value, "auto"))
272-
core_restrict_inherited_handles = -1;
273-
else
274-
core_restrict_inherited_handles =
275-
git_config_bool(var, value);
276-
return 0;
277-
}
278-
279269
return 0;
280270
}
281271

@@ -1760,7 +1750,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17601750
const char *dir,
17611751
int prepend_cmd, int fhin, int fhout, int fherr)
17621752
{
1763-
static int restrict_handle_inheritance = -1;
17641753
STARTUPINFOEXW si;
17651754
PROCESS_INFORMATION pi;
17661755
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1780,16 +1769,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17801769
/* Make sure to override previous errors, if any */
17811770
errno = 0;
17821771

1783-
if (restrict_handle_inheritance < 0)
1784-
restrict_handle_inheritance = core_restrict_inherited_handles;
1785-
/*
1786-
* The following code to restrict which handles are inherited seems
1787-
* to work properly only on Windows 7 and later, so let's disable it
1788-
* on Windows Vista and 2008.
1789-
*/
1790-
if (restrict_handle_inheritance < 0)
1791-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1792-
17931772
do_unset_environment_variables();
17941773

17951774
/* Determine whether or not we are associated to a console */
@@ -1891,7 +1870,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18911870
wenvblk = make_environment_block(deltaenv);
18921871

18931872
memset(&pi, 0, sizeof(pi));
1894-
if (restrict_handle_inheritance && stdhandles_count &&
1873+
if (stdhandles_count &&
18951874
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
18961875
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
18971876
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1912,52 +1891,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19121891
&si.StartupInfo, &pi);
19131892

19141893
/*
1915-
* On Windows 2008 R2, it seems that specifying certain types of handles
1916-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1917-
* error. Rather than playing finicky and fragile games, let's just try
1918-
* to detect this situation and simply try again without restricting any
1919-
* handle inheritance. This is still better than failing to create
1920-
* processes.
1894+
* On the off-chance that something with the file handle restriction
1895+
* went wrong, silently fall back to trying without it.
19211896
*/
1922-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
1897+
if (!ret && stdhandles_count) {
19231898
DWORD err = GetLastError();
19241899
struct strbuf buf = STRBUF_INIT;
19251900

1926-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
1927-
/*
1928-
* On Windows 7 and earlier, handles on pipes and character
1929-
* devices are inherited automatically, and cannot be
1930-
* specified in the thread handle list. Rather than trying
1931-
* to catch each and every corner case (and running the
1932-
* chance of *still* forgetting a few), let's just fall
1933-
* back to creating the process without trying to limit the
1934-
* handle inheritance.
1935-
*/
1936-
!(err == ERROR_INVALID_PARAMETER &&
1937-
GetVersion() >> 16 < 9200) &&
1938-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
1939-
DWORD fl = 0;
1940-
int i;
1941-
1942-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
1943-
1944-
for (i = 0; i < stdhandles_count; i++) {
1945-
HANDLE h = stdhandles[i];
1946-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
1947-
"handle info (%d) %lx\n", i, h,
1948-
GetFileType(h),
1949-
GetHandleInformation(h, &fl),
1950-
fl);
1951-
}
1952-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
1953-
"at\nhttps://github.com/git-for-windows/"
1954-
"git/issues/new\n\n"
1955-
"To suppress this warning, please set "
1956-
"the environment variable\n\n"
1957-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1958-
"\n");
1959-
}
1960-
restrict_handle_inheritance = 0;
19611901
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
19621902
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
19631903
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)