def boundedCheck(target, check, timer, logger):
    """
    Execute the given *check* on the given *target* (*target* should be an
    IP address). The *timer* is used to retrieve the timeout, and useful
    information will be sent using the *logger*.

    This function will fork(), and the check will be executed in the child
    process. The parent process will wait for the child process, and kill
    it if it did not answer within the timeout specified by the *timer*
    implementation.
    """
    timeout = timer.getCheckTimeout()
    deadline = time.time() + timeout
    logger.debug('[DEBUG] Starting check {0} on {1}, timeout={2}'
                 .format(check, target, timeout))
    # Use self-pipe trick: setup a SIGCHLD handler to write 1 byte to a pipe
    # (and select() on that pipe)
    pipe = os.pipe()

    def sigchld(sig, frame):
        try:
            os.write(pipe[1], ' ')
        except:
            pass

    signal.signal(signal.SIGCHLD, sigchld)
    pid = os.fork()
    if pid:
        # parent process: wait for the child
        while deadline < time.time():
            timeout = max(0, deadline - time.time())
            try:
                rfds, wfds, efds = select.select([pipe[0]], [], [], timeout)
            except select.error as err:
                if err.args[0] == errno.EINTR:
                    continue
            if rfds:
                # something in the pipe = got a SIGCHLD
                logger.debug('[DEBUG] Child exited, retrieving its status')
                childpid, status = os.wait()
                logger.debug('[DEBUG] Child exit status={0}'.format(status))
                retval = (status == 0)
            else:
                # timeout
                logger.info('[INFO] Child timeout, killing it')
                os.kill(pid, signal.SIGKILL)
                logger.debug('[DEBUG] Reaping child process')
                os.wait()
                retval = False
            os.close(pipe[0])
            os.close(pipe[1])
            logger.debug('[DEBUG] Check result is {0}'.format(retval))
            return retval
    else:
        # child process: do the check
        try:
            if check.check(target):
                exit(0)
            else:
                exit(1)
        except Exception:
            exit(2)
dataset/ETHPy150Open marccerrato/python-dns-failover/dns_failover/core.py/boundedCheck/swapped operands of `<`