diff hgext/chgserver.py @ 29530:3239e2fdd2e2

chgserver: extract utility to bind unix domain socket to long path This is common problem of using sockaddr_un.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 May 2016 16:52:04 +0900
parents 02de1dbd4f6e
children b439a2a268eb
line wrap: on
line diff
--- a/hgext/chgserver.py	Sat May 21 16:42:59 2016 +0900
+++ b/hgext/chgserver.py	Sat May 21 16:52:04 2016 +0900
@@ -578,18 +578,7 @@
         # use a unique temp address so we can stat the file and do ownership
         # check later
         tempaddress = _tempaddress(self.server_address)
-        # 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)
-        if bakwdfd:
-            os.fchdir(bakwdfd)
-            os.close(bakwdfd)
+        util.bindunixsocket(self.socket, tempaddress)
         self._socketstat = os.stat(tempaddress)
         # rename will replace the old socket file if exists atomically. the
         # old server will detect ownership change and exit.