]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virNetSocketNewConnectUNIX: Use flocks when spawning a daemon
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Apr 2015 12:41:17 +0000 (14:41 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Apr 2015 11:39:13 +0000 (13:39 +0200)
commitbe78814ae07f092d9c4e71fd82dd1947aba2f029
treeb21a48c73bcd74e4234226349e1d05e861753488
parentbb6a62d4abc0ebe3be983a9a02c329f03e24aca9
virNetSocketNewConnectUNIX: Use flocks when spawning a daemon

https://bugzilla.redhat.com/show_bug.cgi?id=1200149

Even though we have a mutex mechanism so that two clients don't spawn
two daemons, it's not strong enough. It can happen that while one
client is spawning the daemon, the other one fails to connect.
Basically two possible errors can happen:

  error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': Connection refused

or:

  error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': No such file or directory

The problem in both cases is, the daemon is only starting up, while we
are trying to connect (and fail). We should postpone the connecting
phase until the daemon is started (by the other thread that is
spawning it). In order to do that, create a file lock 'libvirt-lock'
in the directory where session daemon would create its socket. So even
when called from multiple processes, spawning a daemon will serialize
on the file lock. So only the first to come will spawn the daemon.

Tested-by: Richard W. M. Jones <rjones@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/rpc/virnetsocket.c