From fd0e1e11e9addd9823c94762c2e27015f0cfecff Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 12 Jul 2016 21:36:32 +0100 Subject: [PATCH 08/10] _read_subprocess_line_argv: use _dbus_open_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 b00546e..7332c09 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3601,21 +3601,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_open_standard_fds (DBUS_OPEN_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