From dc1008f9afb1c1bb942e6a76359ba379f241828a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 21 Jul 2016 08:27:36 +0100 Subject: [PATCH] _read_subprocess_line_argv: use _dbus_ensure_standard_fds This also gives us an opportunity to improve the error reporting. Signed-off-by: Simon McVittie --- dbus/dbus-sysdeps-unix.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 700b831..992381d 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3605,21 +3605,35 @@ _read_subprocess_line_argv (const char *progpath, if (pid == 0) { /* child process */ - int fd; + const char *error_str; - fd = open ("/dev/null", O_RDWR); - if (fd == -1) - /* huh?! can't open /dev/null? */ - _exit (1); + if (!_dbus_ensure_standard_fds (DBUS_FORCE_STDIN_NULL, &error_str)) + { + int saved_errno = errno; + + /* Try to write details into the pipe, but don't bother + * trying too hard (no retry loop). */ + + if (write (errors_pipe[WRITE_END], error_str, strlen (error_str)) < 0 || + write (errors_pipe[WRITE_END], ": ", 2) < 0) + { + /* ignore, not much we can do */ + } - _dbus_verbose ("/dev/null fd %d opened\n", fd); + error_str = _dbus_strerror (saved_errno); + + if (write (errors_pipe[WRITE_END], error_str, strlen (error_str)) < 0) + { + /* ignore, not much we can do */ + } + + _exit (1); + } /* set-up stdXXX */ close (result_pipe[READ_END]); close (errors_pipe[READ_END]); - if (dup2 (fd, 0) == -1) /* setup stdin */ - _exit (1); if (dup2 (result_pipe[WRITE_END], 1) == -1) /* setup stdout */ _exit (1); if (dup2 (errors_pipe[WRITE_END], 2) == -1) /* setup stderr */ -- 2.8.1