Fix stderr being improperly closed during daemonization

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-07-25 17:02:11 -07:00
parent 066ed2b2b2
commit ba1a8fd8c7

View file

@ -7305,12 +7305,11 @@ void RedBean(int argc, char *argv[]) {
-1, 0)));
if (daemonize) {
for (int i = 0; i < 256; ++i) {
if (!IsServerFd(i)) {
close(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)));