From 16844b92fc2f3f6cec988f0bb873c7a5da436fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 11 Sep 2015 09:01:26 +0200 Subject: [PATCH] launch_daemon: Open stdin/out/err FDs. * As with the boot script, point them to /dev/null. * This should fix #12298. --- src/servers/launch/LaunchDaemon.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/servers/launch/LaunchDaemon.cpp b/src/servers/launch/LaunchDaemon.cpp index f9733f916c..8b0d2200b7 100644 --- a/src/servers/launch/LaunchDaemon.cpp +++ b/src/servers/launch/LaunchDaemon.cpp @@ -1291,9 +1291,25 @@ LaunchDaemon::_AddInitJob(BJob* job) // #pragma mark - +static void +open_stdio(int targetFD, int openMode) +{ + int fd = open("/dev/null", openMode); + if (fd != targetFD) { + dup2(fd, targetFD); + close(fd); + } +} + + int main() { + // Make stdin/out/err available + open_stdio(STDIN_FILENO, O_RDONLY); + open_stdio(STDOUT_FILENO, O_WRONLY); + dup2(STDOUT_FILENO, STDERR_FILENO); + EventMap events; status_t status; LaunchDaemon* daemon = new LaunchDaemon(false, events, status);