Commit 83e3de74 authored by Alina Quereilhac's avatar Alina Quereilhac

Attemp to connect to main namespace xserver from a child namespace: minor changes.

parent 936dcd46
...@@ -505,15 +505,15 @@ class Client(object): ...@@ -505,15 +505,15 @@ class Client(object):
return fd return fd
except: except:
return None return None
def _send_x11_fd(self): def _send_x11_fd(self):
fd = self._create_x_socket() fd = self._create_x_socket()
if fd is not None: if fd is not None:
self._send_fd('X11', fd.fileno()) self._send_fd('X11', fd.fileno())
def spawn(self, argv, executable = None, def spawn(self, argv, executable = None,
stdin = None, stdout = None, stderr = None, stdin = None, stdout = None, stderr = None,
cwd = None, env = None, user = None): cwd = None, env = None, user = None, X = False):
"""Start a subprocess in the slave; the interface resembles """Start a subprocess in the slave; the interface resembles
subprocess.Popen, but with less functionality. In particular subprocess.Popen, but with less functionality. In particular
stdin/stdout/stderr can only be None or a open file descriptor. stdin/stdout/stderr can only be None or a open file descriptor.
...@@ -552,7 +552,8 @@ class Client(object): ...@@ -552,7 +552,8 @@ class Client(object):
if stderr != None: if stderr != None:
self._send_fd("SERR", stderr) self._send_fd("SERR", stderr)
self._send_x11_fd() if X == True:
self._send_x11_fd()
except: except:
self._send_cmd("PROC", "ABRT") self._send_cmd("PROC", "ABRT")
self._read_and_check_reply() self._read_and_check_reply()
......
...@@ -18,7 +18,7 @@ class Subprocess(object): ...@@ -18,7 +18,7 @@ class Subprocess(object):
default_user = None default_user = None
def __init__(self, node, argv, executable = None, def __init__(self, node, argv, executable = None,
stdin = None, stdout = None, stderr = None, stdin = None, stdout = None, stderr = None,
shell = False, cwd = None, env = None, user = None): shell = False, cwd = None, env = None, user = None, X = False):
self._slave = node._slave self._slave = node._slave
"""Forks and execs a program, with stdio redirection and user """Forks and execs a program, with stdio redirection and user
switching. switching.
...@@ -33,6 +33,8 @@ class Subprocess(object): ...@@ -33,6 +33,8 @@ class Subprocess(object):
numerical UID is given, a reverse lookup is performed to find the user numerical UID is given, a reverse lookup is performed to find the user
name and then set correctly the groups. name and then set correctly the groups.
The `X` parameter indicates if the subprocess will use the x11 server
To run the program in a different directory than the current one, it To run the program in a different directory than the current one, it
should be set in `cwd'. should be set in `cwd'.
...@@ -64,7 +66,7 @@ class Subprocess(object): ...@@ -64,7 +66,7 @@ class Subprocess(object):
# happens in another process! # happens in another process!
self._pid = self._slave.spawn(argv, executable = executable, self._pid = self._slave.spawn(argv, executable = executable,
stdin = stdin, stdout = stdout, stderr = stderr, stdin = stdin, stdout = stdout, stderr = stderr,
cwd = cwd, env = env, user = user) cwd = cwd, env = env, user = user, X=X)
node._add_subprocess(self) node._add_subprocess(self)
...@@ -130,7 +132,7 @@ class Popen(Subprocess): ...@@ -130,7 +132,7 @@ class Popen(Subprocess):
def __init__(self, node, argv, executable = None, def __init__(self, node, argv, executable = None,
stdin = None, stdout = None, stderr = None, bufsize = 0, stdin = None, stdout = None, stderr = None, bufsize = 0,
shell = False, cwd = None, env = None, user = None): shell = False, cwd = None, env = None, user = None, X = False):
"""As in Subprocess, `node' specifies the netns Node to run in. """As in Subprocess, `node' specifies the netns Node to run in.
The `stdin', `stdout', and `stderr' parameters also accept the special The `stdin', `stdout', and `stderr' parameters also accept the special
...@@ -164,7 +166,7 @@ class Popen(Subprocess): ...@@ -164,7 +166,7 @@ class Popen(Subprocess):
super(Popen, self).__init__(node, argv, executable = executable, super(Popen, self).__init__(node, argv, executable = executable,
stdin = fdmap['stdin'], stdout = fdmap['stdout'], stdin = fdmap['stdin'], stdout = fdmap['stdout'],
stderr = fdmap['stderr'], stderr = fdmap['stderr'],
shell = shell, cwd = cwd, env = env, user = user) shell = shell, cwd = cwd, env = env, user = user, X = X)
# Close pipes, they have been dup()ed to the child # Close pipes, they have been dup()ed to the child
for k, v in fdmap.items(): for k, v in fdmap.items():
...@@ -303,8 +305,11 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False, ...@@ -303,8 +305,11 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
if env is None: if env is None:
env = {} env = {}
env['DISPLAY'] = 'unix:0' env['DISPLAY'] = 'unix:0'
env['LD_PRELOAD'] = 'src/lib/libconnectwrapper.so' if 'NETNS_LD_PRELOAD' in os.environ:
env['NETNS_X11_FD'] = str(x11) env['LD_PRELOAD'] = os.environ['NETNS_LD_PRELOAD']
else:
env['LD_PRELOAD'] = 'src/lib/libconnectwrapper.so'
env['NETNS_X11_FD'] = str(x11)
try: try:
# Set up stdio piping # Set up stdio piping
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
import netns import netns
import os import os
netns.environ.set_log_level(netns.environ.LOG_DEBUG) #netns.environ.set_log_level(netns.environ.LOG_DEBUG)
n = netns.Node() n = netns.Node()
err = file('/tmp/out_y', 'wb') err = file('/tmp/out_y', 'wb')
a = n.Popen(['xterm'], stderr = err) a = n.Popen(['xterm'], stderr = err, X = True)
a.wait() a.wait()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment