daemon: Run virStateCleanup conditionally
daemon: Run virStateCleanup conditionally

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

Currently, initialization of drivers is done in a separate thread. This
is done for several reasons: a driver that is initialized may require
running event loop, it may take ages to initialize driver (e.g. due to
autostarting domains). While the thread is spawn and run, the main()
continues its execution. However, if something goes bad, or the event
loop is just exited (e.g. due to a --timeout or SIGINT) we try to
cleanup all the drivers. So we have two threads running Initialize() and
Cleanup() concurrently. This may result in accessing stale pointers -
e.g. netcf driver will free() itself in stateCleanup callback, while the
init thread may come, open a dummy connection in order to autostart some
domains and voilà: do_open() iterates over interface drivers and
accesses stale netcf driver.

The fix consists in not running stateCleanup if the init thread is still
running.

Signed-off-by: Michal Privoznik <83d82aaba2eed257f4814b0c239c260c4caaadf0@redhat.com>

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