]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-launch: use _dbus_ensure_standard_fds when closing stderr
authorSimon McVittie <smcv@debian.org>
Thu, 21 Jul 2016 07:27:06 +0000 (08:27 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 25 Jul 2016 10:27:03 +0000 (11:27 +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 1a39800d28119696c60df919840224d68c5843df..afc1d911aa1fdeae5c529dfbe7878133c2db7212 100644 (file)
@@ -723,27 +723,15 @@ babysit (int   exit_with_session,
 static void
 do_close_stderr (void)
 {
-  int fd;
+  const char *err;
 
   fflush (stderr);
 
-  /* dbus-launch is a Unix-only program, so we can rely on /dev/null being there.
-   * We're including unistd.h and we're dealing with sh/csh launch sequences...
-   */
-  fd = open ("/dev/null", O_RDWR);
-  if (fd == -1)
-    {
-      fprintf (stderr, "Internal error: cannot open /dev/null: %s", strerror (errno));
-      exit (1);
-    }
-
-  close (2);
-  if (dup2 (fd, 2) == -1)
+  if (!_dbus_ensure_standard_fds (DBUS_FORCE_STDERR_NULL, &err))
     {
-      /* error; we can't report an error anymore... */
+      fprintf (stderr, "%s: %s\n", err, strerror (errno));
       exit (1);
     }
-  close (fd);
 }
 
 static void