Patchwork [1,of,2,V2] commandserver: prevent unlink socket twice

login
register
mail settings
Submitter Jun Wu
Date Feb. 8, 2017, 10:52 p.m.
Message ID <5fc577761fb78168fcbd.1486594350@x1c>
Download mbox | patch
Permalink /patch/18355/
State Accepted
Headers show

Comments

Jun Wu - Feb. 8, 2017, 10:52 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1486593458 28800
#      Wed Feb 08 14:37:38 2017 -0800
# Node ID 5fc577761fb78168fcbd7ec93d911a1b7b4989c9
# Parent  a68510b69f413545722c086eaeb840dd5e8305b4
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5fc577761fb7
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.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -448,4 +448,5 @@  class unixforkingservice(object):
         self._oldsigchldhandler = None
         self._workerpids = set()  # updated by signal handler; do not iterate
+        self._socketunlinked = None
 
     def init(self):
@@ -456,9 +457,15 @@  class unixforkingservice(object):
         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)