Exemplo n.º 1
0
def pass_on_signals(pid):
	from os import waitpid, WIFSTOPPED, WSTOPSIG
	from sys import stderr
	while True:
		retpid, status = waitpid(pid, 0)
		assert WIFSTOPPED(status)
		signum = WSTOPSIG(status)
		print >>stderr, "Passing signal to tracee:", signum
		ptrace_cont(pid, signum)
Exemplo n.º 2
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})
Exemplo n.º 3
0
    def SimpleRegistration(self):

        version = GetSystemVersion()
        if version == 6:
            self.clustername = self.clustername + version

        exit_status = system(
            'subscription-manager register --org={} --activationkey={}-KEY {} &> /dev/null'
            .format(self.organization, self.clustername, self.force))
        if WSTOPSIG(exit_status) == 64:
            wait.Info('System already registered, use --force to override')

        return exit_status
Exemplo n.º 4
0
def wait_for_tracee_stop(pid):
	from os import waitpid, WIFSTOPPED, WSTOPSIG
	from signal import SIGSTOP
	from sys import stderr
	while True:
		retpid, status = waitpid(pid, 0)
		assert retpid == pid
		assert WIFSTOPPED(status)
		signum = WSTOPSIG(status)
		if signum == SIGSTOP:
			break
		else:
			print >>stderr, "Passing signal to tracee:", signum
			ptrace_cont(pid, signum)
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
    def _event_handle_process_signal(self, status, pid):
        signum = WSTOPSIG(status)
        logger.debug('signum:%d-%s, pid=%d' %
                     (signum & 0x7f, signal_name(signum & 0x7f), pid))
        dr6 = self.get_debug_regs(6)
        logger.debug('dr6=' + hex(dr6))
        dr7 = self.get_debug_regs(7)
        logger.debug('dr7=' + hex(dr7))

        self.regs = self.get_regs()

        dr6 = self.get_debug_regs(6)
        dr7 = self.get_debug_regs(7)

        if CPU_64BITS:
            logger.debug('rip=%08x' % self.regs.rip)
        else:
            logger.debug('eip=%08x' % self.regs.eip)

        if signum == SIGTRAP:
            if (0x80 | signum) == 0x80:
                is_sys_call = True
            else:
                is_sys_call = False
            return self._event_handle_sigtrap(pid, is_sys_call)

        if signum in self.callbacks.keys():
            return self.callbacks[signum](self)

        # ret
        if self.signal_handle_mode.has_key(signum):
            ignore = self.signal_handle_mode[signum]
            if ignore:
                if signum == SIGSEGV:
                    # self.print_vmmap()
                    self.generate_gcore(pid)
                return 0
        return signum
Exemplo n.º 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