def runVivadoTCL(tclPath):
    # running vivado_hls
    returnValue = system("vivado_hls FPGAClustering_Synthetise.tcl")
    # checking if return value != 0 to look for errors
    if WEXITSTATUS(returnValue) != 0:
        raise RuntimeError(
            "vivado_hls returned value " + WEXITSTATUS(returnValue) +
            "check log and latest header for more info. Aborting scan.")
Пример #2
0
def shell_out():
    try:
        p = popen("/usr/bin/env yum check-update 2>&1")
        output = p.readlines()
        rc = p.close()

        if rc is not None:
            # None represents exit code of 0, otherwise the exit code is in the
            # format returned by wait(). Exit code of 100 from yum represents
            # updates available.
            if WEXITSTATUS(rc) != 100:
                return WEXITSTATUS(rc)
        else:
            # Exit code is None (0), no updates waiting so don't both parsing output
            return 0

        # Yum prints a line of hyphens (old versions) or a blank line between
        # headers and package data, so skip everything before them
        skipheaders = 0
        for line in output:
            if not skipheaders:
                if re.compile("^((-){80}|)$").search(line):
                    skipheaders = 1
                continue

            # Skip any blank lines
            if re.compile("^[ \t]*$").search(line):
                continue

            # Format is:
            # Yum 1.x: name arch (epoch:)?version
            # Yum 2.0: name arch (epoch:)?version repo
            # epoch is optional if 0

            p = string.split(line)
            pname = p[0]
            parch = p[1]
            pevr = p[2]

            # Separate out epoch:version-release
            evr_re = re.compile("^(\d:)?(\S+)-(\S+)$")
            evr = evr_re.match(pevr)

            pepoch = ""
            if evr.group(1) is None:
                pepoch = "0"
            else:
                pepoch = evr.group(1).replace(":", "")
            pversion = evr.group(2)
            prelease = evr.group(3)

            print "_pkg", pname, pepoch, pversion, prelease, parch

        return 0
    except:
        print sys.exc_info()[0]
        return 1
Пример #3
0
    def wait_for_wrapper_process():
        while True:
            pid, exit_status = waitpid(0, 0)
            # make sure it's one of our wrapper processes
            vpn_id, subnet, _ = pids_wrappers.get(pid, (None, None, None))
            if subnet:
                break

        exit_status = WEXITSTATUS(exit_status) # read man waitpid if wondering
        if exit_status != 0:
            if exit_status == 2:
                # this means our perform_queries.py crashed... not good
                log('performing queries through vpn {} failed'.format(vpn_id))
                result_info = 'internal failure: process_crash'
            else:
                # vpn server is probably not responding
                log('connection to vpn {} failed'.format(vpn_id))
                result_info = 'internal failure: vpn_connection_failure'

            try:
                cursor.execute('''
                INSERT INTO user_side_responses
                    (date, result, dns_id, service_id, vpn_id)
                (SELECT TIMESTAMP WITH TIME ZONE %s, %s,
                        dns_id, service_id, vpn_id
                FROM user_side_queries
                WHERE vpn_id = %s);
                ''', (hour, result_info, vpn_id))
            except psycopg2.IntegrityError:
                log('results already exist for vpn {}'.format(vpn_id))

        pids_wrappers.pop(pid)
        subnets.add(subnet)
Пример #4
0
    def exited(self, status):
        # Log last output
        for line in self.readlines():
            pass

        # Display exit code
        if status is not None:
            log_func = self.warning
            info = []
            if WCOREDUMP(status):
                info.append("core.%s dumped!" % self._pid)
                log_func = self.error
            if WIFSIGNALED(status):
                signal = WTERMSIG(status)
                signal = SIGNAME.get(signal, signal)
                info.append("signal %s" % signal)
            if WIFEXITED(status):
                info.append("exitcode=%s" % WEXITSTATUS(status))
            if info:
                log_func("Exit (%s)" % ", ".join(info))
            else:
                log_func("Exit")
        else:
            self.error("Process exited (ECHILD error)")

        # Delete process
        self.process = None
        self._pid = None
Пример #5
0
def compile_with_gcc(file):
  return_value = WEXITSTATUS(system('gcc -w -D\'uint64_t=unsigned long long\' grader/' + file + ' -o .prog >/dev/null 2>&1'))
  
  if return_value != 0:
    system('rm ./.prog')
  
  return return_value
Пример #6
0
def wait_and_reap_zombies(pid):
    _, status = waitpid(pid, 0)
    try:
        while True:
            waitpid(-1, WNOHANG)
    except ChildProcessError:
        pass
    if WIFSIGNALED(status):
        return -WTERMSIG(status)
    return WEXITSTATUS(status)
Пример #7
0
 def execute(self, *args):
     process = Popen4([self.facility.path] + self.facility.args +
                      list(args))
     timers = [
         Timer(time, self.kill, [process.pid, signal])
         for time, signal in self.facility.wait.iteritems()
     ]
     for timer in timers:
         timer.start()
     status = process.wait()
     for timer in timers:
         # No penalty, btw, for cancelling a dead timer
         if timer.isAlive():
             timer.cancel()
     process.tochild.close()
     if __debug__:
         while True:
             line = process.fromchild.readline()
             if line:
                 syslog(line)
             else:
                 break
     process.fromchild.close()
     command = basename(self.facility.path)
     if WIFEXITED(status):
         exit_status = WEXITSTATUS(status)
         if exit_status != EX_OK:
             raise ExecutionError(
                 EX_SOFTWARE, '`%(command)s\' exited with \
             error-code %(exit_status)d' % {
                     'command': command,
                     'exit_status': exit_status
                 })
     elif WIFSIGNALED(status):
         raise ExecutionError(
             EX_SOFTWARE, '`%(command)s\' terminated \
         with signal %(signal)d' % {
                 'command': command,
                 'signal': WTERMSIG(status)
             })
     elif WIFSTOPPED(status):
         raise ExecutionError(
             EX_SOFTWARE, '`%(command)s\' stopped with \
         signal %(signal)d' % {
                 'command': command,
                 'signal': WSTOPSIG(status)
             })
     else:
         # Failsafe: timers should have killed the process by this point, or
         # it should have ended naturally.
         kill(process.pid, SIGKILL)
         raise ExecutionError(
             EX_SOFTWARE, 'Failed timer on `%(command)s\'; \
         terminating the process extraordinarily.' % {'command': command})
Пример #8
0
def check():
    hours = (time() / 3600) % 24
    if skip[0] < hours < skip[1]:
        return
    global out
    for i, code in enumerate(codes):
        print('Testing:', code, sep='\t')
        rf = popen(' '.join(["python3", scriptdir + "test2.py", code[1]]))
        rc = rf.read()
        print(rc)
        ret = rf.close()
        ret = 0 if not ret else WEXITSTATUS(ret)

        if getenv("TEST2_DEBUG_LOG_ENDPOINT") is not None:
            post(getenv("TEST2_DEBUG_LOG_ENDPOINT"),
                 json={
                     "content":
                     "`{}`\n```\n{}\n```".format(
                         ' - '.join([
                             str(i), "{0} ({2}) - {1}".format(*code),
                             str(ret)
                         ]), rc)
                 })

        serialized = dict(
            map(lambda line: tuple(line.split(':\t', 1)),
                rc.strip().split('\n')))
        serialized['retcode'] = ret
        serialized['classname'] = code[0]
        serialized['classcode'] = code[2]
        serialized['input'] = code[1]
        print(repr(serialized))
        if ret == 0 and ret != out[i][0] and serialized.get(
                'organization') is not None:
            runwarning(serialized)
        if ret != 0 and out[i][0] == 0 and ret != out[i][0]:
            post(
                getenv('WEBHOOK'),
                json={
                    'content':
                    "It looks like the **<:gmeet:836629017774915625> Google Meet** just ended! :tada:"
                })
        out[i] = [
            6 if ret == 0 and serialized.get('organization') is None else ret,
            time()
        ]
Пример #9
0
def formatProcessStatus(status, title="Process"):
    if WIFSTOPPED(status):
        signum = WSTOPSIG(status)
        return "%s stopped by signal %s" % (title, signalName(signum))

    if WIFSIGNALED(status):
        signum = WTERMSIG(status)
        return "%s killed by signal %s" % (title, signalName(signum))

    if not WIFEXITED(status):
        raise ValueError("Invalid status: %r" % status)

    exitcode = WEXITSTATUS(status)
    if exitcode:
        return "%s exited with code %s" % (title, exitcode)
    else:
        return "%s exited normally" % title
Пример #10
0
def formatProcessStatus(status, title="Process"):
    """
    Format a process status (integer) as a string.
    """
    if WIFSTOPPED(status):
        signum = WSTOPSIG(status)
        text = "%s stopped by signal %s" % (title, signalName(signum))
    elif WIFSIGNALED(status):
        signum = WTERMSIG(status)
        text = "%s killed by signal %s" % (title, signalName(signum))
    else:
        if not WIFEXITED(status):
            raise ValueError("Invalid status: %r" % status)

        exitcode = WEXITSTATUS(status)
        if exitcode:
            text = "%s exited with code %s" % (title, exitcode)
        else:
            text = "%s exited normally" % title
    if WCOREDUMP(status):
        text += " (core dumped)"
    return text
Пример #11
0
def _waitpid(pid):
    """Convenience wrapper around the original waitpid invocation."""
    # 0 and -1 trigger a different behavior in waitpid. We disallow those
    # values.
    assert pid > 0

    while True:
        pid_, status = waitpid_(pid, 0)
        assert pid_ == pid

        if WIFEXITED(status):
            return WEXITSTATUS(status)
        elif WIFSIGNALED(status):
            # Signals are usually represented as the negated signal number.
            return -WTERMSIG(status)
        elif WIFSTOPPED(status) or WIFCONTINUED(status):
            # In our current usage scenarios we can simply ignore SIGSTOP and
            # SIGCONT by restarting the wait.
            continue
        else:
            assert False
            return 1
Пример #12
0
    def __init__(self, command, fc=True):
        '''
		Creates object _and_ runs a command
		
		command	- a command to run
		fc	- `fast call` - whether to run via fork'n'exec (True)
			  or in the subshell (False)
		'''
        if fc:
            command = command.split()

        inst = Popen3(command, True, -1)
        (o, i, e) = (inst.fromchild, inst.tochild, inst.childerr)

        self.pid = inst.pid

        self.elines = e.readlines()
        self.lines = o.readlines()

        ret = inst.wait()
        if WIFEXITED(ret):
            self.ret = WEXITSTATUS(ret)
        else:
            self.ret = 255

        i.close()
        o.close()
        e.close()

        self.edata = ""
        self.data = ""

        for i in self.lines:
            self.data += i

        for i in self.elines:
            self.edata += i
Пример #13
0
    def processStatus(self, status):
        # Process exited?
        if WIFEXITED(status):
            code = WEXITSTATUS(status)
            event = self.processExited(code)

        # Process killed by a signal?
        elif WIFSIGNALED(status):
            signum = WTERMSIG(status)
            event = self.processKilled(signum)

        # Invalid process status?
        elif not WIFSTOPPED(status):
            raise ProcessError(self, "Unknown process status: %r" % status)

        # Ptrace event?
        elif HAS_PTRACE_EVENTS and WPTRACEEVENT(status):
            event = WPTRACEEVENT(status)
            event = self.ptraceEvent(event)

        else:
            signum = WSTOPSIG(status)
            event = self.processSignal(signum)
        return event
Пример #14
0
def shell_out():
    count = 0
    try:
        p = popen("/usr/bin/env yum check-update 2>&1")
        output = p.readlines()
        rc = p.close()

        if rc is not None:
            # None represents exit code of 0, otherwise the exit code is in the
            # format returned by wait(). Exit code of 100 from yum represents
            # updates available.
            if WEXITSTATUS(rc) != 100:
                return count
        else:
            # Exit code is None (0), no updates waiting so don't both parsing output
            return count

        # Yum prints a line of hyphens (old versions) or a blank line between
        # headers and package data, so skip everything before them
        skipheaders = 0
        for line in output:
            if not skipheaders:
                if re.compile("^((-){80}|)$").search(line):
                    skipheaders = 1
                continue

            # Skip any blank lines
            if re.compile("^[ \t]*$").search(line):
                continue

            count = count + 1

        return count
    except:
        print sys.exc_info()[0]
        return count
Пример #15
0
def compile_with_gcc_and_run(file):
    system('gcc -w -D\'uint64_t=unsigned long long\' ' + file + ' -o .prog')
    return_value = WEXITSTATUS(system('./.prog'))
    system('rm ./.prog')
    return return_value
Пример #16
0
     reason = unquote(msg['reason'])
     print 'problem with execution of %s  on  %s:  %s ' % \
           (msg['exec'],host,reason)
     # keep going until all man's finish
 elif msg['cmd'] == 'job_aborted_early':
     print 'rank %d in job %s caused collective abort of all ranks' % \
           ( msg['rank'], msg['jobid'] )
     status = msg['exit_status']
     if WIFSIGNALED(status):
         if status > myExitStatus:
             myExitStatus = status
         killed_status = status & 0x007f  # AND off core flag
         print '  exit status of rank %d: killed by signal %d ' % \
               (msg['rank'],killed_status)
     else:
         exit_status = WEXITSTATUS(status)
         if exit_status > myExitStatus:
             myExitStatus = exit_status
         print '  exit status of rank %d: return code %d ' % \
               (msg['rank'],exit_status)
 elif msg['cmd'] == 'job_aborted':
     print 'job aborted; reason = %s' % (msg['reason'])
 elif msg['cmd'] == 'client_exit_status':
     if outXmlDoc:
         outXmlProc = outXmlDoc.createElement('exit-code')
         outXmlEC.appendChild(outXmlProc)
         outXmlProc.setAttribute('rank',
                                 str(msg['cli_rank']))
         outXmlProc.setAttribute('status',
                                 str(msg['cli_status']))
         outXmlProc.setAttribute('pid', str(msg['cli_pid']))
Пример #17
0
#
Пример #18
0
 def _event_handle_process_exit(self, status, pid):
     code = WEXITSTATUS(status)
     logger.debug('process exited with code:%d, pid=%d' % (code, pid))
     self.pid_dict.pop(pid)
     if len(self.pid_dict) == 0:
         self.process_exist = True