From 2f776d49796fe34dcf5a876f4c4e34f79b66f705 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 10 Oct 2013 16:31:47 -0500 Subject: [PATCH] rpc: Fix getsockopt on Snow Leopard and lower Since 5a468b38b6 we use SOL_LOCAL for the 2nd argument of getsockopt() however Lion added the define SOL_LOCAL set to 0, which is the value to the 2nd argument of getsockopt() for Unix sockets on Mac OS X. So instead of using the define just pass 0 so we restore compatibility with Snow Leopard and Leopard. Reported at https://github.com/mxcl/homebrew/pull/23141 --- src/rpc/virnetsocket.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index a2823efc3a..e8cdfa6435 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1149,6 +1149,23 @@ cleanup: } #elif defined(LOCAL_PEERCRED) +/* VIR_SOL_PEERCRED - the value needed to let getsockopt() work with + * LOCAL_PEERCRED + */ +# ifdef __APPLE__ +# ifdef SOL_LOCAL +# define VIR_SOL_PEERCRED SOL_LOCAL +# else +/* Prior to Mac OS X 10.7, SOL_LOCAL was not defined and users were + * expected to supply 0 as the second value for getsockopt() when using + * LOCAL_PEERCRED + */ +# define VIR_SOL_PEERCRED 0 +# endif +# else +# define VIR_SOL_PEERCRED SOL_SOCKET +# endif + int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, uid_t *uid, gid_t *gid, @@ -1159,11 +1176,7 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, socklen_t cr_len = sizeof(cr); virObjectLock(sock); -# if defined(__APPLE__) - if (getsockopt(sock->fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &cr_len) < 0) { -# else - if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) { -# endif + if (getsockopt(sock->fd, VIR_SOL_PEERCRED, LOCAL_PEERCRED, &cr, &cr_len) < 0) { virReportSystemError(errno, "%s", _("Failed to get client socket identity")); virObjectUnlock(sock); -- GitLab