Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
64c2e142
Commit
64c2e142
authored
Oct 21, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert X11 modifications
parent
a5f1257f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
149 deletions
+13
-149
protocol.txt
protocol.txt
+0
-1
src/lib/Makefile
src/lib/Makefile
+0
-9
src/lib/connect.c
src/lib/connect.c
+0
-53
src/netns/protocol.py
src/netns/protocol.py
+3
-47
src/netns/subprocess_.py
src/netns/subprocess_.py
+10
-27
test/test_x11.py
test/test_x11.py
+0
-12
No files found.
protocol.txt
View file @
64c2e142
...
@@ -27,7 +27,6 @@ PROC ENV k v k v... 200/500 (3)
...
@@ -27,7 +27,6 @@ PROC ENV k v k v... 200/500 (3)
PROC SIN 354+200/500 (4)
PROC SIN 354+200/500 (4)
PROC SOUT 354+200/500 (4)
PROC SOUT 354+200/500 (4)
PROC SERR 354+200/500 (4)
PROC SERR 354+200/500 (4)
PROC X11 354+200/500 (4)
PROC RUN 200 <pid>/500 (5)
PROC RUN 200 <pid>/500 (5)
PROC ABRT 200 (5)
PROC ABRT 200 (5)
PROC POLL <pid> 200 <code>/450/500 check if process alive
PROC POLL <pid> 200 <code>/450/500 check if process alive
...
...
src/lib/Makefile
deleted
100644 → 0
View file @
a5f1257f
CFLAGS
+=
-fpic
LDFLAGS
+=
-ldl
all
:
libconnectwrapper.so
libconnectwrapper.so
:
connect.o
$(CC)
$(LDFLAGS)
-shared
-o
$@
$^
connect.o
:
connect.c
clean
:
rm
-f
*
.o 2>/dev/null
\ No newline at end of file
src/lib/connect.c
deleted
100644 → 0
View file @
a5f1257f
#define _GNU_SOURCE 1
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
static
int
get_xfd
(
void
)
{
char
*
env
=
getenv
(
"NETNS_X11_FD"
);
if
(
env
==
0
)
{
return
-
1
;
}
return
atoi
(
env
);
}
typedef
int
(
*
ConnectFunction
)
(
int
,
const
struct
sockaddr
*
,
socklen_t
);
int
connect
(
int
sockfd
,
const
struct
sockaddr
*
serv_addr
,
socklen_t
addrlen
)
{
if
(
serv_addr
->
sa_family
==
AF_UNIX
)
{
const
struct
sockaddr_un
*
sun
=
(
const
struct
sockaddr_un
*
)
serv_addr
;
if
(
strcmp
(
sun
->
sun_path
,
"/tmp/.X11-unix/X0"
)
==
0
)
{
// this is an attempt to connect to the X server.
// intercept !
int
xfd
=
get_xfd
();
fcntl
(
xfd
,
F_SETFD
,
0
);
int
status
=
dup2
(
xfd
,
sockfd
);
status
=
close
(
xfd
);
return
0
;
}
}
// lookup the symbol named connect in the next library
// in the name lookup scope of the dynamic loader
void
*
symbol
=
dlsym
(
RTLD_NEXT
,
"connect"
);
if
(
symbol
==
0
)
{
return
-
1
;
}
ConnectFunction
connect_function
=
(
ConnectFunction
)
symbol
;
int
status
=
connect_function
(
sockfd
,
serv_addr
,
addrlen
);
return
status
;
}
src/netns/protocol.py
View file @
64c2e142
...
@@ -58,7 +58,6 @@ _proc_commands = {
...
@@ -58,7 +58,6 @@ _proc_commands = {
"SIN"
:
(
""
,
""
),
"SIN"
:
(
""
,
""
),
"SOUT"
:
(
""
,
""
),
"SOUT"
:
(
""
,
""
),
"SERR"
:
(
""
,
""
),
"SERR"
:
(
""
,
""
),
"X11"
:
(
""
,
""
),
"RUN"
:
(
""
,
""
),
"RUN"
:
(
""
,
""
),
"ABRT"
:
(
""
,
""
),
"ABRT"
:
(
""
,
""
),
}
}
...
@@ -262,13 +261,12 @@ class Server(object):
...
@@ -262,13 +261,12 @@ class Server(object):
self
.
reply
(
500
,
"Invalid payload: %s."
%
payload
)
self
.
reply
(
500
,
"Invalid payload: %s."
%
payload
)
return
return
m
=
{
'PROC SIN'
:
'stdin'
,
'PROC SOUT'
:
'stdout'
,
'PROC SERR'
:
'stderr'
,
m
=
{
'PROC SIN'
:
'stdin'
,
'PROC SOUT'
:
'stdout'
,
'PROC SERR'
:
'stderr'
}
'PROC X11'
:
'x11'
}
self
.
_proc
[
m
[
cmdname
]]
=
fd
self
.
_proc
[
m
[
cmdname
]]
=
fd
self
.
reply
(
200
,
'FD saved as %s.'
%
m
[
cmdname
])
self
.
reply
(
200
,
'FD saved as %s.'
%
m
[
cmdname
])
# Same code for the three commands
# Same code for the three commands
do_PROC_SOUT
=
do_PROC_SERR
=
do_PROC_
X11
=
do_PROC_
SIN
do_PROC_SOUT
=
do_PROC_SERR
=
do_PROC_SIN
def
do_PROC_RUN
(
self
,
cmdname
):
def
do_PROC_RUN
(
self
,
cmdname
):
params
=
self
.
_proc
params
=
self
.
_proc
...
@@ -472,48 +470,9 @@ class Client(object):
...
@@ -472,48 +470,9 @@ class Client(object):
raise
raise
self
.
_read_and_check_reply
()
self
.
_read_and_check_reply
()
def
_create_x_socket
(
self
):
import
os
import
socket
import
re
if
not
os
.
environ
.
has_key
(
'DISPLAY'
):
use_unix
=
True
display
=
'0'
else
:
disp
=
os
.
environ
[
'DISPLAY'
]
m
=
re
.
match
(
'([^:]+)(:([0-9]+))?'
,
disp
)
if
m
is
None
:
use_unix
=
True
display
=
'0'
else
:
host
=
m
.
group
(
1
)
display
=
m
.
group
(
3
)
if
host
==
'unix'
:
use_unix
=
True
else
:
use_unix
=
False
if
display
is
None
:
display
=
'0'
try
:
if
use_unix
:
fd
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
fd
.
connect
(
'/tmp/.X11-unix/X'
+
display
)
else
:
fd
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
port
=
6000
+
int
(
display
)
fd
.
connect
((
host
,
port
))
return
fd
except
:
return
None
def
_send_x11_fd
(
self
):
fd
=
self
.
_create_x_socket
()
if
fd
is
not
None
:
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
,
X
=
False
):
cwd
=
None
,
env
=
None
,
user
=
None
):
"""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.
...
@@ -551,9 +510,6 @@ class Client(object):
...
@@ -551,9 +510,6 @@ class Client(object):
self
.
_send_fd
(
"SOUT"
,
stdout
)
self
.
_send_fd
(
"SOUT"
,
stdout
)
if
stderr
!=
None
:
if
stderr
!=
None
:
self
.
_send_fd
(
"SERR"
,
stderr
)
self
.
_send_fd
(
"SERR"
,
stderr
)
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
()
...
...
src/netns/subprocess_.py
View file @
64c2e142
...
@@ -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
,
X
=
False
):
shell
=
False
,
cwd
=
None
,
env
=
None
,
user
=
None
):
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,8 +33,6 @@ class Subprocess(object):
...
@@ -33,8 +33,6 @@ 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'.
...
@@ -66,7 +64,7 @@ class Subprocess(object):
...
@@ -66,7 +64,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
,
X
=
X
)
cwd
=
cwd
,
env
=
env
,
user
=
user
)
node
.
_add_subprocess
(
self
)
node
.
_add_subprocess
(
self
)
...
@@ -132,7 +130,7 @@ class Popen(Subprocess):
...
@@ -132,7 +130,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
,
X
=
False
):
shell
=
False
,
cwd
=
None
,
env
=
None
,
user
=
None
):
"""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
...
@@ -166,7 +164,7 @@ class Popen(Subprocess):
...
@@ -166,7 +164,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
,
X
=
X
)
shell
=
shell
,
cwd
=
cwd
,
env
=
env
,
user
=
user
)
# 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
():
...
@@ -255,7 +253,7 @@ def backticks_raise(node, args):
...
@@ -255,7 +253,7 @@ def backticks_raise(node, args):
# Server-side code, called from netns.protocol.Server
# Server-side code, called from netns.protocol.Server
def
spawn
(
executable
,
argv
=
None
,
cwd
=
None
,
env
=
None
,
close_fds
=
False
,
def
spawn
(
executable
,
argv
=
None
,
cwd
=
None
,
env
=
None
,
close_fds
=
False
,
stdin
=
None
,
stdout
=
None
,
stderr
=
None
,
user
=
None
,
x11
=
None
):
stdin
=
None
,
stdout
=
None
,
stderr
=
None
,
user
=
None
):
"""Internal function that performs all the dirty work for Subprocess, Popen
"""Internal function that performs all the dirty work for Subprocess, Popen
and friends. This is executed in the slave process, directly from the
and friends. This is executed in the slave process, directly from the
protocol.Server class.
protocol.Server class.
...
@@ -301,16 +299,6 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
...
@@ -301,16 +299,6 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
pid
=
os
.
fork
()
pid
=
os
.
fork
()
if
pid
==
0
:
# pragma: no cover
if
pid
==
0
:
# pragma: no cover
# coverage doesn't seem to understand fork
# coverage doesn't seem to understand fork
if
x11
is
not
None
:
if
env
is
None
:
env
=
{}
env
[
'DISPLAY'
]
=
'unix:0'
if
'NETNS_LD_PRELOAD'
in
os
.
environ
:
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
for
i
in
range
(
3
):
for
i
in
range
(
3
):
...
@@ -326,18 +314,13 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
...
@@ -326,18 +314,13 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
if
close_fds
==
True
:
if
close_fds
==
True
:
for
i
in
xrange
(
3
,
MAXFD
):
for
i
in
xrange
(
3
,
MAXFD
):
if
i
==
w
:
if
i
!=
w
:
continue
try
:
if
x11
is
not
None
and
i
==
x11
:
os
.
close
(
i
)
continue
except
:
try
:
pass
os
.
close
(
i
)
except
:
pass
elif
close_fds
!=
False
:
elif
close_fds
!=
False
:
for
i
in
close_fds
:
for
i
in
close_fds
:
if
x11
is
not
None
and
i
==
x11
:
continue
os
.
close
(
i
)
os
.
close
(
i
)
if
user
!=
None
:
if
user
!=
None
:
...
...
test/test_x11.py
deleted
100644 → 0
View file @
a5f1257f
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import
netns
import
os
#netns.environ.set_log_level(netns.environ.LOG_DEBUG)
n
=
netns
.
Node
()
err
=
file
(
'/tmp/out_y'
,
'wb'
)
a
=
n
.
Popen
([
'xterm'
],
stderr
=
err
,
X
=
True
)
a
.
wait
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment