Skip to content

Commit a7e57c2

Browse files
committed
fixup! mingw: spawned processes need to inherit only standard handles
Use a more elegant way to de-duplicate the list of handles, suggested by Jeff Hostetler. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent e78e3c8 commit a7e57c2

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

compat/mingw.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,27 +1652,16 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16521652
si.StartupInfo.hStdOutput = winansi_get_osfhandle(fhout);
16531653
si.StartupInfo.hStdError = winansi_get_osfhandle(fherr);
16541654

1655+
/* The list of handles cannot contain duplicates */
16551656
if (si.StartupInfo.hStdInput != INVALID_HANDLE_VALUE)
16561657
stdhandles[stdhandles_count++] = si.StartupInfo.hStdInput;
1657-
if (si.StartupInfo.hStdOutput != INVALID_HANDLE_VALUE)
1658+
if (si.StartupInfo.hStdOutput != INVALID_HANDLE_VALUE &&
1659+
si.StartupInfo.hStdOutput != si.StartupInfo.hStdInput)
16581660
stdhandles[stdhandles_count++] = si.StartupInfo.hStdOutput;
1659-
if (si.StartupInfo.hStdError != INVALID_HANDLE_VALUE)
1661+
if (si.StartupInfo.hStdError != INVALID_HANDLE_VALUE &&
1662+
si.StartupInfo.hStdError != si.StartupInfo.hStdInput &&
1663+
si.StartupInfo.hStdError != si.StartupInfo.hStdOutput)
16601664
stdhandles[stdhandles_count++] = si.StartupInfo.hStdError;
1661-
1662-
/* The list of handles cannot contain duplicates */
1663-
if (stdhandles_count == 3) {
1664-
if (stdhandles[2] == stdhandles[0])
1665-
stdhandles_count =
1666-
stdhandles[2] == stdhandles[1] ? 1 : 2;
1667-
else if (stdhandles[2] == stdhandles[1])
1668-
stdhandles_count = 2;
1669-
else if (stdhandles[1] == stdhandles[0]) {
1670-
stdhandles_count = 2;
1671-
stdhandles[1] = stdhandles[2];
1672-
}
1673-
} else if (stdhandles_count == 2 && stdhandles[1] == stdhandles[0])
1674-
stdhandles_count = 1;
1675-
16761665
if (stdhandles_count)
16771666
si.StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
16781667

0 commit comments

Comments
 (0)