From: Simon McVittie Date: Thu, 21 Jul 2016 07:27:36 +0000 (+0100) Subject: _read_subprocess_line_argv: use _dbus_ensure_standard_fds X-Git-Tag: dbus-1.11.4~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e4724af4ee03c8f624dd83402b90a5ddf8dd94dd;p=thirdparty%2Fdbus.git _read_subprocess_line_argv: use _dbus_ensure_standard_fds This also gives us an opportunity to improve the error reporting. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008 Signed-off-by: Simon McVittie Reviewed-by: Thiago Macieira --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 700b8315b..992381d0e 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 */