Ejemplo n.º 1
0
Archivo: Run.py Proyecto: rancb/ocean
def createChild(arguments, no_stdout, env=None):
    """
    Create a child process:
     - arguments: list of string where (eg. ['ls', '-la'])
     - no_stdout: if True, use null device for stdout/stderr
     - env: environment variables dictionary

    Use:
     - env={} to start with an empty environment
     - env=None (default) to copy the environment
    """

    # Fork process
    pid = fork()
    if pid:
        return pid
    else:

        try:
          ptrace_traceme()
        except PtraceError, err:
          raise ChildError(str(err))

        _execChild(arguments, no_stdout, env)
        exit(255)
Ejemplo n.º 2
0
def _createChild(arguments,
                 no_stdout,
                 env,
                 errpipe_write,
                 close_fds=True,
                 pass_fds=()):
    # Child code
    try:
        ptrace_traceme()
    except PtraceError as err:
        raise ChildError(str(err))

    for fd in pass_fds:
        set_inheritable(fd, True)

    if close_fds:
        # Close all files except 0, 1, 2 and errpipe_write
        for fd in range(3, MAXFD):
            if fd == errpipe_write or (fd in pass_fds):
                continue
            try:
                close(fd)
            except OSError:
                pass

    try:
        _execChild(arguments, no_stdout, env)
    except:   # noqa: E722
        exc_type, exc_value, tb = exc_info()
        # Save the traceback and attach it to the exception object
        exc_lines = format_exception(exc_type, exc_value, tb)
        exc_value.child_traceback = ''.join(exc_lines)
        _write_no_intr(errpipe_write, pickle.dumps(exc_value))
    exit(255)
Ejemplo n.º 3
0
def createChild(arguments, no_stdout, env=None):
    """
    Create a child process:
     - arguments: list of string where (eg. ['ls', '-la'])
     - no_stdout: if True, use null device for stdout/stderr
     - env: environment variables dictionary

    Use:
     - env={} to start with an empty environment
     - env=None (default) to copy the environment
    """

    # Fork process
    pid = fork()
    if pid:
        return pid
    else:
        #print "limit",getrlimit(RLIMIT_DATA)
        setrlimit(RLIMIT_AS, (1024 * 1024 * 1024, -1))
        #print "limit",getrlimit(RLIMIT_DATA)

        try:
            ptrace_traceme()
        except PtraceError, err:
            raise ChildError(str(err))

        _execChild(arguments, no_stdout, env)
        exit(255)
Ejemplo n.º 4
0
    def createChild(self, program):
        # Fork process
        pid = fork()
        if pid:
            return pid

        # Child code
        try:
            ptrace_traceme()
        except PtraceError, err:
            print >> stderr, "CHILD PTRACE ERROR! %s" % err
            exit(1)
Ejemplo n.º 5
0
    def createChild(self, program):
        # Fork process
        pid = fork()
        if pid:
            return pid

        # Child code
        try:
            ptrace_traceme()
        except PtraceError, err:
            print >>stderr, "CHILD PTRACE ERROR! %s" % err
            exit(1)
Ejemplo n.º 6
0
    def __init__(self, args):
        self.pid = os.fork()

        if self.pid == 0:
            ptrace_traceme()
            os.execvp(args[0], args)
            os.exit(0)

        self.tracer = ptrace.debugger.PtraceDebugger()
        # wait for the pid, I guess
        # waitpid_no_intr(self.pid, 0)
        self.process = self.tracer.addProcess(self.pid, True)
Ejemplo n.º 7
0
    def __spawn(self):
        self.pid = os.fork()
        if self.pid == 0:
            # Make GCOV dump into the session_dir
            os.environ['GCOV_PREFIX'] = self.service.gcov_dir
            os.environ['GCOV_PREFIX_STRIP'] = str(service.gcovstrip)
            os.close(sys.stdin.fileno())
            os.close(sys.stderr.fileno())
            os.close(sys.stdout.fileno())

            ptrace_traceme() #force process to stop after exec
            os.execvp(self.service.cmd[0], self.service.cmd)
            raise Exception("Failed to Exec")
        (pid, ret) = os.waitpid(self.pid, 0) #Wait for first trap
Ejemplo n.º 8
0
    def __spawn(self):
        self.pid = os.fork()
        if self.pid == 0:
            # Make GCOV dump into the session_dir
            os.environ['GCOV_PREFIX'] = self.service.gcov_dir
            os.environ['GCOV_PREFIX_STRIP'] = str(service.gcovstrip)
            os.close(sys.stdin.fileno())
            os.close(sys.stderr.fileno())
            os.close(sys.stdout.fileno())

            os.dup2(self.conn.fileno(), sys.stdin.fileno())
            os.dup2(self.conn.fileno(), sys.stderr.fileno())
            os.dup2(self.conn.fileno(), sys.stdout.fileno())

            ptrace_traceme() #force process to stop after exec
            os.execvp(self.service.cmd[0], self.service.cmd)
            raise Exception("Failed to Exec")
        (pid, ret) = os.waitpid(self.pid, 0) #Wait for first trap
        self.tracer = PtraceProcess(None, self.pid, True)
        #set a breakpoint when it exits gracefully
        self.exitbp = self.tracer.createBreakpoint(self.finiaddr)
        ptrace_cont(self.pid) #Start the process again
        self.service.instances[self.pid] = self
Ejemplo n.º 9
0
def _createChild(arguments, no_stdout, env, errpipe_write):
    # Child code
    try:
        ptrace_traceme()
    except PtraceError as err:
        raise ChildError(str(err))

    # Close all files except 0, 1, 2 and errpipe_write
    for fd in range(3, MAXFD):
        if fd == errpipe_write:
            continue
        try:
            close(fd)
        except OSError:
            pass
    try:
        _execChild(arguments, no_stdout, env)
    except:
        exc_type, exc_value, tb = exc_info()
        # Save the traceback and attach it to the exception object
        exc_lines = format_exception(exc_type, exc_value, tb)
        exc_value.child_traceback = ''.join(exc_lines)
        _write_no_intr(errpipe_write, pickle.dumps(exc_value))
    exit(255)
Ejemplo n.º 10
0
def _createChild(arguments, no_stdout, env, errpipe_write):
    # Child code
    try:
        ptrace_traceme()
    except PtraceError, err:
        raise ChildError(str(err))
Ejemplo n.º 11
0
 def traceme(self):
     if not self.enabled:
         return False
     ptrace_traceme()
     return True
Ejemplo n.º 12
0
 def traceme(self):
     if not self.enabled:
         return False
     ptrace_traceme()
     return True