On 10/17/2017 07:51 AM, llilulu wrote:
Hi
In my program , When libvirtd restart , the old libvirtd connection(virConnectPtr)
has to reconnect, Before usr old virConnectPtr , I call virConnectIsAlive. but when I
restart libvirtd , virConnectIsAlive return 1, and I continue other operate use the old
virConnectPtr, program will receive signal pipe.
I use libvirt event. before any api use, I call virEventRegisterDefaultImpl, and run
virEventRunDefaultImpl. then use virConnectIsAlive, when I restart libvirtd,
virConnectIsAlive will return 0, I want know how to use virConnectIsAlive, if
virConnectIsAlive use keep alive message, what default the interval and count.
Thanks
virConnectIsAlive() will produce desired result only when event loop is
used (e.g. virEventRunDefaultImpl()). However, with this API there'll
always be TOCTOU [1] race. Therefore I suggest registering a disconnect
callback that reconnects. At least that's how it is done in virsh. This
[2] is called before every command and then this [3] is the callback.
Michal
1:
https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use
2:
https://libvirt.org/git/?p=libvirt.git;a=blob;f=tools/virsh.c;h=d1789f03a...
3:
https://libvirt.org/git/?p=libvirt.git;a=blob;f=tools/virsh.c;h=d1789f03a...