daemon: Avoid races on pidfile creation.
authorBen Pfaff <blp@nicira.com>
Mon, 4 Apr 2011 17:59:19 +0000 (10:59 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Apr 2011 21:31:49 +0000 (14:31 -0700)
commitcb447687e9c37bc5ecf4bddc2a2c2e744becc16d
tree500ea30cbf386f2a117385de30c309ebd7815f9e
parent37865d539dabd50321ee252173d853676ee0a7d8
daemon: Avoid races on pidfile creation.

Until now, if two copies of one OVS daemon started up at the same time,
then due to races in pidfile creation it was possible for both of them to
start successfully, instead of just one.  This was made worse when a
previous copy of the daemon had died abruptly, leaving a stale pidfile.

This commit implements a new pidfile creation and removal protocol that I
believe closes these races.  Now, a pidfile is asserted with "link" instead
of "rename", which prevents the race on creation, and a stale pidfile may
only be deleted by a process after it has taken a lock on it.

This may solve mysterious problems seen occasionally on vswitch restart.
I'm still puzzled by these problems, however, because I don't see anything
in our tests cases that would actually cause two copies of a daemon to
start at the same time, which as far as I can see is a necessary
precondition for the problem.
lib/daemon.c
python/ovs/daemon.py
tests/test-daemon.py