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
bfb3a065
Commit
bfb3a065
authored
Jul 01, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve base64 encoding, close file descriptors after spawn()
parent
85d80ba4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
7 deletions
+22
-7
src/netns/protocol.py
src/netns/protocol.py
+22
-7
No files found.
src/netns/protocol.py
View file @
bfb3a065
...
...
@@ -308,8 +308,14 @@ class Server(object):
return
self
.
_children
[
chld
.
pid
]
=
chld
self
.
_proc
=
None
self
.
commands
=
_proto_commands
# I can close the fds now
for
d
in
(
'stdin'
,
'stdout'
,
'stderr'
):
if
d
in
self
.
_proc
:
os
.
close
(
self
.
_proc
[
d
])
self
.
_proc
=
None
self
.
reply
(
200
,
"%d running."
%
chld
.
pid
)
def
do_PROC_ABRT
(
self
,
cmdname
):
...
...
@@ -406,6 +412,7 @@ class Client(object):
defaults to 2."""
code
,
text
=
self
.
_read_reply
()
if
code
/
100
!=
expected
:
# FIXME: shuld try to save and re-create exceptions
raise
RuntimeError
(
"Error from slave: %d %s"
%
(
code
,
text
))
return
text
...
...
@@ -428,26 +435,26 @@ class Client(object):
stdin/stdout/stderr can only be None or a open file descriptor.
See netns.subprocess.spawn for details."""
params
=
[
"PROC"
,
"CRTE"
,
base64
.
b64encode
(
executable
)]
params
=
[
"PROC"
,
"CRTE"
,
_b64
(
executable
)]
if
argv
!=
None
:
for
i
in
argv
:
params
.
append
(
base64
.
b64encode
(
i
))
params
.
append
(
_b64
(
i
))
self
.
_send_cmd
(
*
params
)
self
.
_read_and_check_reply
()
if
user
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"USER"
,
base64
.
b64encode
(
user
))
self
.
_send_cmd
(
"PROC"
,
"USER"
,
_b64
(
user
))
self
.
_read_and_check_reply
()
if
cwd
!=
None
:
self
.
_send_cmd
(
"PROC"
,
"CWD"
,
base64
.
b64encode
(
cwd
))
self
.
_send_cmd
(
"PROC"
,
"CWD"
,
_b64
(
cwd
))
self
.
_read_and_check_reply
()
if
env
!=
None
:
params
=
[]
for
i
in
env
:
params
.
append
(
base64
.
b64encode
(
i
))
params
.
append
(
_b64
(
i
))
self
.
_send_cmd
(
"PROC"
,
"ENV"
,
params
)
self
.
_read_and_check_reply
()
...
...
@@ -484,7 +491,7 @@ class Client(object):
exitcode
=
text
.
split
()[
0
]
return
exitcode
def
kil
l
(
self
,
pid
,
sig
=
signal
.
SIGTERM
):
def
signa
l
(
self
,
pid
,
sig
=
signal
.
SIGTERM
):
"""Equivalent to Popen.send_signal(). Sends a signal to the child
process; signal defaults to SIGTERM."""
if
sig
:
...
...
@@ -494,3 +501,11 @@ class Client(object):
text
=
self
.
_read_and_check_reply
()
def
_b64
(
text
):
text
=
str
(
text
)
if
filter
(
lambda
x
:
ord
(
x
)
>
ord
(
" "
)
and
ord
(
x
)
<=
ord
(
"z"
)
and
x
!=
"="
,
text
):
return
text
else
:
return
"="
+
base64
.
b64encode
(
text
)
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