(seed_hosts, auto_hosts)
| 207 | |
| 208 | |
| 209 | def hw_main(seed_hosts, auto_hosts): |
| 210 | helpers.logprefix = 'HH: ' |
| 211 | |
| 212 | debug1('Starting hostwatch with Python version %s' |
| 213 | % platform.python_version()) |
| 214 | |
| 215 | for h in seed_hosts: |
| 216 | check_host(h) |
| 217 | |
| 218 | if auto_hosts: |
| 219 | read_host_cache() |
| 220 | _enqueue(_check_etc_hosts) |
| 221 | _enqueue(_check_netstat) |
| 222 | check_host('localhost') |
| 223 | check_host(socket.gethostname()) |
| 224 | |
| 225 | while 1: |
| 226 | now = time.time() |
| 227 | # For each item in the queue |
| 228 | for t, last_polled in list(queue.items()): |
| 229 | (op, args) = t |
| 230 | if not _stdin_still_ok(0): |
| 231 | break |
| 232 | |
| 233 | # Determine if we need to run. |
| 234 | maxtime = POLL_TIME |
| 235 | # netstat runs more often than other jobs |
| 236 | if op == _check_netstat: |
| 237 | maxtime = NETSTAT_POLL_TIME |
| 238 | |
| 239 | # Check if this jobs needs to run. |
| 240 | if now - last_polled > maxtime: |
| 241 | queue[t] = time.time() |
| 242 | op(*args) |
| 243 | try: |
| 244 | sys.stdout.flush() |
| 245 | except IOError: |
| 246 | break |
| 247 | |
| 248 | # FIXME: use a smarter timeout based on oldest last_polled |
| 249 | if not _stdin_still_ok(1): # sleeps for up to 1 second |
| 250 | break |
nothing calls this directly
no test coverage detected