Beispiel #1
0
    def is_lock_holder_known_dead(self):
        """True if the lock holder process is known to be dead.

        False if it's either known to be still alive, or if we just can't tell.

        We can be fairly sure the lock holder is dead if it declared the same
        hostname and there is no process with the given pid alive.  If people
        have multiple machines with the same hostname this may cause trouble.

        This doesn't check whether the lock holder is in fact the same process
        calling this method.  (In that case it will return true.)
        """
        if self.get('hostname') != get_host_name():
            return False
        if self.get('hostname') == 'localhost':
            # Too ambiguous.
            return False
        if self.get('user') != get_username_for_lock_info():
            # Could well be another local process by a different user, but
            # just to be safe we won't conclude about this either.
            return False
        pid_str = self.info_dict.get('pid', None)
        if not pid_str:
            mutter("no pid recorded in %r" % (self, ))
            return False
        try:
            pid = int(pid_str)
        except ValueError:
            mutter("can't parse pid %r from %r"
                % (pid_str, self))
            return False
        return osutils.is_local_pid_dead(pid)
Beispiel #2
0
    def is_lock_holder_known_dead(self):
        """True if the lock holder process is known to be dead.

        False if it's either known to be still alive, or if we just can't tell.

        We can be fairly sure the lock holder is dead if it declared the same
        hostname and there is no process with the given pid alive.  If people
        have multiple machines with the same hostname this may cause trouble.

        This doesn't check whether the lock holder is in fact the same process
        calling this method.  (In that case it will return true.)
        """
        if self.get('hostname') != get_host_name():
            return False
        if self.get('hostname') == 'localhost':
            # Too ambiguous.
            return False
        if self.get('user') != get_username_for_lock_info():
            # Could well be another local process by a different user, but
            # just to be safe we won't conclude about this either.
            return False
        pid_str = self.info_dict.get('pid', None)
        if not pid_str:
            mutter("no pid recorded in %r" % (self, ))
            return False
        try:
            pid = int(pid_str)
        except ValueError:
            mutter("can't parse pid %r from %r" % (pid_str, self))
            return False
        return osutils.is_local_pid_dead(pid)
Beispiel #3
0
 def for_this_process(cls, extra_holder_info):
     """Return a new LockHeldInfo for a lock taken by this process.
     """
     info = dict(
         hostname=get_host_name(),
         pid=str(os.getpid()),
         nonce=rand_chars(20),
         start_time=str(int(time.time())),
         user=get_username_for_lock_info(),
         )
     if extra_holder_info is not None:
         info.update(extra_holder_info)
     return cls(info)
Beispiel #4
0
 def for_this_process(cls, extra_holder_info):
     """Return a new LockHeldInfo for a lock taken by this process.
     """
     info = dict(
         hostname=get_host_name(),
         pid=str(os.getpid()),
         nonce=rand_chars(20),
         start_time=str(int(time.time())),
         user=get_username_for_lock_info(),
     )
     if extra_holder_info is not None:
         info.update(extra_holder_info)
     return cls(info)
Beispiel #5
0
 def is_locked_by_this_process(self):
     """True if this process seems to be the current lock holder."""
     return (
         self.get('hostname') == get_host_name()
         and self.get('pid') == str(os.getpid())
         and self.get('user') == get_username_for_lock_info())
Beispiel #6
0
 def is_locked_by_this_process(self):
     """True if this process seems to be the current lock holder."""
     return (self.get('hostname') == get_host_name()
             and self.get('pid') == str(os.getpid())
             and self.get('user') == get_username_for_lock_info())