]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-launch: use _dbus_ensure_standard_fds() in the babysitter
authorSimon McVittie <smcv@debian.org>
Thu, 21 Jul 2016 07:26:40 +0000 (08:26 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 25 Jul 2016 10:26:52 +0000 (11:26 +0100)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Thiago Macieira <thiago@kde.org>
tools/dbus-launch.c

index 763c7b8e9d2355d9dba280e234de1abb1a4249c3..1a39800d28119696c60df919840224d68c5843df 100644 (file)
@@ -612,8 +612,8 @@ babysit (int   exit_with_session,
          pid_t child_pid,
          int   read_bus_pid_fd)  /* read pid from here */
 {
+  DBusEnsureStandardFdsFlags 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_FORCE_STDOUT_NULL;
+
+  if (!exit_with_session)
+    flags |= DBUS_FORCE_STDIN_NULL;
+
+  s = getenv ("DBUS_DEBUG_OUTPUT");
+
+  if (s == NULL || *s == '\0')
+    flags |= DBUS_FORCE_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 (!_dbus_ensure_standard_fds (flags, &s))
     {
-      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
-    {
-      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)