Skip to content

Commit 35abdc6

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 cdc340f + 1184ccc commit 35abdc6

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

707-
core.restrictinheritedhandles::
708-
Windows-only: override whether spawned processes inherit only standard
709-
file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
710-
`auto`, `true` or `false`. Defaults to `auto`, which means `true` on
711-
Windows 7 and later, and `false` on older Windows versions.
712-
713707
core.createObject::
714708
You can set this to 'link', in which case a hardlink followed by
715709
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
@@ -274,7 +274,6 @@ enum hide_dotfiles_type {
274274
HIDE_DOTFILES_DOTGITONLY
275275
};
276276

277-
static int core_restrict_inherited_handles = -1;
278277
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
279278
static char *unset_environment_variables;
280279
int core_fscache;
@@ -325,15 +324,6 @@ int mingw_core_config(const char *var, const char *value,
325324
return 0;
326325
}
327326

328-
if (!strcmp(var, "core.restrictinheritedhandles")) {
329-
if (value && !strcasecmp(value, "auto"))
330-
core_restrict_inherited_handles = -1;
331-
else
332-
core_restrict_inherited_handles =
333-
git_config_bool(var, value);
334-
return 0;
335-
}
336-
337327
return 0;
338328
}
339329

@@ -2063,7 +2053,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20632053
const char *dir, const char *prepend_cmd,
20642054
int fhin, int fhout, int fherr)
20652055
{
2066-
static int restrict_handle_inheritance = -1;
20672056
STARTUPINFOEXW si;
20682057
PROCESS_INFORMATION pi;
20692058
LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -2083,16 +2072,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20832072
/* Make sure to override previous errors, if any */
20842073
errno = 0;
20852074

2086-
if (restrict_handle_inheritance < 0)
2087-
restrict_handle_inheritance = core_restrict_inherited_handles;
2088-
/*
2089-
* The following code to restrict which handles are inherited seems
2090-
* to work properly only on Windows 7 and later, so let's disable it
2091-
* on Windows Vista and 2008.
2092-
*/
2093-
if (restrict_handle_inheritance < 0)
2094-
restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
2095-
20962075
do_unset_environment_variables();
20972076

20982077
/* Determine whether or not we are associated to a console */
@@ -2198,7 +2177,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21982177
wenvblk = make_environment_block(deltaenv);
21992178

22002179
memset(&pi, 0, sizeof(pi));
2201-
if (restrict_handle_inheritance && stdhandles_count &&
2180+
if (stdhandles_count &&
22022181
(InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
22032182
GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
22042183
(attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -2219,52 +2198,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22192198
&si.StartupInfo, &pi);
22202199

22212200
/*
2222-
* On Windows 2008 R2, it seems that specifying certain types of handles
2223-
* (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
2224-
* error. Rather than playing finicky and fragile games, let's just try
2225-
* to detect this situation and simply try again without restricting any
2226-
* handle inheritance. This is still better than failing to create
2227-
* processes.
2201+
* On the off-chance that something with the file handle restriction
2202+
* went wrong, silently fall back to trying without it.
22282203
*/
2229-
if (!ret && restrict_handle_inheritance && stdhandles_count) {
2204+
if (!ret && stdhandles_count) {
22302205
DWORD err = GetLastError();
22312206
struct strbuf buf = STRBUF_INIT;
22322207

2233-
if (err != ERROR_NO_SYSTEM_RESOURCES &&
2234-
/*
2235-
* On Windows 7 and earlier, handles on pipes and character
2236-
* devices are inherited automatically, and cannot be
2237-
* specified in the thread handle list. Rather than trying
2238-
* to catch each and every corner case (and running the
2239-
* chance of *still* forgetting a few), let's just fall
2240-
* back to creating the process without trying to limit the
2241-
* handle inheritance.
2242-
*/
2243-
!(err == ERROR_INVALID_PARAMETER &&
2244-
GetVersion() >> 16 < 9200) &&
2245-
!getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
2246-
DWORD fl = 0;
2247-
int i;
2248-
2249-
setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
2250-
2251-
for (i = 0; i < stdhandles_count; i++) {
2252-
HANDLE h = stdhandles[i];
2253-
strbuf_addf(&buf, "handle #%d: %p (type %lx, "
2254-
"handle info (%d) %lx\n", i, h,
2255-
GetFileType(h),
2256-
GetHandleInformation(h, &fl),
2257-
fl);
2258-
}
2259-
strbuf_addstr(&buf, "\nThis is a bug; please report it "
2260-
"at\nhttps://github.com/git-for-windows/"
2261-
"git/issues/new\n\n"
2262-
"To suppress this warning, please set "
2263-
"the environment variable\n\n"
2264-
"\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
2265-
"\n");
2266-
}
2267-
restrict_handle_inheritance = 0;
22682208
flags &= ~EXTENDED_STARTUPINFO_PRESENT;
22692209
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
22702210
TRUE, flags, wenvblk, dir ? wdir : NULL,

0 commit comments

Comments
 (0)