~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/interpret.py

  • Committer: Matt Giuca
  • Date: 2009-05-26 04:15:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090526041523-hsg5q2enlhvjb5y2
doc/man/architecture.rst: User management server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# Runs a student script in a safe execution environment.
23
23
 
24
24
from ivle import studpath
25
 
from ivle.util import IVLEError, IVLEJailError
 
25
from ivle.util import IVLEError, IVLEJailError, split_path
26
26
import ivle.conf
27
27
 
28
28
import functools
138
138
 
139
139
    # usage: tramp uid jail_dir working_dir script_path
140
140
    pid = subprocess.Popen(
141
 
        [trampoline, str(uid), jail_dir, working_dir, interpreter,
 
141
        [trampoline, str(uid), ivle.conf.jail_base, ivle.conf.jail_src_base,
 
142
         ivle.conf.jail_system, jail_dir, working_dir, interpreter,
142
143
        script_path],
143
144
        stdin=f, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
144
145
        cwd=tramp_dir)
403
404
    if script_path and script_path.startswith('/home'):
404
405
        normscript = os.path.normpath(script_path)
405
406
 
406
 
        uri_into_jail = studpath.url_to_jailpaths(os.path.normpath(req.path))[2]
 
407
        uri_into_jail = studpath.to_home_path(os.path.normpath(req.path))
407
408
 
408
409
        # PATH_INFO is wrong because the script doesn't physically exist.
409
410
        env['PATH_INFO'] = uri_into_jail[len(normscript):]
415
416
    env['SERVER_SOFTWARE'] = "IVLE/" + str(ivle.conf.ivle_version)
416
417
 
417
418
    # Additional environment variables
418
 
    username = studpath.url_to_jailpaths(req.path)[0]
 
419
    username = split_path(req.path)[0]
419
420
    env['HOME'] = os.path.join('/home', username)
420
421
 
421
422
class ExecutionError(Exception):
433
434
 
434
435
    # Fire up trampoline. Vroom, vroom.
435
436
    proc = subprocess.Popen(
436
 
        [tramp, str(user.unixid), jail_dir, working_dir, binary] + args,
 
437
        [tramp, str(user.unixid), ivle.conf.jail_base,
 
438
         ivle.conf.jail_src_base, ivle.conf.jail_system, jail_dir,
 
439
         working_dir, binary] + args,
437
440
        stdin=subprocess.PIPE, stdout=subprocess.PIPE,
438
441
        stderr=subprocess.PIPE, cwd=tramp_dir, close_fds=True)
439
 
    exitcode = proc.wait()
 
442
 
 
443
    (stdout, stderr) = proc.communicate()
 
444
    exitcode = proc.returncode
440
445
 
441
446
    if exitcode != 0:
442
447
        raise ExecutionError('subprocess ended with code %d, stderr %s' %
443
448
                             (exitcode, proc.stderr.read()))
444
 
    return (proc.stdout.read(), proc.stderr.read())
 
449
    return (stdout, stderr)