From 64b84d3cf9df0cde90aee0afa7a5f9fb42362a29 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 18 Sep 2013 17:51:53 +0100 Subject: [PATCH 6/7] If sendmsg() with SCM_CREDS fails with EINVAL, retry with send() 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 --- dbus/dbus-sysdeps-unix.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 0708004..13a0e98 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -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; -- 1.8.4.rc3