Beispiel #1
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
Beispiel #2
0
    def _debug_event_iteration(self):
        # (pid, status) = waitpid(self.pid, 0)
        (pid, status) = waitpid(0, 0)
        self.pid = pid
        signum = 0
        logger.debug('status:' + hex(status) + ' pid:' + str(pid))
        # Process exited?
        if WIFEXITED(status):
            self._event_handle_process_exit(status, pid)

        # Process killed by a signal?
        elif WIFSIGNALED(status):
            self._event_handle_process_kill(status, pid)

        # Invalid process status?
        elif not WIFSTOPPED(status):
            self._event_handle_process_unknown_status(status, pid)

        # Ptrace event?
        elif self.WPTRACEEVENT(status):
            self._event_handle_process_ptrace_event(status, pid)
        else:
            signum = self._event_handle_process_signal(status, pid)

        # continue
        if signum is None:
            signum = 0
        if self.single_step_flag | (self._restore_breakpoint is not None):
            self._ptrace(PTRACE_SINGLESTEP, pid, 0, signum)
        elif self.trace_sys_call_flag:
            self._ptrace(PTRACE_SYSCALL, pid, 0, signum)
        else:
            self._ptrace(PTRACE_CONT, pid, 0, signum)
Beispiel #3
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)
Beispiel #4
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})
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
0
     done += 1
 elif not msg.has_key('cmd'):
     mpd_raise('mpdrun: from man, invalid msg=:%s:' % (msg))
 elif msg['cmd'] == 'execution_problem':
     # print 'rank %d (%s) in job %s failed to find executable %s' % \
     # ( msg['rank'], msg['src'], msg['jobid'], msg['exec'] )
     host = msg['src'].split('_')[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: