From fce5d46d60bdb724903ee694269209b75ab5b5be Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 21 Jul 2016 08:27:06 +0100 Subject: [PATCH] dbus-launch: use _dbus_ensure_standard_fds when closing stderr Signed-off-by: Simon McVittie --- tools/dbus-launch.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 1a39800..afc1d91 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -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 -- 2.8.1