def test_granting_to_subprocess(self):
   parent_socket, child_socket = naclimc.os_socketpair()
   if sys.platform == "win32":
     import win32api
     import win32con
     close = win32api.CloseHandle
     win32api.SetHandleInformation(child_socket, win32con.HANDLE_FLAG_INHERIT,
                                   win32con.HANDLE_FLAG_INHERIT)
     kwargs = {}
   else:
     close = os.close
     def pre_exec():
       close(parent_socket)
     kwargs = {"preexec_fn": pre_exec}
   if 'PYTHON_ARCH' in os.environ:
     # This is a workaround for Mac OS 10.6 where we have to request
     # an architecture for the interpreter that matches the extension
     # we built.
     python_prefix = ['arch', '-arch', os.environ['PYTHON_ARCH']]
   else:
     python_prefix = []
   proc = subprocess.Popen(
       python_prefix
       + [sys.executable,
          os.path.join(os.path.dirname(__file__), "test_prog.py"),
          "%i" % child_socket],
       **kwargs)
   close(child_socket)
   socket = naclimc.from_os_socket(parent_socket)
   received = socket.imc_recvmsg(100)
   self.assertEquals(received, ("message from test_prog", ()))
Ejemplo n.º 2
0
def _spawn_sel_ldr(args, fd_slots, **kwargs):
    """ do the actual NaCl launch.

    First, setup the in and out file descriptors,
    add them to the command line arguements passed to sel_ldr
    then fork and launch sel_ldr.

    """
    sockets = [(fd_slot, naclimc.os_socketpair())
               for fd_slot in fd_slots]
    extra_args = []
    for fd_slot, (child_fd, parent_fd) in sockets:
        extra_args.extend(["-i", "%i:%i" % (fd_slot, child_fd)])

    def _pre_exec():
        """ before we run, close off the other ends of the FDs so we can't
        use them."""
        for _, (_, parent_fd) in sockets:
            os.close(parent_fd)

    cmd = [repy_constants.NACL_ENV["NACL_SEL_LDR"]] + extra_args + args
 
    proc = subprocess.Popen(cmd, preexec_fn=_pre_exec, **kwargs)
    start_new_thread(nacl_watchdog, (proc,))
    for fd_slot, (child_fd, parent_fd) in sockets:
        os.close(child_fd)
    result_sockets = [naclimc.from_os_socket(parent_fd)
                      for fd_slot, (child_fd, parent_fd) in sockets]
    return proc, result_sockets
Ejemplo n.º 3
0
def _spawn_sel_ldr(args, fd_slots, **kwargs):
    """ do the actual NaCl launch.

    First, setup the in and out file descriptors,
    add them to the command line arguements passed to sel_ldr
    then fork and launch sel_ldr.

    """
    sockets = [(fd_slot, naclimc.os_socketpair()) for fd_slot in fd_slots]
    extra_args = []
    for fd_slot, (child_fd, parent_fd) in sockets:
        extra_args.extend(["-i", "%i:%i" % (fd_slot, child_fd)])

    def _pre_exec():
        """ before we run, close off the other ends of the FDs so we can't
        use them."""
        for _, (_, parent_fd) in sockets:
            os.close(parent_fd)

    cmd = [repy_constants.NACL_ENV["NACL_SEL_LDR"]] + extra_args + args

    proc = subprocess.Popen(cmd, preexec_fn=_pre_exec, **kwargs)
    start_new_thread(nacl_watchdog, (proc, ))
    for fd_slot, (child_fd, parent_fd) in sockets:
        os.close(child_fd)
    result_sockets = [
        naclimc.from_os_socket(parent_fd)
        for fd_slot, (child_fd, parent_fd) in sockets
    ]
    return proc, result_sockets
Ejemplo n.º 4
0
    def test_granting_to_subprocess(self):
        parent_socket, child_socket = naclimc.os_socketpair()
        if sys.platform == "win32":
            import win32api
            import win32con
            close = win32api.CloseHandle
            win32api.SetHandleInformation(child_socket,
                                          win32con.HANDLE_FLAG_INHERIT,
                                          win32con.HANDLE_FLAG_INHERIT)
            kwargs = {}
        else:
            close = os.close

            def pre_exec():
                close(parent_socket)

            kwargs = {"preexec_fn": pre_exec}
        if 'PYTHON_ARCH' in os.environ:
            # This is a workaround for Mac OS 10.6 where we have to request
            # an architecture for the interpreter that matches the extension
            # we built.
            python_prefix = ['arch', '-arch', os.environ['PYTHON_ARCH']]
        else:
            python_prefix = []
        proc = subprocess.Popen(
            python_prefix + [
                sys.executable,
                os.path.join(os.path.dirname(__file__), "test_prog.py"),
                "%i" % child_socket
            ], **kwargs)
        close(child_socket)
        socket = naclimc.from_os_socket(parent_socket)
        received = socket.imc_recvmsg(100)
        self.assertEquals(received, ("message from test_prog", ()))
Ejemplo n.º 5
0
def _spawn_internal_sel_ldr(args, fd_slots, **kwargs):
    # prepare the UD socket
    sockets = [(fd_slot, naclimc.os_socketpair())
               for fd_slot in fd_slots]
    extra_args = []
    for fd_slot, (child_fd, parent_fd) in sockets:
        extra_args.extend(["-i", "%i:%i" % (fd_slot, child_fd)])

    cmd = [repy_constants.NACL_ENV["NACL_SEL_LDR"]] + extra_args + args

    nacl.call_native_launch(cmd)
    
    result_sockets = [naclimc.from_os_socket(parent_fd)
                      for fd_slot, (child_fd, parent_fd) in sockets]


    return None, result_sockets
Ejemplo n.º 6
0
def _spawn_internal_sel_ldr(args, fd_slots, **kwargs):
    # prepare the UD socket
    sockets = [(fd_slot, naclimc.os_socketpair()) for fd_slot in fd_slots]
    extra_args = []
    for fd_slot, (child_fd, parent_fd) in sockets:
        extra_args.extend(["-i", "%i:%i" % (fd_slot, child_fd)])

    cmd = [repy_constants.NACL_ENV["NACL_SEL_LDR"]] + extra_args + args

    nacl.call_native_launch(cmd)

    result_sockets = [
        naclimc.from_os_socket(parent_fd)
        for fd_slot, (child_fd, parent_fd) in sockets
    ]

    return None, result_sockets
Ejemplo n.º 7
0
def Main(args):
    child_fd, parent_fd = naclimc.os_socketpair()
    socket = naclimc.from_os_socket(parent_fd)
    bitness = os.environ.get('NACL_BITNESS', '')
    sel_ldr_name = 'nacl{0}-sel_ldr'.format(bitness)

    child = subprocess.Popen(
        [sel_ldr_name, '-i', '3:'+str(child_fd), '--', 'test']
    )
    def handler(signum, frame):
        print 'Caught SIGCHLD'
        raise KeyboardInterrupt
    signal(SIGCHLD, handler)
    try:
        serve(socket)
        sys.exit(child.wait())
    except KeyboardInterrupt:
        pass
 def test_raw_socketpair(self):
   fd1, fd2 = naclimc.os_socketpair()
   sock1 = naclimc.from_os_socket(fd1)
   sock2 = naclimc.from_os_socket(fd2)
   self._CheckDataMessages(sock1, sock2)
   self._CheckDataMessages(sock2, sock1)
Ejemplo n.º 9
0
 def test_raw_socketpair(self):
     fd1, fd2 = naclimc.os_socketpair()
     sock1 = naclimc.from_os_socket(fd1)
     sock2 = naclimc.from_os_socket(fd2)
     self._CheckDataMessages(sock1, sock2)
     self._CheckDataMessages(sock2, sock1)