Show More
@@ -542,8 +542,8 class chgunixservicehandler(object): | |||
|
542 | 542 | |
|
543 | 543 | def __init__(self, ui): |
|
544 | 544 | self.ui = ui |
|
545 | self.idletimeout = ui.configint('chgserver', 'idletimeout', 3600) | |
|
546 | self.lastactive = time.time() | |
|
545 | self._idletimeout = ui.configint('chgserver', 'idletimeout', 3600) | |
|
546 | self._lastactive = time.time() | |
|
547 | 547 | |
|
548 | 548 | def bindsocket(self, sock, address): |
|
549 | 549 | self._inithashstate(address) |
@@ -552,57 +552,57 class chgunixservicehandler(object): | |||
|
552 | 552 | self._createsymlink() |
|
553 | 553 | |
|
554 | 554 | def _inithashstate(self, address): |
|
555 | self.baseaddress = address | |
|
555 | self._baseaddress = address | |
|
556 | 556 | if self.ui.configbool('chgserver', 'skiphash', False): |
|
557 | self.hashstate = None | |
|
558 | self.address = address | |
|
557 | self._hashstate = None | |
|
558 | self._realaddress = address | |
|
559 | 559 | return |
|
560 | self.hashstate = hashstate.fromui(self.ui) | |
|
561 | self.address = _hashaddress(address, self.hashstate.confighash) | |
|
560 | self._hashstate = hashstate.fromui(self.ui) | |
|
561 | self._realaddress = _hashaddress(address, self._hashstate.confighash) | |
|
562 | 562 | |
|
563 | 563 | def _checkextensions(self): |
|
564 | if not self.hashstate: | |
|
564 | if not self._hashstate: | |
|
565 | 565 | return |
|
566 | 566 | if extensions.notloaded(): |
|
567 | 567 | # one or more extensions failed to load. mtimehash becomes |
|
568 | 568 | # meaningless because we do not know the paths of those extensions. |
|
569 | 569 | # set mtimehash to an illegal hash value to invalidate the server. |
|
570 | self.hashstate.mtimehash = '' | |
|
570 | self._hashstate.mtimehash = '' | |
|
571 | 571 | |
|
572 | 572 | def _bind(self, sock): |
|
573 | 573 | # use a unique temp address so we can stat the file and do ownership |
|
574 | 574 | # check later |
|
575 | tempaddress = _tempaddress(self.address) | |
|
575 | tempaddress = _tempaddress(self._realaddress) | |
|
576 | 576 | util.bindunixsocket(sock, tempaddress) |
|
577 | 577 | self._socketstat = os.stat(tempaddress) |
|
578 | 578 | # rename will replace the old socket file if exists atomically. the |
|
579 | 579 | # old server will detect ownership change and exit. |
|
580 | util.rename(tempaddress, self.address) | |
|
580 | util.rename(tempaddress, self._realaddress) | |
|
581 | 581 | |
|
582 | 582 | def _createsymlink(self): |
|
583 | if self.baseaddress == self.address: | |
|
583 | if self._baseaddress == self._realaddress: | |
|
584 | 584 | return |
|
585 | tempaddress = _tempaddress(self.baseaddress) | |
|
586 | os.symlink(os.path.basename(self.address), tempaddress) | |
|
587 | util.rename(tempaddress, self.baseaddress) | |
|
585 | tempaddress = _tempaddress(self._baseaddress) | |
|
586 | os.symlink(os.path.basename(self._realaddress), tempaddress) | |
|
587 | util.rename(tempaddress, self._baseaddress) | |
|
588 | 588 | |
|
589 | def issocketowner(self): | |
|
589 | def _issocketowner(self): | |
|
590 | 590 | try: |
|
591 | stat = os.stat(self.address) | |
|
591 | stat = os.stat(self._realaddress) | |
|
592 | 592 | return (stat.st_ino == self._socketstat.st_ino and |
|
593 | 593 | stat.st_mtime == self._socketstat.st_mtime) |
|
594 | 594 | except OSError: |
|
595 | 595 | return False |
|
596 | 596 | |
|
597 | 597 | def unlinksocket(self, address): |
|
598 | if not self.issocketowner(): | |
|
598 | if not self._issocketowner(): | |
|
599 | 599 | return |
|
600 | 600 | # it is possible to have a race condition here that we may |
|
601 | 601 | # remove another server's socket file. but that's okay |
|
602 | 602 | # since that server will detect and exit automatically and |
|
603 | 603 | # the client will start a new server on demand. |
|
604 | 604 | try: |
|
605 | os.unlink(self.address) | |
|
605 | os.unlink(self._realaddress) | |
|
606 | 606 | except OSError as exc: |
|
607 | 607 | if exc.errno != errno.ENOENT: |
|
608 | 608 | raise |
@@ -612,20 +612,20 class chgunixservicehandler(object): | |||
|
612 | 612 | pass |
|
613 | 613 | |
|
614 | 614 | def shouldexit(self): |
|
615 | if not self.issocketowner(): | |
|
616 | self.ui.debug('%s is not owned, exiting.\n' % self.address) | |
|
615 | if not self._issocketowner(): | |
|
616 | self.ui.debug('%s is not owned, exiting.\n' % self._realaddress) | |
|
617 | 617 | return True |
|
618 | if time.time() - self.lastactive > self.idletimeout: | |
|
618 | if time.time() - self._lastactive > self._idletimeout: | |
|
619 | 619 | self.ui.debug('being idle too long. exiting.\n') |
|
620 | 620 | return True |
|
621 | 621 | return False |
|
622 | 622 | |
|
623 | 623 | def newconnection(self): |
|
624 | self.lastactive = time.time() | |
|
624 | self._lastactive = time.time() | |
|
625 | 625 | |
|
626 | 626 | def createcmdserver(self, repo, conn, fin, fout): |
|
627 | 627 | return chgcmdserver(self.ui, repo, fin, fout, conn, |
|
628 | self.hashstate, self.baseaddress) | |
|
628 | self._hashstate, self._baseaddress) | |
|
629 | 629 | |
|
630 | 630 | def chgunixservice(ui, repo, opts): |
|
631 | 631 | if repo: |
General Comments 0
You need to be logged in to leave comments.
Login now