[PATCH 2 of 4] cmdutil.service: move pidfile writing to a local function

Siddharth Agarwal sid0 at fb.com
Wed Oct 2 18:19:44 CDT 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1380752270 25200
#      Wed Oct 02 15:17:50 2013 -0700
# Node ID e4b7774aec7e068677e811ddf7ddd24ed9ce3d65
# Parent  63a4ad5b170b08c5b1b33b992710c3da3b518b16
cmdutil.service: move pidfile writing to a local function

An upcoming patch will reuse this code.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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']


More information about the Mercurial-devel mailing list