From 1db94fe8a729e4f3a22af9f76ee6dae1dbb2c712 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 12 Jul 2016 21:35:34 +0100 Subject: [PATCH 06/10] dbus-launch: use _dbus_open_standard_fds() in the babysitter Signed-off-by: Simon McVittie --- tools/dbus-launch.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index b58026f..49f3af4 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -612,8 +612,8 @@ babysit (int exit_with_session, pid_t child_pid, int read_bus_pid_fd) /* read pid from here */ { + DBusOpenStandardFdsFlags flags; int ret; - int dev_null_fd; const char *s; verbose ("babysitting, exit_with_session = %d, child_pid = %ld, read_bus_pid_fd = %d\n", @@ -633,28 +633,26 @@ babysit (int exit_with_session, exit (1); } + flags = DBUS_OPEN_STDOUT_NULL; + + if (!exit_with_session) + flags |= DBUS_OPEN_STDIN_NULL; + + s = getenv ("DBUS_DEBUG_OUTPUT"); + + if (s == NULL || *s == '\0') + flags |= DBUS_OPEN_STDERR_NULL; + /* Close stdout/stderr so we don't block an "eval" or otherwise * lock up. stdout is still chaining through to dbus-launch * and in turn to the parent shell. */ - dev_null_fd = open ("/dev/null", O_RDWR); - if (dev_null_fd >= 0) - { - if (!exit_with_session) - dup2 (dev_null_fd, 0); - dup2 (dev_null_fd, 1); - s = getenv ("DBUS_DEBUG_OUTPUT"); - if (s == NULL || *s == '\0') - dup2 (dev_null_fd, 2); - close (dev_null_fd); - } - else + if (!_dbus_open_standard_fds (flags, &s)) { - fprintf (stderr, "Failed to open /dev/null: %s\n", - strerror (errno)); - /* continue, why not */ + fprintf (stderr, "%s: %s\n", s, strerror (errno)); + exit (1); } - + ret = fork (); if (ret < 0) -- 2.8.1