Mercurial > public > mercurial-scm > hg
comparison hgext/chgserver.py @ 28768:2461f33c9f97
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.
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 04 Apr 2016 03:17:59 +0100 |
parents | 73bfd9a54a5c |
children | 97c8da2f89f9 |
comparison
equal
deleted
inserted
replaced
28767:73bfd9a54a5c | 28768:2461f33c9f97 |
---|---|
609 | 609 |
610 def server_bind(self): | 610 def server_bind(self): |
611 # use a unique temp address so we can stat the file and do ownership | 611 # use a unique temp address so we can stat the file and do ownership |
612 # check later | 612 # check later |
613 tempaddress = _tempaddress(self.server_address) | 613 tempaddress = _tempaddress(self.server_address) |
614 self.socket.bind(tempaddress) | 614 # use relative path instead of full path at bind() if possible, since |
615 self._socketstat = os.stat(tempaddress) | 615 # AF_UNIX path has very small length limit (107 chars) on common |
616 # platforms (see sys/un.h) | |
617 dirname, basename = os.path.split(tempaddress) | |
618 bakwdfd = None | |
619 if dirname: | |
620 bakwdfd = os.open('.', os.O_DIRECTORY) | |
621 os.chdir(dirname) | |
622 self.socket.bind(basename) | |
623 self._socketstat = os.stat(basename) | |
616 # rename will replace the old socket file if exists atomically. the | 624 # rename will replace the old socket file if exists atomically. the |
617 # old server will detect ownership change and exit. | 625 # old server will detect ownership change and exit. |
618 util.rename(tempaddress, self.server_address) | 626 util.rename(basename, self.server_address) |
627 if bakwdfd: | |
628 os.fchdir(bakwdfd) | |
629 os.close(bakwdfd) | |
619 | 630 |
620 def issocketowner(self): | 631 def issocketowner(self): |
621 try: | 632 try: |
622 stat = os.stat(self.server_address) | 633 stat = os.stat(self.server_address) |
623 return (stat.st_ino == self._socketstat.st_ino and | 634 return (stat.st_ino == self._socketstat.st_ino and |