cmdutil.service: move pidfile writing to a local function
authorSiddharth Agarwal <sid0@fb.com>
Wed, 02 Oct 2013 15:17:50 -0700
changeset 19867 edce20ebe1f3
parent 19866 993b24488679
child 19868 0532c8f8e911
cmdutil.service: move pidfile writing to a local function An upcoming patch will reuse this code.
mercurial/cmdutil.py
--- 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']