# HG changeset patch # User Siddharth Agarwal # Date 2013-10-02 22:20:49 # Node ID 0532c8f8e911d374a08b71ae1426ec0ef664dab3 # Parent edce20ebe1f3434367796747f802fe74e23ede9b cmdutil.service: move pidfile writing to the parent in daemon mode There is a potential race here, which I suspect I've spotted in the wild, where something reads the pid file after the parent exits but before the child has had a chance to write to it. Moving writing the file to the parent causes this to no longer be an issue. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -497,6 +497,7 @@ def service(opts, parentfn=None, initfn= pid = util.rundetached(runargs, condfn) if pid < 0: raise util.Abort(_('child process failed to start')) + writepid(pid) finally: try: os.unlink(lockpath) @@ -511,7 +512,8 @@ def service(opts, parentfn=None, initfn= if initfn: initfn() - writepid(os.getpid()) + if not opts['daemon']: + writepid(os.getpid()) if opts['daemon_pipefds']: lockpath = opts['daemon_pipefds']