mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-12 18:33:22 +00:00
Fix redirection of stderr in sys::Program::ExecuteAndWait. There was logic
error that caused it to redirect stderr to stdout too often. This fix is applied identically to the win32 code as well, but that is untested. --Thi line, and those below, will be ignored-- M System/Unix/Program.inc M System/Win32/Program.inc git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52233 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
905261efed
commit
cf45ca0408
@ -170,14 +170,21 @@ Program::ExecuteAndWait(const Path& path,
|
|||||||
case 0: {
|
case 0: {
|
||||||
// Redirect file descriptors...
|
// Redirect file descriptors...
|
||||||
if (redirects) {
|
if (redirects) {
|
||||||
|
// Redirect stdin
|
||||||
if (RedirectIO(redirects[0], 0, ErrMsg)) { return -1; }
|
if (RedirectIO(redirects[0], 0, ErrMsg)) { return -1; }
|
||||||
|
// Redirect stdout
|
||||||
if (RedirectIO(redirects[1], 1, ErrMsg)) { return -1; }
|
if (RedirectIO(redirects[1], 1, ErrMsg)) { return -1; }
|
||||||
if (redirects[1] && redirects[2] &&
|
if (redirects[1] && redirects[2] &&
|
||||||
*(redirects[1]) != *(redirects[2])) {
|
*(redirects[1]) == *(redirects[2])) {
|
||||||
|
// If stdout and stderr should go to the same place, redirect stderr
|
||||||
|
// to the FD already open for stdout.
|
||||||
|
if (-1 == dup2(1,2)) {
|
||||||
|
MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Just redirect stderr
|
||||||
if (RedirectIO(redirects[2], 2, ErrMsg)) { return -1; }
|
if (RedirectIO(redirects[2], 2, ErrMsg)) { return -1; }
|
||||||
} else if (-1 == dup2(1,2)) {
|
|
||||||
MakeErrMsg(ErrMsg, "Can't redirect");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,14 @@ Program::ExecuteAndWait(const Path& path,
|
|||||||
MakeErrMsg(ErrMsg, "can't redirect stdout");
|
MakeErrMsg(ErrMsg, "can't redirect stdout");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (redirects[1] && redirects[2] && *(redirects[1]) != *(redirects[2])) {
|
if (redirects[1] && redirects[2] && *(redirects[1]) == *(redirects[2])) {
|
||||||
|
// If stdout and stderr should go to the same place, redirect stderr
|
||||||
|
// to the handle already open for stdout.
|
||||||
|
DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
|
||||||
|
GetCurrentProcess(), &si.hStdError,
|
||||||
|
0, TRUE, DUPLICATE_SAME_ACCESS);
|
||||||
|
} else {
|
||||||
|
// Just redirect stderr
|
||||||
si.hStdError = RedirectIO(redirects[2], 2, ErrMsg);
|
si.hStdError = RedirectIO(redirects[2], 2, ErrMsg);
|
||||||
if (si.hStdError == INVALID_HANDLE_VALUE) {
|
if (si.hStdError == INVALID_HANDLE_VALUE) {
|
||||||
CloseHandle(si.hStdInput);
|
CloseHandle(si.hStdInput);
|
||||||
@ -184,10 +191,6 @@ Program::ExecuteAndWait(const Path& path,
|
|||||||
MakeErrMsg(ErrMsg, "can't redirect stderr");
|
MakeErrMsg(ErrMsg, "can't redirect stderr");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
|
|
||||||
GetCurrentProcess(), &si.hStdError,
|
|
||||||
0, TRUE, DUPLICATE_SAME_ACCESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user