[libvirt-users] Callback re-registration after libvirtd restart

Daniel Kučera libvirt at danman.eu
Wed May 17 13:08:23 UTC 2017


Hi all,

I'm using libvirt-go and I following code to listen for lifecycle events:

func event_listen() {
    log.Printf("event_listen %s", conf.Libvirt.LocalUrl)
    hv, err := libvirt.NewConnect(conf.Libvirt.LocalUrl)

    lifecycleCallback := func(c *libvirt.Connect, d *libvirt.Domain, event
*libvirt.DomainEventLifecycle) {
        event_message(c, d, "lifecycle", event)
    }

    _, err = hv.DomainEventLifecycleRegister(nil, lifecycleCallback)
    if err != nil {
        log.Printf("unable to register event callback")
        return
    }

    log.Printf("Libvirt event listener started")

    go func() {
        for err == nil {
            err = libvirt.EventRunDefaultImpl()
            log.Printf("EventRunDefaultImpl err: %+v", err)
        }
        time.Sleep(time.Second)
        event_listen()
    }()

}

It works ok until I restart libvirtd (service libvirtd restart). After
that, the inner go func waits some time and continues without error. But
the callback is not working anymore.

My question is, how can I detect hv reconnect (I guess it's happening in
background) so I know when to reinitialize callbacks?

Thanks.

BR
Daniel Kucera.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20170517/435a0594/attachment.htm>


More information about the libvirt-users mailing list