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
03d0dd98
Commit
03d0dd98
authored
Jul 01, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure the protocol remains in a sane state during PROC commands; add tests for that
parent
b17d2af5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
29 deletions
+63
-29
src/netns/protocol.py
src/netns/protocol.py
+42
-29
t/test_protocol.py
t/test_protocol.py
+21
-0
No files found.
src/netns/protocol.py
View file @
03d0dd98
...
...
@@ -418,14 +418,21 @@ class Client(object):
def
shutdown
(
self
):
"Tell the client to quit."
self
.
_send_cmd
(
(
"QUIT"
,
)
)
self
.
_send_cmd
(
"QUIT"
)
self
.
_read_and_check_reply
()
def
_send_fd
(
self
,
typ
e
,
fd
):
def
_send_fd
(
self
,
nam
e
,
fd
):
"Pass a file descriptor"
self
.
_send_cmd
(
"PROC"
,
typ
e
)
self
.
_send_cmd
(
"PROC"
,
nam
e
)
self
.
_read_and_check_reply
(
3
)
passfd
.
sendfd
(
self
.
_fd
,
fd
,
"PROC "
+
type
)
try
:
passfd
.
sendfd
(
self
.
_fd
,
fd
,
"PROC "
+
name
)
except
:
# need to fill the buffer on the other side, nevertheless
self
.
_fd
.
write
(
"="
*
(
len
(
name
)
+
5
))
# And also read the expected error
self
.
_read_and_check_reply
(
5
)
raise
self
.
_read_and_check_reply
()
def
spawn
(
self
,
executable
,
argv
=
None
,
cwd
=
None
,
env
=
None
,
...
...
@@ -443,32 +450,38 @@ class Client(object):
self
.
_send_cmd
(
*
params
)
self
.
_read_and_check_reply
()
if
user
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"USER"
,
_b64
(
user
))
self
.
_read_and_check_reply
()
if
cwd
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"CWD"
,
_b64
(
cwd
))
self
.
_read_and_check_reply
()
if
env
!=
None
:
params
=
[]
for
i
in
env
:
params
.
append
(
_b64
(
i
))
self
.
_send_cmd
(
"PROC"
,
"ENV"
,
params
)
# After this, if we get an error, we have to abort the PROC
try
:
if
user
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"USER"
,
_b64
(
user
))
self
.
_read_and_check_reply
()
if
cwd
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"CWD"
,
_b64
(
cwd
))
self
.
_read_and_check_reply
()
if
env
!=
None
:
params
=
[]
for
i
in
env
:
params
.
append
(
_b64
(
i
))
self
.
_send_cmd
(
"PROC"
,
"ENV"
,
params
)
self
.
_read_and_check_reply
()
if
stdin
!=
None
:
self
.
_send_fd
(
"SIN"
,
stdin
)
if
stdout
!=
None
:
self
.
_send_fd
(
"SOUT"
,
stdout
)
if
stderr
!=
None
:
self
.
_send_fd
(
"SERR"
,
stderr
)
self
.
_send_cmd
(
"PROC"
,
"RUN"
)
pid
=
self
.
_read_and_check_reply
().
split
()[
0
]
return
pid
except
:
self
.
_send_cmd
(
"PROC"
,
"ABRT"
)
self
.
_read_and_check_reply
()
if
stdin
!=
None
:
self
.
_send_fd
(
"SIN"
,
stdin
)
if
stdout
!=
None
:
self
.
_send_fd
(
"SOUT"
,
stdout
)
if
stderr
!=
None
:
self
.
_send_fd
(
"SERR"
,
stderr
)
self
.
_send_cmd
(
"PROC"
,
"RUN"
)
pid
=
self
.
_read_and_check_reply
().
split
()[
0
]
return
pid
raise
def
poll
(
self
,
pid
):
"""Equivalent to Popen.poll(), checks if the process has finished.
...
...
t/test_protocol.py
View file @
03d0dd98
...
...
@@ -34,6 +34,27 @@ class TestServer(unittest.TestCase):
pid
,
ret
=
os
.
waitpid
(
pid
,
0
)
self
.
assertEquals
(
ret
,
0
)
def
test_spawn_recovery
(
self
):
(
s0
,
s1
)
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
,
0
)
pid
=
os
.
fork
()
if
not
pid
:
s1
.
close
()
srv
=
netns
.
protocol
.
Server
(
s0
)
srv
.
run
()
os
.
_exit
(
0
)
cli
=
netns
.
protocol
.
Client
(
s1
)
s0
.
close
()
# make PROC SIN fail
self
.
assertRaises
(
OSError
,
cli
.
spawn
,
"/bin/true"
,
stdin
=
-
1
)
# check if the protocol is in a sane state:
# PROC CWD should not be valid
cli
.
_send_cmd
(
"PROC"
,
"CWD"
,
"/"
)
self
.
assertRaises
(
RuntimeError
,
cli
.
_read_and_check_reply
)
cli
.
shutdown
()
pid
,
ret
=
os
.
waitpid
(
pid
,
0
)
self
.
assertEquals
(
ret
,
0
)
def
test_basic_stuff
(
self
):
(
s0
,
s1
)
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
,
0
)
srv
=
netns
.
protocol
.
Server
(
s0
)
...
...
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