Example #1
0
def _terminate_s2e():
    terminate()

    # First, send SIGTERM to S2E process group
    if not s2e_main_process:
        return

    logger.warning('Sending SIGTERM to S2E process group')

    try:
        os.killpg(s2e_main_process.pid, signal.SIGTERM)
    except OSError:
        return

    s2e_main_process.poll()

    # Give S2E time to quit
    logger.warning('Waiting for S2E processes to quit...')
    for _ in xrange(15):
        if not _has_s2e_processes(s2e_main_process.pid):
            logger.warning('All S2E processes terminated, exiting.')
            return
        time.sleep(1)

    # Second, kill s2e process group and all processes in its cgroup
    logger.warning('Sending SIGKILL to S2E process group')
    os.killpg(s2e_main_process.pid, signal.SIGKILL)
    s2e_main_process.wait()
Example #2
0
    def run(self):
        # Launch s2e
        global s2e_main_process
        s2e_main_process = subprocess.Popen(self._args,
                                            preexec_fn=_s2e_preexec,
                                            env=self._env,
                                            cwd=self._cwd,
                                            stdout=self._stdout,
                                            stderr=self._stderr)

        # Wait until all processes in the S2E cgroup terminate
        s2e_main_process.wait()

        returncode = s2e_main_process.returncode
        while True:
            if not _has_s2e_processes(s2e_main_process.pid):
                break
            time.sleep(1)

        if self._stdout != sys.stdout:
            self._stdout.close()
        if self._stderr != sys.stderr:
            self._stderr.close()

        terminate()
        logger.info('S2E terminated with code %d', returncode)

        return returncode