[libvirt] Initial working Mac OS X libvirt client build

Daniel P. Berrange berrange at redhat.com
Mon Oct 25 08:48:36 UTC 2010


On Mon, Oct 25, 2010 at 10:37:36AM +0200, Ruben Kerkhof wrote:
> On Mon, Oct 25, 2010 at 10:20, Ruben Kerkhof <ruben at rubenkerkhof.com> wrote:
> > On Mon, Oct 25, 2010 at 07:09, Justin Clift <jclift at redhat.com> wrote:
> >> On 10/25/2010 12:18 PM, Ruben Kerkhof wrote:
> >>> On Sun, Oct 24, 2010 at 02:46, Justin Clift <jclift at redhat.com> wrote:
> >>>> On 10/24/2010 09:33 AM, Ruben Kerkhof wrote:
> >>>> <snip>
> >>>>> None at all, actually. I just started libvirtd on my local mac on
> >>>>> which I also have VirtualBox installed.
> >>>>> Speaking of which, it would be nice to have a launchctl file for
> >>>>> libvirtd. I might be able to come up with something...
> >>>>
> >>>> Please do. It'd be nice to have that part working "out of the box" for
> >>>> people as well. :)
> >>>
> >>> For that to work, I'd like to run libvirtd as my own user, so I can
> >>> add the launchtl file to my own Library directory.
> >>>
> >>> I'm curious, can you successfully run libvirtd as your own user (no sudo)?
> >>>
> >>> 03:10:17.562: error : qemudListenUnix:582 : Failed to bind socket to
> >>> '@/Users/ruben/.libvirt/libvirt-sock': No such file or directory
> >>
> >> Actually, that looks familiar.  I think I tried the same thing, but was
> >> ok running it as root instead after getting the same error.
> >>
> >> I didn't look into it any more though. ;)
> >>
> >>
> >>> Stepping through the code now, I see 2 (possible) issues:
> >>>
> >>> First: qemudInitPaths doesn't seem to create the ~/.libvirt directory
> >>> Second: in qemudListenUnix, this piece of code:
> >>>
> >>> addr.sun_family = AF_UNIX;
> >>>     if (virStrcpyStatic(addr.sun_path, path) == NULL) {
> >>>         VIR_ERROR(_("Path %s too long for unix socket"), path);
> >>>         goto cleanup;
> >>>     }
> >>>     if (addr.sun_path[0] == '@')
> >>>         addr.sun_path[0] = '\0';
> >>>
> >>> So the first byte of the sun_path is '\0', something that Leopard
> >>> doesn't seem to like.
> >>> Breaking into gdb and setting the path manually to
> >>> "/Users/ruben/.libvirt/libvirt-sock" seems to work.
> >>
> >> Interesting.  We can definitely pull together a temporary OSX workaround
> >> patch for the moment (purely in the Homebrew formula).  But it would be
> >> better to have a proper fix in libvirt instead.
> >>
> >> How good is your C coding? :)
> >
> > Terrible ;) I think the easiest fix is
> >
> > if (addr[0] == '@')
> >    addr[0] = '\0';
> 
> Argh, I meant path[0] here of course.
> 
> >
> > if (virStrcpyStatic(addr.sun_path, path) == NULL) {
> >    VIR_ERROR(_("Path %s too long for unix socket"), path);
> >   goto cleanup;
> > }
> >
> > Or am I missing something?
> >
> > I haven't been able to bootstrap a build from libvirt git yet, mainly
> > gettext issues.
> > Otherwise I would have come up with a proper patch.
> >
> > Thanks,
> >
> > Ruben
> 
> Here's a (completely untested) patch. I will have more time tomorrow
> to dig into this.
> 
> >From 3fa6bcfca4bb50b18935cc4637426ef3ac3cdcbd Mon Sep 17 00:00:00 2001
> From: Ruben Kerkhof <ruben at tilaa.nl>
> Date: Mon, 25 Oct 2010 10:31:15 +0200
> Subject: [PATCH] Fix binding to a unix socket on OSX
> 
> addr.sun_path doesn't like the first
> byte to be NULL
> 
> Signed-off-by: Ruben Kerkhof <ruben at tilaa.nl>
> ---
>  daemon/libvirtd.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
> index 8e88d05..76b8dc8 100644
> --- a/daemon/libvirtd.c
> +++ b/daemon/libvirtd.c
> @@ -571,13 +571,14 @@ static int qemudListenUnix(struct qemud_server *server,
>          virSetNonBlock(sock->fd) < 0)
>          goto cleanup;
> 
> +    if (path[0] == '@')
> +        path[0] = '\0';
> +
>      sock->addr.data.un.sun_family = AF_UNIX;
>      if (virStrcpyStatic(sock->addr.data.un.sun_path, path) == NULL) {
>          VIR_ERROR(_("Path %s too long for unix socket"), path);
>          goto cleanup;
>      }
> -    if (sock->addr.data.un.sun_path[0] == '@')
> -        sock->addr.data.un.sun_path[0] = '\0';

NACK, this results in 'path' being a zer-length string, so no data is
copied in the next virStrcpyStatic line. The original code is correctly
creating a socket in the abstract namespace, ie one which does not
appear in the filesystem

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list