Python os.WSTOPSIG Examples

The following are 14 code examples of os.WSTOPSIG(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File: posix.py    From nightmare with GNU General Public License v2.0 6 votes vote down vote up
def platformProcessEvent(self, status):

        if os.WIFEXITED(status):
            tid = self.getMeta("ThreadId", -1)
            if tid != self.getPid():
                # Set the selected thread ID to the pid cause
                # the old one's invalid
                if tid in self.pthreads:
                    self.pthreads.remove(tid)
                self.setMeta("ThreadId", self.getPid())
                self._fireExitThread(tid, os.WEXITSTATUS(status))
            else:
                self._fireExit(os.WEXITSTATUS(status))

        elif os.WIFSIGNALED(status):
            self.setMeta("ExitCode", os.WTERMSIG(status))
            self.fireNotifiers(vtrace.NOTIFY_EXIT)

        elif os.WIFSTOPPED(status):
            sig = os.WSTOPSIG(status)
            self.handlePosixSignal(sig)

        else:
            print "OMG WTF JUST HAPPENED??!?11/!?1?>!" 
Example #2
Source File: subprocess.py    From Imogen with MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example #3
Source File: subprocess.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example #4
Source File: subprocess.py    From android_universal with MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example #5
Source File: subprocess32.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope."""
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise RuntimeError("Unknown child exit status!") 
Example #6
Source File: subprocess.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise RuntimeError("Unknown child exit status!") 
Example #7
Source File: exitstatus.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def __init__(self, cmdline, sts):
        self.cmdline = cmdline
        if os.WIFEXITED(sts):
            self.state = 1
            self._status = self._es = os.WEXITSTATUS(sts)

        elif os.WIFSTOPPED(sts):
            self.state = 2
            self._status = self.stopsig = os.WSTOPSIG(sts)

        elif os.WIFSIGNALED(sts):
            self.state = 3
            self._status = self.termsig = os.WTERMSIG(sts) 
Example #8
Source File: linux.py    From mayhem with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _call_function(self, function_address, *args):
		if len(args) > 6:
			raise Exception('can not pass more than 6 arguments')
		registers_backup = self._get_registers()
		if mayhem.utilities.architecture_is_32bit(self.__arch__):
			registers = {'eip': function_address, 'eax': function_address}
			self._set_registers(registers)
			backup_sp = self.read_memory(registers_backup['esp'], 4)
			self.write_memory(registers_backup['esp'], b'\x00\x00\x00\x00')
			for i in range(len(args)):
				stack_cursor = registers_backup['esp'] + ((i + 1) * 4)
				backup_sp += self.read_memory(stack_cursor, 4)
				if args[i] < 0:
					self.write_memory(stack_cursor, struct.pack('i', args[i]))
				else:
					self.write_memory(stack_cursor, struct.pack('I', args[i]))
			self._ptrace(PTRACE_CONT)
			wait_result = os.waitpid(self.pid, 0)
			self.write_memory(registers_backup['esp'], backup_sp)
			ending_ip = self._get_registers()['eip']
			result = self._get_registers()['eax']
		elif mayhem.utilities.architecture_is_64bit(self.__arch__):
			registers = {'rip': function_address, 'rax': function_address}
			arg_registers = ['rdi', 'rsi', 'rdx', 'rcx', 'r8', 'r9']
			for i in range(len(args)):
				registers[arg_registers[i]] = args[i]
			self._set_registers(registers)
			backup_sp = self.read_memory(registers_backup['rsp'], 8)
			self.write_memory(registers_backup['rsp'], b'\x00\x00\x00\x00\x00\x00\x00\x00')
			self._ptrace(PTRACE_CONT)
			wait_result = os.waitpid(self.pid, 0)
			self.write_memory(registers_backup['rsp'], backup_sp)
			ending_ip = self._get_registers()['rip']
			result = self._get_registers()['rax']
		self._set_registers(registers_backup)
		if os.WSTOPSIG(wait_result[1]) == signal.SIGSEGV and ending_ip != 0:
			raise LinuxProcessError('segmentation fault')
		return result 
Example #9
Source File: _defs_linux.py    From ptracer with Apache License 2.0 5 votes vote down vote up
def WPTRACEEVENT(status):
    if os.WIFSTOPPED(status):
        stopsig = os.WSTOPSIG(status)
        if stopsig == signal.SIGTRAP:
            return status >> 16

    return 0 
Example #10
Source File: process.py    From ryu with Apache License 2.0 5 votes vote down vote up
def status_msg(status):
    """Given 'status', which is a process status in the form reported by
    waitpid(2) and returned by process_status(), returns a string describing
    how the process terminated."""
    if os.WIFEXITED(status):
        s = "exit status %d" % os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        s = _signal_status_msg("killed", os.WTERMSIG(status))
    elif os.WIFSTOPPED(status):
        s = _signal_status_msg("stopped", os.WSTOPSIG(status))
    else:
        s = "terminated abnormally (%x)" % status
    if os.WCOREDUMP(status):
        s += ", core dumped"
    return s 
Example #11
Source File: fork.py    From mitogen with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _convert_exit_status(status):
    """
    Convert a :func:`os.waitpid`-style exit status to a :mod:`subprocess` style
    exit status.
    """
    if os.WIFEXITED(status):
        return os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        return -os.WTERMSIG(status)
    elif os.WIFSTOPPED(status):
        return -os.WSTOPSIG(status) 
Example #12
Source File: subprocess.py    From unity-python with MIT License 5 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise RuntimeError("Unknown child exit status!") 
Example #13
Source File: AflThread.py    From afl-utils with Apache License 2.0 4 votes vote down vote up
def run(self):
        while not self.exit:
            self.in_queue_lock.acquire()
            if not self.in_queue.empty():
                cs = self.in_queue.get()
                self.in_queue_lock.release()

                cmd = self.target_cmd.replace("@@", os.path.abspath(cs))
                cs_fd = open(os.path.abspath(cs))
                try:
                    if afl_utils.afl_collect.stdin_mode(self.target_cmd):
                        v = subprocess.call(cmd.split(), stdin=cs_fd, stderr=subprocess.DEVNULL,
                                            stdout=subprocess.DEVNULL, timeout=self.timeout_secs)
                    else:
                        v = subprocess.call(cmd.split(), stderr=subprocess.DEVNULL,
                                            stdout=subprocess.DEVNULL, timeout=self.timeout_secs)
                    # check if process was terminated/stopped by signal
                    if not os.WIFSIGNALED(v) and not os.WIFSTOPPED(v):
                        self.out_queue_lock.acquire()
                        self.out_queue.put((cs, 'invalid'))
                        self.out_queue_lock.release()
                    else:
                        # need extension (add uninteresting signals):
                        # following signals don't indicate hard crashes: 1
                        # os.WTERMSIG(v) ?= v & 0x7f ???
                        if (os.WTERMSIG(v) or os.WSTOPSIG(v)) in [1]:
                            self.out_queue_lock.acquire()
                            self.out_queue.put((cs, 'invalid'))
                            self.out_queue_lock.release()
                        # debug
                        # else:
                        #     if os.WIFSIGNALED(v):
                        #         print("%s: sig: %d (%d)" % (cs, os.WTERMSIG(v), v))
                        #     elif os.WIFSTOPPED(v):
                        #         print("%s: sig: %d (%d)" % (cs, os.WSTOPSIG(v), v))
                except subprocess.TimeoutExpired:
                    self.out_queue_lock.acquire()
                    self.out_queue.put((cs, 'timeout'))
                    self.out_queue_lock.release()
                except Exception:
                    pass
                cs_fd.close()
            else:
                self.in_queue_lock.release()
                self.exit = True 
Example #14
Source File: ptrace.py    From ptracer with Apache License 2.0 4 votes vote down vote up
def _wait_for_trace_stop(pid):
    try:
        # First, check if the tracee is already stopped.
        siginfo = getsiginfo(pid)
    except OSError as e:
        if e.errno == errno.ESRCH:
            # The tracee is still running, so we'll wait
            pass
        else:
            raise
    else:
        # Normally, PTRACE_ATTACH will send a SIGSTOP to the tracee,
        # which we will see here.  However, on some kernels the actual
        # signal may sometimes be SIGTRAP, and that seems to happen
        # when the previous tracer had died without calling PTRACE_DETACH
        # on this process first.  In this case, we need to restart the process
        # and wait for the real SIGSTOP.
        if siginfo.si_signo == signal.SIGTRAP:
            cont(pid, siginfo.si_signo)
        elif is_stop_signal(siginfo.si_signo):
            return
        else:
            raise OSError('traced process has stopped with an unexpected '
                          'signal {}'.format(siginfo.si_signo))

    pid, status = wait(pid)

    if os.WIFEXITED(status):
        raise OSError('traced process {} has exited with exit code {}'.format(
            pid, os.WEXITSTATUS(status)))

    elif os.WIFSIGNALED(status):
        raise OSError('traced process {} has been killed by '
                      'the {} signal {}'.format(pid, os.WTERMSIG(status)))

    if not os.WIFSTOPPED(status):
        raise OSError('waitpid({}) returned an unexpected status {}'.format(
            pid, hex(status)))

    stopsig = os.WSTOPSIG(status)
    if stopsig != signal.SIGSTOP:
        raise OSError('waitpid({}) returned an unexpected status {}'.format(
            pid, hex(status)))