Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
29529:02de1dbd4f6e | 29530:3239e2fdd2e2 |
---|---|
576 | 576 |
577 def server_bind(self): | 577 def server_bind(self): |
578 # use a unique temp address so we can stat the file and do ownership | 578 # use a unique temp address so we can stat the file and do ownership |
579 # check later | 579 # check later |
580 tempaddress = _tempaddress(self.server_address) | 580 tempaddress = _tempaddress(self.server_address) |
581 # use relative path instead of full path at bind() if possible, since | 581 util.bindunixsocket(self.socket, tempaddress) |
582 # AF_UNIX path has very small length limit (107 chars) on common | |
583 # platforms (see sys/un.h) | |
584 dirname, basename = os.path.split(tempaddress) | |
585 bakwdfd = None | |
586 if dirname: | |
587 bakwdfd = os.open('.', os.O_DIRECTORY) | |
588 os.chdir(dirname) | |
589 self.socket.bind(basename) | |
590 if bakwdfd: | |
591 os.fchdir(bakwdfd) | |
592 os.close(bakwdfd) | |
593 self._socketstat = os.stat(tempaddress) | 582 self._socketstat = os.stat(tempaddress) |
594 # rename will replace the old socket file if exists atomically. the | 583 # rename will replace the old socket file if exists atomically. the |
595 # old server will detect ownership change and exit. | 584 # old server will detect ownership change and exit. |
596 util.rename(tempaddress, self.server_address) | 585 util.rename(tempaddress, self.server_address) |
597 | 586 |