[PATCH] rpc: Fix getsockopt on Snow Leopard and lower

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
---
v2:
* Refactored ifdef outside of the function and create a define for the
  second argument of getsockopt().
---
 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 a2823ef..e8cdfa6 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);
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]