Fix stderr being improperly closed during daemonization (#513)

This may happen when ProgramLogPath is used after a file descriptor is
already used by an earlier call (for example, to open an SQLite file).
This commit is contained in:
Paul Kulchenko 2022-08-05 14:57:17 -07:00 committed by GitHub
parent 5f552338d6
commit 449fb2fb59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7320,12 +7320,11 @@ void RedBean(int argc, char *argv[]) {
-1, 0)));
if (daemonize) {
for (int i = 0; i < 256; ++i) {
if (!IsServerFd(i)) {
close(i);
}
}
open("/dev/null", O_RDONLY);
open("/dev/null", O_WRONLY);
open("/dev/null", O_WRONLY);
}
zpath = GetProgramExecutableName();
CHECK_NE(-1, (zfd = open(zpath, O_RDONLY)));