virNetSocketNewConnectUNIX: Use flocks when spawning a daemon
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 <d9c0c1814229c9d7f78a7e860ff9791c82a22dba@redhat.com>
Signed-off-by: Michal Privoznik <83d82aaba2eed257f4814b0c239c260c4caaadf0@redhat.com>

datto/libvirt,libvirt/libvirt,crobinso/libvirt,jfehlig/libvirt,fabianfreyer/libvirt,fabianfreyer/libvirt,jardasgit/libvirt,taget/libvirt,agx/libvirt,agx/libvirt,eskultety/libvirt,taget/libvirt,rlaager/libvirt,rlaager/libvirt,fabianfreyer/libvirt,rlaager/libvirt,zippy2/libvirt,rlaager/libvirt,VenkatDatta/libvirt,eskultety/libvirt,VenkatDatta/libvirt,crobinso/libvirt,agx/libvirt,VenkatDatta/libvirt,andreabolognani/libvirt,libvirt/libvirt,nertpinx/libvirt,eskultety/libvirt,jardasgit/libvirt,agx/libvirt,nertpinx/libvirt,andreabolognani/libvirt,taget/libvirt,eskultety/libvirt,taget/libvirt,jardasgit/libvirt,libvirt/libvirt,crobinso/libvirt,eskultety/libvirt,olafhering/libvirt,datto/libvirt,jfehlig/libvirt,rlaager/libvirt,datto/libvirt,andreabolognani/libvirt,agx/libvirt,crobinso/libvirt,fabianfreyer/libvirt,nertpinx/libvirt,nertpinx/libvirt,datto/libvirt,jfehlig/libvirt,andreabolognani/libvirt,VenkatDatta/libvirt,olafhering/libvirt,zippy2/libvirt,olafhering/libvirt,nertpinx/libvirt,zippy2/libvirt,libvirt/libvirt,VenkatDatta/libvirt,jfehlig/libvirt,jardasgit/libvirt,zippy2/libvirt,datto/libvirt,fabianfreyer/libvirt,jardasgit/libvirt,andreabolognani/libvirt,olafhering/libvirt,taget/libvirt