commandserver: prevent unlink socket twice
authorJun Wu <quark@fb.com>
Wed, 08 Feb 2017 14:37:38 -0800
changeset 30887 a95fc01aaffe
parent 30886 2aaa8bfc7bd9
child 30891 b1b36c6499c2
commandserver: prevent unlink socket twice This patch changes unixforkingservice so it only calls `self._servicehandler.unlinksocket(self.address)` at most once. This is needed by the next patch.
mercurial/commandserver.py
--- a/mercurial/commandserver.py	Thu Feb 09 05:57:54 2017 -0800
+++ b/mercurial/commandserver.py	Wed Feb 08 14:37:38 2017 -0800
@@ -447,6 +447,7 @@
         self._sock = None
         self._oldsigchldhandler = None
         self._workerpids = set()  # updated by signal handler; do not iterate
+        self._socketunlinked = None
 
     def init(self):
         self._sock = socket.socket(socket.AF_UNIX)
@@ -455,11 +456,17 @@
         o = signal.signal(signal.SIGCHLD, self._sigchldhandler)
         self._oldsigchldhandler = o
         self._servicehandler.printbanner(self.address)
+        self._socketunlinked = False
+
+    def _unlinksocket(self):
+        if not self._socketunlinked:
+            self._servicehandler.unlinksocket(self.address)
+            self._socketunlinked = True
 
     def _cleanup(self):
         signal.signal(signal.SIGCHLD, self._oldsigchldhandler)
         self._sock.close()
-        self._servicehandler.unlinksocket(self.address)
+        self._unlinksocket()
         # don't kill child processes as they have active clients, just wait
         self._reapworkers(0)