Submitter | Jun Wu |
---|---|
Date | March 2, 2016, 10:44 a.m. |
Message ID | <b8522c5e995a8a49c53a.1456915443@x1c> |
Download | mbox | patch |
Permalink | /patch/13522/ |
State | Accepted |
Delegated to: | Yuya Nishihara |
Headers | show |
Comments
Jun Wu <quark@fb.com> wrote: > the client can connect to the server, a symbol link is created at the original symbolic > address pointing to the new address. > > The address is intensionally mangled at the server, instead of being pre- intentionally
On Wed, 2 Mar 2016 10:44:03 +0000, Jun Wu wrote: > # HG changeset patch > # User Jun Wu <quark@fb.com> > # Date 1456913406 0 > # Wed Mar 02 10:10:06 2016 +0000 > # Node ID b8522c5e995a8a49c53ad68cbd215fb50bebfbf8 > # Parent d8d4dccea8d6ad5ba738f14485ed18ec61c2b807 > chgserver: mangle server address to include confighash Reordered the patch 1 and 2 to avoid test failure at this revision, and pushed to the clowncopter, thanks. > + def _createsymlink(self): > + if self.baseaddress == self.address: > + return > + tempaddress = _tempaddress(self.baseaddress) > + os.symlink(self.address, tempaddress) > + os.rename(tempaddress, self.baseaddress) Changed to use util.rename().
On Wed, 2 Mar 2016 10:44:03 +0000, Jun Wu wrote: > + def _createsymlink(self): > + if self.baseaddress == self.address: > + return > + tempaddress = _tempaddress(self.baseaddress) > + os.symlink(self.address, tempaddress) FWIW, I prefer making a symlink of relative path to make sure it never escapes from the socket directory.
Patch
diff --git a/hgext/chgserver.py b/hgext/chgserver.py --- a/hgext/chgserver.py +++ b/hgext/chgserver.py @@ -505,6 +505,9 @@ def _tempaddress(address): return '%s.%d.tmp' % (address, os.getpid()) +def _hashaddress(address, hashstr): + return '%s-%s' % (address, hashstr) + class AutoExitMixIn: # use old-style to comply with SocketServer design lastactive = time.time() idletimeout = 3600 # defualt 1 hour @@ -570,6 +573,7 @@ # drop options set for "hg serve --cmdserver" command self.ui.setconfig('progress', 'assume-tty', None) signal.signal(signal.SIGHUP, self._reloadconfig) + self._inithashstate() class cls(AutoExitMixIn, SocketServer.ForkingMixIn, SocketServer.UnixStreamServer): ui = self.ui @@ -578,9 +582,25 @@ self.server.idletimeout = self.ui.configint( 'chgserver', 'idletimeout', self.server.idletimeout) self.server.startautoexitthread() + self._createsymlink() # avoid writing "listening at" message to stdout before attachio # request, which calls setvbuf() + def _inithashstate(self): + self.baseaddress = self.address + if self.ui.configbool('chgserver', 'skiphash', False): + self.hashstate = None + return + self.hashstate = hashstate.fromui(self.ui) + self.address = _hashaddress(self.address, self.hashstate.confighash) + + def _createsymlink(self): + if self.baseaddress == self.address: + return + tempaddress = _tempaddress(self.baseaddress) + os.symlink(self.address, tempaddress) + os.rename(tempaddress, self.baseaddress) + def _reloadconfig(self, signum, frame): self.ui = self.server.ui = _renewui(self.ui)