Fix #6147 DB corruption from child process overwrite

Don't leave stdout/stderr dangling on a fork.
This commit is contained in:
Howard Chu 2019-11-17 11:41:09 +00:00 committed by wowario
parent 0a825e0a3e
commit 5267747297
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111
1 changed files with 6 additions and 1 deletions

View File

@ -127,13 +127,18 @@ void fork(const std::string & pidfile)
{
quit("Unable to open output file: " + output);
}
#else
if (open("/dev/null", O_WRONLY) < 0)
{
quit("Unable to open /dev/null");
}
#endif
// Also send standard error to the same log file.
if (dup(1) < 0)
{
quit("Unable to dup output descriptor");
}
#endif
}
} // namespace posix