[CVS] pidfile support

Henrique de Moraes Holschuh hmh at debian.org
Tue Dec 17 10:34:36 EST 2002


On Tue, 17 Dec 2002, Rob Siemborski wrote:
> On Tue, 17 Dec 2002, Henrique de Moraes Holschuh wrote:
> > It won't.   We will have to transfer the lock to B without a
> > race-condition.  That means IPC, or signals, or something like that...
> 
> Yeah, I was discussing this with someone in the office yesterday, and
> there's a half-decent way to do this, but it does requrie signals (well, a
> pipe), and two locks.

Looks good to me...  pipes quite sane in most unixes, AFAIK.

> I'm not sure I like using the presence of the pidfile, and this method
> feels a bit kudgy to me (using kill to detect the presence of the process,

Kludgy it is :P   but using kill to detect the presence of a process is
actually reasonably portable AFAIK, and safe :-)

> for example).  Like you mention, there's also a minor race.  I think we
> can do better:
> 
> [A] Create/lock pidfile.lock.  If locked, exit(failure).
> [A] Create a pipe
> [A] Fork [B]
> [A] Block on reading exit code from pipe
> [B] Create/lock pidfile  If locked, write failure code to pipe and exit(failure)
> [B] write pid to pidfile
> [B] write success code to pipe & finish starting up
> [A] exit(code read from pipe)
> 
> I think this works no matter how the things are interleaved after forking.

I like it.  It also allows us to keep [A] around for a little while if we
wish to do so, to detect startup errors of other sorts...

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh




More information about the Info-cyrus mailing list