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

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

 



On 10/10/2013 03:44 PM, Doug Goldstein wrote:
> 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
> ---

> +++ b/src/rpc/virnetsocket.c
> @@ -1160,7 +1160,13 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
>      virObjectLock(sock);
>  
>  # if defined(__APPLE__)
> -    if (getsockopt(sock->fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
> +    /* Lion (10.7) and higher define the value to be passed to getsockopt()
> +     * as SOL_LOCAL for Unix sockets, it is defined to 0. However
> +     * Snow Leopard and lower did not have this define so you had to
> +     * pass 0. To support the most cases we just pass 0, this behavior
> +     * matches PostgreSQL and CUPS source code.
> +     */
> +    if (getsockopt(sock->fd, 0, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
>  # else
>      if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
>  # endif

You know, I think it might be even cleaner-looking if we could hoist the
ifdef outside of the function body.  Something like:

/* 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
#  define VIR_SOL_PEERCRED 0
# endif
#else
# define VIR_SOL_PEERCRED SOL_SOCKET
#endif
...
{
    if (getsockopt(sock->fd, VIR_SOL_PEERCRED, LOCAL_PEERCRED,
        &cr, &cr_len) < 0) {
...

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]