changeset 19867:edce20ebe1f3

cmdutil.service: move pidfile writing to a local function An upcoming patch will reuse this code.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 02 Oct 2013 15:17:50 -0700
parents 993b24488679
children 0532c8f8e911
files mercurial/cmdutil.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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']