launch_daemon: Open stdin/out/err FDs.

* As with the boot script, point them to /dev/null.
* This should fix #12298.
This commit is contained in:
Axel Dörfler
2015-09-11 09:01:26 +02:00
parent e668e80db0
commit 16844b92fc
+16
View File
@@ -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);