From abaefdf829383b1403a516770b8a7eb8521dc8c5 Mon Sep 17 00:00:00 2001 From: weetmuts Date: Tue, 13 Aug 2019 20:46:50 +0200 Subject: [PATCH] Properly reopen stdin,stdout and stderr in daemon. --- src/main.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cc b/src/main.cc index ace3177..9b48d0d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -409,6 +409,15 @@ void startDaemon(string pid_file) close(STDOUT_FILENO); close(STDERR_FILENO); + if (open("/dev/null", O_RDONLY) == -1) { + error("Failed to reopen stdin while daemonising (errno=%d)",errno); + } + if (open("/dev/null", O_WRONLY) == -1) { + error("Failed to reopen stdout while daemonising (errno=%d)",errno); + } + if (open("/dev/null", O_RDWR) == -1) { + error("Failed to reopen stderr while daemonising (errno=%d)",errno); + } startUsingConfigFiles("", true); }