410
410
# Additional environment variables
411
411
username = studpath.url_to_jailpaths(req.path)[0]
412
412
env['HOME'] = os.path.join('/home', username)
414
class ExecutionError(Exception):
417
def execute_raw(user, jail_dir, working_dir, binary, args):
418
'''Execute a binary in a user's jail, returning the raw output.
420
The binary is executed in the given working directory with the given
421
args. A tuple of (stdout, stderr) is returned.
424
tramp = location_cgi_python
425
tramp_dir = os.path.split(location_cgi_python)[0]
427
# Fire up trampoline. Vroom, vroom.
428
proc = subprocess.Popen(
429
[tramp, str(user.unixid), jail_dir, working_dir, binary] + args,
430
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
431
stderr=subprocess.PIPE, cwd=tramp_dir, close_fds=True)
432
exitcode = proc.wait()
435
raise ExecutionError('subprocess ended with code %d, stderr %s' %
436
(exitcode, proc.stderr.read()))
437
return (proc.stdout.read(), proc.stderr.read())