]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Check EINVAL for socketpair and retry without SOCK_CLOEXEC
authorChengwei Yang <chengwei.yang@intel.com>
Tue, 10 Sep 2013 14:29:19 +0000 (22:29 +0800)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 13 Sep 2013 12:33:21 +0000 (13:33 +0100)
As the same as _dbus_open_socket() and _dbus_full_duplex_pipe(),
socketpair() may fail with EINVAL if call with SOCK_CLOEXEC.

Check for the failure and retry without SOCK_CLOEXEC, in addition, only
call _dbus_fd_set_close_on_exec() if the socketpair failure happened.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69073
[trivial coding style fixes -smcv]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
dbus/dbus-sysdeps-unix.c

index e31c735588e92a1d5ad84fb2ddcb2d4358bbd021..b84ad0e97d5deb313030410c06cbebb9b374eee5 100644 (file)
@@ -887,16 +887,24 @@ _dbus_connect_exec (const char     *path,
 {
   int fds[2];
   pid_t pid;
+  int retval;
+  dbus_bool_t cloexec_done = 0;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
   _dbus_verbose ("connecting to process %s\n", path);
 
-  if (socketpair (AF_UNIX, SOCK_STREAM
 #ifdef SOCK_CLOEXEC
-                  |SOCK_CLOEXEC
+  retval = socketpair (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
+  cloexec_done = (retval >= 0);
+
+  if (retval < 0 && (errno == EINVAL))
 #endif
-                  , 0, fds) < 0)
+    {
+      retval = socketpair (AF_UNIX, SOCK_STREAM, 0, fds);
+    }
+
+  if (retval < 0)
     {
       dbus_set_error (error,
                       _dbus_error_from_errno (errno),
@@ -905,8 +913,11 @@ _dbus_connect_exec (const char     *path,
       return -1;
     }
 
-  _dbus_fd_set_close_on_exec (fds[0]);
-  _dbus_fd_set_close_on_exec (fds[1]);
+  if (!cloexec_done)
+    {
+      _dbus_fd_set_close_on_exec (fds[0]);
+      _dbus_fd_set_close_on_exec (fds[1]);
+    }
 
   pid = fork ();
   if (pid < 0)