Skip to content

Commit

Permalink
Merge pull request #1230 from Sonicadvance1/fix_stdio_log
Browse files Browse the repository at this point in the history
FEXLoader: Fixes potential bug in log output to stdout/stderr
  • Loading branch information
Sonicadvance1 authored Aug 28, 2021
2 parents 097b3ad + de64db5 commit 1092229
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Source/Tests/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,18 @@ int main(int argc, char **argv, char **const envp) {

if (!::SilentLog) {
auto LogFile = OutputLog();
// If stderr or stdout then we need to dup the FD
// In some cases some applications will close stderr and stdout
// then redirect the FD to either a log OR some cases just not use
// stderr/stdout and the FD will be reused for regular FD ops.
//
// We want to maintain the original output location otherwise we
// can run in to problems of writing to some file
if (LogFile == "stderr") {
OutputFD = STDERR_FILENO;
OutputFD = dup(STDERR_FILENO);
}
else if (LogFile == "stdout") {
OutputFD = STDOUT_FILENO;
OutputFD = dup(STDOUT_FILENO);
}
else if (!LogFile.empty()) {
OutputFD = open(LogFile.c_str(), O_CREAT | O_CLOEXEC | O_WRONLY);
Expand Down

0 comments on commit 1092229

Please sign in to comment.