Show More
@@ -578,18 +578,7 b' class AutoExitMixIn: # use old-style to' | |||
|
578 | 578 | # use a unique temp address so we can stat the file and do ownership |
|
579 | 579 | # check later |
|
580 | 580 | tempaddress = _tempaddress(self.server_address) |
|
581 | # use relative path instead of full path at bind() if possible, since | |
|
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) | |
|
581 | util.bindunixsocket(self.socket, tempaddress) | |
|
593 | 582 | self._socketstat = os.stat(tempaddress) |
|
594 | 583 | # rename will replace the old socket file if exists atomically. the |
|
595 | 584 | # old server will detect ownership change and exit. |
@@ -598,3 +598,18 b' def readpipe(pipe):' | |||
|
598 | 598 | return ''.join(chunks) |
|
599 | 599 | finally: |
|
600 | 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) |
General Comments 0
You need to be logged in to leave comments.
Login now