# HG changeset patch # User Jun Wu # Date 1459736279 -3600 # Node ID 2461f33c9f97f09394def3394715f9a022e1a927 # Parent 73bfd9a54a5c2756e04592b5695bf89c30d6023a chgserver: use relative path at socket.bind Before this patch, if the server address is long, the server will fail to listen and throw the error: socket.error: AF_UNIX path too long It is because AF_UNIX path usually has a very short length limit (107 chars on common platforms, see sys/un.h). This patch addresses the issue by using relative path instead. Therefore the directory length does not matter. It helps run tests with chg using a long $TMPDIR. diff -r 73bfd9a54a5c -r 2461f33c9f97 hgext/chgserver.py --- a/hgext/chgserver.py Mon Apr 04 01:10:51 2016 +0100 +++ b/hgext/chgserver.py Mon Apr 04 03:17:59 2016 +0100 @@ -611,11 +611,22 @@ # use a unique temp address so we can stat the file and do ownership # check later tempaddress = _tempaddress(self.server_address) - self.socket.bind(tempaddress) - self._socketstat = os.stat(tempaddress) + # use relative path instead of full path at bind() if possible, since + # AF_UNIX path has very small length limit (107 chars) on common + # platforms (see sys/un.h) + dirname, basename = os.path.split(tempaddress) + bakwdfd = None + if dirname: + bakwdfd = os.open('.', os.O_DIRECTORY) + os.chdir(dirname) + self.socket.bind(basename) + self._socketstat = os.stat(basename) # rename will replace the old socket file if exists atomically. the # old server will detect ownership change and exit. - util.rename(tempaddress, self.server_address) + util.rename(basename, self.server_address) + if bakwdfd: + os.fchdir(bakwdfd) + os.close(bakwdfd) def issocketowner(self): try: