Mercurial > hg-stable
changeset 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 | 222f482930c8 |
files | hgext/chgserver.py |
diffstat | 1 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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: