]> xenbits.xensource.com Git - libvirt.git/commitdiff
rpc: Fix getsockopt on Snow Leopard and lower
authorDoug Goldstein <cardoe@cardoe.com>
Thu, 10 Oct 2013 21:31:47 +0000 (16:31 -0500)
committerDoug Goldstein <cardoe@cardoe.com>
Fri, 11 Oct 2013 14:22:57 +0000 (09:22 -0500)
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

index a2823efc3a0f9bb871f2276afef745fb5e9ad784..e8cdfa6435020d1b9472913795a9a6cf5079ff38 100644 (file)
@@ -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);