From: Simon McVittie Date: Wed, 18 Sep 2013 16:51:53 +0000 (+0100) Subject: If sendmsg() with SCM_CREDS fails with EINVAL, retry with send() X-Git-Tag: dbus-1.7.10~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ca8a53e336a1a829bae93c70fe617af6493201a;p=thirdparty%2Fdbus.git 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 Tested-by: Svante Signell Reviewed-by: Chengwei Yang --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 19f5ea30a..c12f294e2 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;