Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a9979b8a
Commit
a9979b8a
authored
Feb 07, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Killing processes isn't working.
parent
70c37130
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
common/lib/codejail/codejail/jailpy.py
+9
-13
common/lib/codejail/codejail/tests/test_jailpy.py
+7
-1
No files found.
common/lib/codejail/codejail/jailpy.py
View file @
a9979b8a
...
...
@@ -2,7 +2,6 @@
# Instructions:
# - AppArmor.md from xserver
# XXX- apt-get install timelimit
import
os
,
os
.
path
import
resource
...
...
@@ -26,7 +25,6 @@ if os.path.exists(SANDBOX_PYTHON):
# Python -S inhibits loading site.py, which prevent Ubuntu from adding
# specialized traceback handlers that fail in the sandbox.
PYTHON_CMD
=
[
#'timelimit', '-t', '1', '-s', '9',
'sudo'
,
'-u'
,
'sandbox'
,
SANDBOX_PYTHON
,
'-S'
]
...
...
@@ -80,7 +78,6 @@ def jailpy(code, files=None, argv=None, stdin=None):
result
=
JailResult
()
result
.
stdout
,
result
.
stderr
=
subproc
.
communicate
(
stdin
)
result
.
status
=
subproc
.
returncode
killer
.
join
()
return
result
...
...
@@ -106,17 +103,16 @@ class ProcessKillerThread(threading.Thread):
self
.
limit
=
limit
def
run
(
self
):
time
.
sleep
(
self
.
limit
)
start
=
time
.
time
()
while
(
time
.
time
()
-
start
)
<
self
.
limit
:
time
.
sleep
(
.
1
)
if
self
.
subproc
.
poll
()
is
not
None
:
# Process ended, no need for us any more.
return
if
self
.
subproc
.
poll
()
is
None
:
# Can't use subproc.kill because we launched the subproc with sudo.
#killargs = ["sudo", "-u", "sandbox", "kill", "-9", str(self.subproc.pid)]
killargs
=
[
"sudo"
,
"-u"
,
"sandbox"
,
"ps"
,
str
(
self
.
subproc
.
pid
)]
print
killargs
killargs
=
[
"sudo"
,
"kill"
,
"-9"
,
str
(
self
.
subproc
.
pid
)]
kill
=
subprocess
.
Popen
(
killargs
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
kill
.
communicate
()
print
out
print
err
print
"Return status:
%
r"
%
kill
.
returncode
#if ret:
#print "Couldn't kill: %r" % ret
#os.system("sudo -u sandbox kill -9 %s" % self.subproc.pid)
# TODO: This doesn't actually kill the process.... :(
common/lib/codejail/codejail/tests/test_jailpy.py
View file @
a9979b8a
import
textwrap
import
unittest
from
nose.plugins.skip
import
SkipTest
from
codejail.jailpy
import
jailpy
...
...
@@ -43,6 +44,11 @@ class TestLimits(unittest.TestCase):
self
.
assertEqual
(
res
.
stdout
,
""
)
def
test_cant_use_too_much_time
(
self
):
res
=
jailpy
(
"import time; time.sleep(5); print 'Done!'"
)
raise
SkipTest
# TODO: test this once we can kill sleeping processes.
res
=
jailpy
(
dedent
(
"""
\
import time
time.sleep(5)
print 'Done!'
"""
))
self
.
assertNotEqual
(
res
.
status
,
0
)
self
.
assertEqual
(
res
.
stdout
,
""
)
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