690
690
self.current_checker_command)
691
691
# Start a new checker if needed
692
692
if self.checker is None:
693
# Escape attributes for the shell
694
escaped_attrs = dict(
695
(attr, re.escape(unicode(getattr(self, attr))))
697
self.runtime_expansions)
694
# In case checker_command has exactly one % operator
695
command = self.checker_command % self.host
697
# Escape attributes for the shell
698
escaped_attrs = dict(
700
re.escape(unicode(str(getattr(self, attr, "")),
704
self.runtime_expansions)
707
command = self.checker_command % escaped_attrs
708
except TypeError as error:
709
logger.error('Could not format string "%s"',
710
self.checker_command, exc_info=error)
711
return True # Try again later
699
command = self.checker_command % escaped_attrs
700
except TypeError as error:
701
logger.error('Could not format string "%s"',
702
self.checker_command, exc_info=error)
703
return True # Try again later
712
704
self.current_checker_command = command
714
706
logger.info("Starting checker %r for %s",
720
712
self.checker = subprocess.Popen(command,
722
714
shell=True, cwd="/")
723
self.checker_callback_tag = (gobject.child_watch_add
725
self.checker_callback,
727
# The checker may have completed before the gobject
728
# watch was added. Check for this.
729
pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
731
gobject.source_remove(self.checker_callback_tag)
732
self.checker_callback(pid, status, command)
733
715
except OSError as error:
734
716
logger.error("Failed to start subprocess",
718
self.checker_callback_tag = (gobject.child_watch_add
720
self.checker_callback,
722
# The checker may have completed before the gobject
723
# watch was added. Check for this.
724
pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
726
gobject.source_remove(self.checker_callback_tag)
727
self.checker_callback(pid, status, command)
736
728
# Re-run this periodically if run by gobject.timeout_add