]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_read_subprocess_line_argv: use _dbus_ensure_standard_fds
authorSimon McVittie <smcv@debian.org>
Thu, 21 Jul 2016 07:27:36 +0000 (08:27 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 25 Jul 2016 10:27:13 +0000 (11:27 +0100)
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 <smcv@debian.org>
Reviewed-by: Thiago Macieira <thiago@kde.org>
dbus/dbus-sysdeps-unix.c

index 700b8315b1f9ba0a7709db9e897e95049ab24507..992381d0e82ede24062cfb425b9fd3c6f039b282 100644 (file)
@@ -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 */