]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
If sendmsg() with SCM_CREDS fails with EINVAL, retry with send()
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 18 Sep 2013 16:51:53 +0000 (17:51 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 6 Jan 2014 15:49:41 +0000 (15:49 +0000)
Perhaps some OSs accept and ignore attempts to send a SCM_CREDS
message on a non-Unix socket, but GNU/kFreeBSD doesn't (and presumably
FreeBSD doesn't either).

Based on a patch by Svante Signell.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69492
Tested-by: Svante Signell
Reviewed-by: Chengwei Yang <chengwei.yang@intel.com>
dbus/dbus-sysdeps-unix.c

index 19f5ea30a5e29b013493d09622e657f9eba2dd10..c12f294e2d85d217d4322c6daf60142f82e2f526 100644 (file)
@@ -1572,13 +1572,19 @@ write_credentials_byte (int             server_fd,
                            |MSG_NOSIGNAL
 #endif
                            );
-#else
-  bytes_written = send (server_fd, buf, 1, 0
-#if HAVE_DECL_MSG_NOSIGNAL
-                        |MSG_NOSIGNAL
+
+  /* If we HAVE_CMSGCRED, the OS still might not let us sendmsg()
+   * with a SOL_SOCKET/SCM_CREDS message - for instance, FreeBSD
+   * only allows that on AF_UNIX. Try just doing a send() instead. */
+  if (bytes_written < 0 && errno == EINVAL)
 #endif
-                        );
+    {
+      bytes_written = send (server_fd, buf, 1, 0
+#if HAVE_DECL_MSG_NOSIGNAL
+                            |MSG_NOSIGNAL
 #endif
+                            );
+    }
 
   if (bytes_written < 0 && errno == EINTR)
     goto again;