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>
Mon, 4 Apr 2011 17:59:19 +0000 (10:59 -0700)
commitaacea8ba432bdffcca77696ba407be0c62661394
tree2341fa0abe8ee9c6406b427ca6a67c5789780cae
parent00c08589876b7c1cd8f57e5ebb3e66bb164c5a3d
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