cmdutil.service: move pidfile writing to a local function
An upcoming patch will reuse this code.
--- a/mercurial/cmdutil.py Wed Oct 02 14:20:26 2013 -0700
+++ b/mercurial/cmdutil.py Wed Oct 02 15:17:50 2013 -0700
@@ -468,6 +468,13 @@
runargs=None, appendpid=False):
'''Run a command as a service.'''
+ def writepid(pid):
+ if opts['pid_file']:
+ mode = appendpid and 'a' or 'w'
+ fp = open(opts['pid_file'], mode)
+ fp.write(str(pid) + '\n')
+ fp.close()
+
if opts['daemon'] and not opts['daemon_pipefds']:
# Signal child process startup with file removal
lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
@@ -504,11 +511,7 @@
if initfn:
initfn()
- if opts['pid_file']:
- mode = appendpid and 'a' or 'w'
- fp = open(opts['pid_file'], mode)
- fp.write(str(os.getpid()) + '\n')
- fp.close()
+ writepid(os.getpid())
if opts['daemon_pipefds']:
lockpath = opts['daemon_pipefds']