Mercurial > public > mercurial-scm > hg
comparison mercurial/posix.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 | c7129ed280b8 |
children | 4b1af1c867fa 5f33116cd787 |
comparison
equal
deleted
inserted
replaced
29529:02de1dbd4f6e | 29530:3239e2fdd2e2 |
---|---|
596 break | 596 break |
597 | 597 |
598 return ''.join(chunks) | 598 return ''.join(chunks) |
599 finally: | 599 finally: |
600 fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags) | 600 fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags) |
601 | |
602 def bindunixsocket(sock, path): | |
603 """Bind the UNIX domain socket to the specified path""" | |
604 # use relative path instead of full path at bind() if possible, since | |
605 # AF_UNIX path has very small length limit (107 chars) on common | |
606 # platforms (see sys/un.h) | |
607 dirname, basename = os.path.split(path) | |
608 bakwdfd = None | |
609 if dirname: | |
610 bakwdfd = os.open('.', os.O_DIRECTORY) | |
611 os.chdir(dirname) | |
612 sock.bind(basename) | |
613 if bakwdfd: | |
614 os.fchdir(bakwdfd) | |
615 os.close(bakwdfd) |