On Thu, Jan 05, 2012 at 06:18:26PM -0600, Michael Roth wrote:
> On 01/05/2012 04:26 PM, MATSUDA, Daiki wrote:
> >Hi, all.
> >
> >I am trying QEMU Guest Agent and encountered a small bug. It is that the
> >PIDFILE remains when daemon start fails. And maybe forgotton to g_free().
> >
> >MATSUDA, Daiki
> >
> 
> Thanks for the patch. There was some contention in the past about
> whether or not to clean up pidfiles when there was abnormal
> termination, but personally I like this approach better.

Yep, this still leaves open the problem of pidfile cleanup when the
daemon crashes. For libvirtd we recently switched over to a crash-safe
pidfile acquisition design, that uses fcntl(F_SETLK) to maintain
exclusive access over the pidfile. With this you don't need to worry
about forgetting to unlink() on termination, since the POSIX lock is
automatically released when process exits (or crashes).

If you're interested in copying the algorithm libvirt uses for pidfiles
then look at the virPidFileAcquirePath() function, starting line 308,
and also corresponding virPidFileReleasePath() to (optionally) call
on shutdown:

http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virpidfile.c;hb=HEAD

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

Reply via email to