From ec37b5c50fdfea462d810641c4a6da933b1a6159 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Thu, 9 Jul 2015 18:19:05 -0400 Subject: [PATCH 1/9] Don't hardcode container interface in Docker vmms Instead of putting all the file copying and su-ing in the docker run command constructed by the vmm, include an interface script in the container and use it as the container entrypoint. The only thing passed from the vmm to the container are the resource limit parameters. In addition, rewrite the dockerfile so it (1) includes fewer RUN lines, and (2) does not need to fetch Tango from github in order to build autodriver; Instead, the autodriver source is copied to the container using the ADD instruction --- autodriver/Dockerfile | 32 +++++++++++++++++++++++++++++++ autodriver/autograde_wrapper.py | 33 ++++++++++++++++++++++++++++++++ vmms/Dockerfile | 34 --------------------------------- vmms/localDocker.py | 10 +--------- 4 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 autodriver/Dockerfile create mode 100644 autodriver/autograde_wrapper.py delete mode 100644 vmms/Dockerfile diff --git a/autodriver/Dockerfile b/autodriver/Dockerfile new file mode 100644 index 00000000..7cb0c15c --- /dev/null +++ b/autodriver/Dockerfile @@ -0,0 +1,32 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +RUN apt-get update && apt-get install -y build-essential wget + +# Install autodriver +WORKDIR /home +RUN useradd autolab && useradd autograde +RUN mkdir autolab autograde output && chown autolab:autolab autolab output && chown autograde:autograde autograde +ADD . /home/autodriver +WORKDIR /home/autodriver +RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper +ENTRYPOINT ["/usr/bin/autograde_wrapper"] + +# Install C0 +WORKDIR /home +RUN wget http://c0.typesafety.net/dist/cc0-v0440-linux3.18.1-64bit-bin.tgz +RUN tar -xvzf cc0-* +WORKDIR /home/cc0 +RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0 +#RUN ./a.out +RUN cp bin/cc0 /usr/bin/cc0 + +# Clean up +WORKDIR /home +RUN apt-get remove -y wget && apt-get -y autoremove +RUN rm -rf autodriver cc0* + +# Check installation +RUN ls -l /home && which autodriver && which cc0 diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py new file mode 100644 index 00000000..c6f6de3a --- /dev/null +++ b/autodriver/autograde_wrapper.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 +import sys +import os +import pwd +import shutil +import subprocess +print("Running "+ str(sys.argv)) + +for f in os.listdir("mount"): + src=os.path.join("mount", f) + dst=os.path.join("autolab", f) + shutil.copy(src, dst) + +autolabuser=pwd.getpwnam("autolab") +pid=os.fork() +if pid == 0: + os.setgroups([]) + os.setgid(autolabuser.pw_gid) + os.setuid(autolabuser.pw_uid) + outfile=open("output/feedback", "w") + args=["autodriver"] + args.extend(sys.argv[1:]) + args.append("autolab") + print("Executing "+str(args), file=outfile) + sys.exit(subprocess.call(args, stdout=outfile, stderr=outfile, close_fds=True)) +(np, status)=os.waitpid(pid, 0) +# if core, exit -1, else pass through code. +if status & 0xff: + status=-1 +else: + status>>=8; +shutil.copy("output/feedback", "mount/feedback") +sys.exit(status) diff --git a/vmms/Dockerfile b/vmms/Dockerfile deleted file mode 100644 index e9053445..00000000 --- a/vmms/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN apt-get install -y git -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# Clean up -WORKDIR /home -RUN apt-get remove -y git -RUN apt-get -y autoremove -RUN rm -rf Tango/ - -# Check installation -RUN ls -l /home -RUN which autodriver \ No newline at end of file diff --git a/vmms/localDocker.py b/vmms/localDocker.py index 45b54145..1825a10b 100644 --- a/vmms/localDocker.py +++ b/vmms/localDocker.py @@ -136,16 +136,8 @@ def runJob(self, vm, runTimeout, maxOutputFileSize): args = ['docker', 'run', '--name', instanceName, '-v'] args = args + ['%s:%s' % (volumePath, '/home/mount')] args = args + [vm.image] - args = args + ['sh', '-c'] - autodriverCmd = 'autodriver -u %d -f %d -t %d -o %d autolab &> output/feedback' % \ - (config.Config.VM_ULIMIT_USER_PROC, - config.Config.VM_ULIMIT_FILE_SIZE, - runTimeout, config.Config.MAX_OUTPUT_FILE_SIZE) - - args = args + ['cp -r mount/* autolab/; su autolab -c "%s"; \ - cp output/feedback mount/feedback' % - autodriverCmd] + args = args + [ "-u", str(config.Config.VM_ULIMIT_USER_PROC), "-f", str(config.Config.VM_ULIMIT_FILE_SIZE), "-t", str(runTimeout), "-o", str(config.Config.MAX_OUTPUT_FILE_SIZE)] self.log.debug('Running job: %s' % str(args)) ret = timeout(args, runTimeout * 2) From bfcdb44df14356e5a08ab6f028d81190002b1c98 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Wed, 15 Jul 2015 21:31:21 -0400 Subject: [PATCH 2/9] python 2.x and 3.x compat for interface script Make the wrapper script compatible with python 2.x (x>=6), not just 3.0 --- autodriver/autograde_wrapper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py index c6f6de3a..878fdc87 100644 --- a/autodriver/autograde_wrapper.py +++ b/autodriver/autograde_wrapper.py @@ -1,10 +1,11 @@ -#!/usr/bin/python3 +#!/usr/bin/python +from __future__ import print_function import sys import os import pwd import shutil import subprocess -print("Running "+ str(sys.argv)) +#print("Running "+ str(sys.argv)) for f in os.listdir("mount"): src=os.path.join("mount", f) From 67524d8fae34e99e380a024e59a0ad039a5e9de2 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Sun, 2 Aug 2015 16:44:25 -0400 Subject: [PATCH 3/9] Dockerfile: install python, make cc0 work install python2 so interface script can use #!/usr/bin/python Install all of C0's files, and use a wrapper shell script for cc0 so the compiler is always invoked with an absolute path --- autodriver/Dockerfile | 9 ++++----- autodriver/cc0wrap.sh | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 autodriver/cc0wrap.sh diff --git a/autodriver/Dockerfile b/autodriver/Dockerfile index 7cb0c15c..b36fb2a4 100644 --- a/autodriver/Dockerfile +++ b/autodriver/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:14.04 MAINTAINER Mihir Pandya -RUN apt-get update && apt-get install -y build-essential wget +RUN apt-get update && apt-get install -y build-essential wget python # Install autodriver WORKDIR /home @@ -11,17 +11,16 @@ RUN useradd autolab && useradd autograde RUN mkdir autolab autograde output && chown autolab:autolab autolab output && chown autograde:autograde autograde ADD . /home/autodriver WORKDIR /home/autodriver -RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper +RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper && cp cc0wrap.sh /usr/bin/cc0 && chmod +x /usr/bin/cc0 ENTRYPOINT ["/usr/bin/autograde_wrapper"] # Install C0 WORKDIR /home RUN wget http://c0.typesafety.net/dist/cc0-v0440-linux3.18.1-64bit-bin.tgz -RUN tar -xvzf cc0-* -WORKDIR /home/cc0 +RUN tar -C /usr/local -xvzf cc0-* +WORKDIR /usr/local/cc0 RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0 #RUN ./a.out -RUN cp bin/cc0 /usr/bin/cc0 # Clean up WORKDIR /home diff --git a/autodriver/cc0wrap.sh b/autodriver/cc0wrap.sh new file mode 100644 index 00000000..4a14c111 --- /dev/null +++ b/autodriver/cc0wrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /usr/local/cc0/bin/cc0 $@ From 2c0f8ad1695e140cbf39b2420b3a479c450b4885 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Sun, 2 Aug 2015 17:51:47 -0400 Subject: [PATCH 4/9] autograde_wrapper.py improvements - spawn a thread that calls wait(). We are pid 1 in the container and need to collect all zombies, otherwise autodriver might get confused - Don't double fork. it's not easy to pass the full exit status of autodriver through a double fork, so use os.execvp instead of subprocess.call. This means we have to do some of the file descriptor munging directly. - Don't bother creating a temporary output file. Directly pipe autodriver's output to the real output file --- autodriver/autograde_wrapper.py | 46 +++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py index 878fdc87..158b7283 100644 --- a/autodriver/autograde_wrapper.py +++ b/autodriver/autograde_wrapper.py @@ -4,31 +4,61 @@ import os import pwd import shutil -import subprocess +import threading #print("Running "+ str(sys.argv)) +# Wait for all processes, since we are pid 1 in the container, +# terminate once the interesting process exits +class WaitLoop(object): + def __init__(self, pid=None): + self.waitfor=pid + self.status=None + def __call__(self): + try: + (np, self.status)=os.wait() + while pid is None or np != self.waitfor: + (np, self.status)=os.wait() + except OSError: + if pid: + print("Chld process {} never exited, but no more children left".format(self.waitfor)) + self.status=-1 + for f in os.listdir("mount"): src=os.path.join("mount", f) dst=os.path.join("autolab", f) shutil.copy(src, dst) autolabuser=pwd.getpwnam("autolab") +(r_p, w_p)=os.pipe() pid=os.fork() if pid == 0: + os.close(r_p) os.setgroups([]) os.setgid(autolabuser.pw_gid) os.setuid(autolabuser.pw_uid) - outfile=open("output/feedback", "w") args=["autodriver"] args.extend(sys.argv[1:]) args.append("autolab") - print("Executing "+str(args), file=outfile) - sys.exit(subprocess.call(args, stdout=outfile, stderr=outfile, close_fds=True)) -(np, status)=os.waitpid(pid, 0) + if w_p != 1: + os.dup2(w_p, 1) + if w_p != 2: + os.dup2(w_p, 2) + if w_p > 2: + os.close(w_p) + os.execvp(args[0], args) +os.close(w_p) +waiter=WaitLoop(pid) +thr=threading.Thread(target=waiter) +thr.start() +rpf=os.fdopen(r_p) +shutil.copyfileobj(rpf, open("mount/feedback", "w")) +#print("Copied output") +rpf.close() +thr.join() # if core, exit -1, else pass through code. -if status & 0xff: +if os.WIFSIGNALED(waiter.status): status=-1 else: - status>>=8; -shutil.copy("output/feedback", "mount/feedback") + status=os.WEXITSTATUS(waiter.status) +#print("Status is {}".format(status)) sys.exit(status) From 932a3d88098336967f58469ee09f4f31686c019c Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Sun, 2 Aug 2015 22:04:56 -0400 Subject: [PATCH 5/9] Update Dockerfiles master now has 2 dockerfiles, one targeting 122 with C0, and one not Apply updates (fewer RUN lines, do not fetch autodriver from github) to both of them. --- autodriver/Dockerfile_122 | 32 +++++++++++++++++++++++ autodriver/Dockerfile_ubuntu | 24 ++++++++++++++++++ vmms/Dockerfile_122 | 49 ------------------------------------ vmms/Dockerfile_ubuntu | 34 ------------------------- 4 files changed, 56 insertions(+), 83 deletions(-) create mode 100644 autodriver/Dockerfile_122 create mode 100644 autodriver/Dockerfile_ubuntu delete mode 100644 vmms/Dockerfile_122 delete mode 100644 vmms/Dockerfile_ubuntu diff --git a/autodriver/Dockerfile_122 b/autodriver/Dockerfile_122 new file mode 100644 index 00000000..51a1eaa8 --- /dev/null +++ b/autodriver/Dockerfile_122 @@ -0,0 +1,32 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +RUN apt-get update && apt-get install -y build-essential wget python + +# Install autodriver +WORKDIR /home +RUN useradd autolab && useradd autograde +RUN mkdir autolab autograde output && chown autolab:autolab autolab output && chown autograde:autograde autograde +ADD . /home/autodriver +WORKDIR /home/autodriver +RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper && cp cc0wrap.sh /usr/bin/cc0 && chmod +x /usr/bin/cc0 + +ENTRYPOINT ["/usr/bin/autograde_wrapper"] + +# Install C0 +WORKDIR /home +RUN wget http://c0.typesafety.net/dist/cc0-v0440-linux3.18.1-64bit-bin.tgz +RUN tar -C /usr/local -xvzf cc0-* +WORKDIR /usr/local/cc0 +RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0 +#RUN ./a.out + +# Clean up +WORKDIR /home +RUN apt-get remove -y wget && apt-get -y autoremove +RUN rm -rf autodriver cc0* + +# Check installation +RUN ls -l /home && which autodriver && which cc0 diff --git a/autodriver/Dockerfile_ubuntu b/autodriver/Dockerfile_ubuntu new file mode 100644 index 00000000..dbb40213 --- /dev/null +++ b/autodriver/Dockerfile_ubuntu @@ -0,0 +1,24 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +RUN apt-get update && apt-get install -y build-essential wget python + +# Install autodriver +WORKDIR /home +RUN useradd autolab && useradd autograde +RUN mkdir autolab autograde output && chown autolab:autolab autolab output && chown autograde:autograde autograde +ADD . /home/autodriver +WORKDIR /home/autodriver +RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper + +ENTRYPOINT ["/usr/bin/autograde_wrapper"] + +# Clean up +WORKDIR /home +RUN apt-get remove -y wget && apt-get -y autoremove +RUN rm -rf autodriver + +# Check installation +RUN ls -l /home && which autodriver diff --git a/vmms/Dockerfile_122 b/vmms/Dockerfile_122 deleted file mode 100644 index f021598d..00000000 --- a/vmms/Dockerfile_122 +++ /dev/null @@ -1,49 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -# Install necessary packages -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential -RUN apt-get install -y wget -RUN apt-get install -y git - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# Install C0 -WORKDIR /home -RUN wget http://c0.typesafety.net/dist/cc0-v0440-linux3.18.1-64bit-bin.tgz -RUN tar -xvzf cc0-* -WORKDIR /home/cc0 -RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0 -RUN ./a.out -RUN cp bin/cc0 /usr/bin/cc0 - -# Clean up -WORKDIR /home -RUN apt-get remove -y git -RUN apt-get remove -y wget -RUN apt-get -y autoremove -RUN rm -rf Tango/ -RUN rm -f cc0-* -RUN rm -rf cc0/ - -# Check installation -RUN ls -l /home -RUN which autodriver -RUN which cc0 \ No newline at end of file diff --git a/vmms/Dockerfile_ubuntu b/vmms/Dockerfile_ubuntu deleted file mode 100644 index e9053445..00000000 --- a/vmms/Dockerfile_ubuntu +++ /dev/null @@ -1,34 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN apt-get install -y git -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# Clean up -WORKDIR /home -RUN apt-get remove -y git -RUN apt-get -y autoremove -RUN rm -rf Tango/ - -# Check installation -RUN ls -l /home -RUN which autodriver \ No newline at end of file From fb27fcf80b5af5854ac8ca5695a1b62761172f2f Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Sun, 2 Aug 2015 22:18:16 -0400 Subject: [PATCH 6/9] Update distDocker to use entrypoint interface --- vmms/distDocker.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/vmms/distDocker.py b/vmms/distDocker.py index c5726176..b1a8498f 100644 --- a/vmms/distDocker.py +++ b/vmms/distDocker.py @@ -224,19 +224,13 @@ def runJob(self, vm, runTimeout, maxOutputFileSize): self.log.debug("Lost persistent SSH connection") return ret - autodriverCmd = 'autodriver -u %d -f %d -t %d -o %d autolab &> output/feedback' % \ + autodriverArgs = '-u %d -f %d -t %d -o %d' % \ (config.Config.VM_ULIMIT_USER_PROC, config.Config.VM_ULIMIT_FILE_SIZE, runTimeout, config.Config.MAX_OUTPUT_FILE_SIZE) - # IMPORTANT: The single and double quotes are important, since we - # are switching to the autolab user and then running - # bash commands. - setupCmd = 'cp -r mount/* autolab/; su autolab -c "%s"; \ - cp output/feedback mount/feedback' % autodriverCmd - - args = "(docker run --name %s -v %s:/home/mount %s sh -c '%s')" % \ - (instanceName, volumePath, vm.image, setupCmd) + args = "(docker run --name %s -v %s:/home/mount %s %s)" % \ + (instanceName, volumePath, vm.image, autodriverArgs) self.log.debug('Running job: %s' % args) From d3d6168a805ddd2696692c689a3b3c30a5ed8252 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Thu, 11 Feb 2016 09:56:25 -0500 Subject: [PATCH 7/9] Use correct variable name for wait result --- autodriver/autograde_wrapper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py index 158b7283..d62ac6cd 100644 --- a/autodriver/autograde_wrapper.py +++ b/autodriver/autograde_wrapper.py @@ -8,7 +8,8 @@ #print("Running "+ str(sys.argv)) # Wait for all processes, since we are pid 1 in the container, -# terminate once the interesting process exits +# exit thread (which is blocking the main thread) once the +# interesting process exits class WaitLoop(object): def __init__(self, pid=None): self.waitfor=pid @@ -16,7 +17,7 @@ def __init__(self, pid=None): def __call__(self): try: (np, self.status)=os.wait() - while pid is None or np != self.waitfor: + while np is None or np != self.waitfor: (np, self.status)=os.wait() except OSError: if pid: From 6aca17e9d44ba53f5504fb7f0384797b47d49655 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Thu, 11 Feb 2016 09:58:54 -0500 Subject: [PATCH 8/9] Move autograde_wrapper guts into a main() function This cleans up some warnings --- autodriver/autograde_wrapper.py | 82 +++++++++++++++++---------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py index d62ac6cd..5e45fdbf 100644 --- a/autodriver/autograde_wrapper.py +++ b/autodriver/autograde_wrapper.py @@ -20,46 +20,50 @@ def __call__(self): while np is None or np != self.waitfor: (np, self.status)=os.wait() except OSError: - if pid: + if np: print("Chld process {} never exited, but no more children left".format(self.waitfor)) self.status=-1 -for f in os.listdir("mount"): - src=os.path.join("mount", f) - dst=os.path.join("autolab", f) - shutil.copy(src, dst) +def main(): + for f in os.listdir("mount"): + src=os.path.join("mount", f) + dst=os.path.join("autolab", f) + shutil.copy(src, dst) -autolabuser=pwd.getpwnam("autolab") -(r_p, w_p)=os.pipe() -pid=os.fork() -if pid == 0: - os.close(r_p) - os.setgroups([]) - os.setgid(autolabuser.pw_gid) - os.setuid(autolabuser.pw_uid) - args=["autodriver"] - args.extend(sys.argv[1:]) - args.append("autolab") - if w_p != 1: - os.dup2(w_p, 1) - if w_p != 2: - os.dup2(w_p, 2) - if w_p > 2: - os.close(w_p) - os.execvp(args[0], args) -os.close(w_p) -waiter=WaitLoop(pid) -thr=threading.Thread(target=waiter) -thr.start() -rpf=os.fdopen(r_p) -shutil.copyfileobj(rpf, open("mount/feedback", "w")) -#print("Copied output") -rpf.close() -thr.join() -# if core, exit -1, else pass through code. -if os.WIFSIGNALED(waiter.status): - status=-1 -else: - status=os.WEXITSTATUS(waiter.status) -#print("Status is {}".format(status)) -sys.exit(status) + autolabuser=pwd.getpwnam("autolab") + (r_p, w_p)=os.pipe() + pid=os.fork() + if pid == 0: + os.close(r_p) + os.setgroups([]) + os.setgid(autolabuser.pw_gid) + os.setuid(autolabuser.pw_uid) + args=["autodriver"] + args.extend(sys.argv[1:]) + args.append("autolab") + if w_p != 1: + os.dup2(w_p, 1) + if w_p != 2: + os.dup2(w_p, 2) + if w_p > 2: + os.close(w_p) + os.execvp(args[0], args) + os.close(w_p) + waiter=WaitLoop(pid) + thr=threading.Thread(target=waiter) + thr.start() + rpf=os.fdopen(r_p) + shutil.copyfileobj(rpf, open("mount/feedback", "w")) + #print("Copied output") + rpf.close() + thr.join() + # if core, exit -1, else pass through code. + if os.WIFSIGNALED(waiter.status): + status=-1 + else: + status=os.WEXITSTATUS(waiter.status) + #print("Status is {}".format(status)) + sys.exit(status) + +if __name__ == '__main__': + main() From 1d72166490c6cf53d5617e4b5add91c870ffd685 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Thu, 11 Feb 2016 10:02:02 -0500 Subject: [PATCH 9/9] Fix pylint warnings in autograde_wrapper.py --- autodriver/autograde_wrapper.py | 41 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py index 5e45fdbf..ce27a822 100644 --- a/autodriver/autograde_wrapper.py +++ b/autodriver/autograde_wrapper.py @@ -12,33 +12,34 @@ # interesting process exits class WaitLoop(object): def __init__(self, pid=None): - self.waitfor=pid - self.status=None + self.waitfor = pid + self.status = None def __call__(self): try: - (np, self.status)=os.wait() - while np is None or np != self.waitfor: - (np, self.status)=os.wait() + (nextpid, self.status) = os.wait() + while nextpid is None or nextpid != self.waitfor: + (nextpid, self.status) = os.wait() except OSError: - if np: - print("Chld process {} never exited, but no more children left".format(self.waitfor)) - self.status=-1 + if nextpid: + print("Chld process {} never exited, but no more children left". + format(self.waitfor)) + self.status = -1 def main(): - for f in os.listdir("mount"): - src=os.path.join("mount", f) - dst=os.path.join("autolab", f) + for copyfile in os.listdir("mount"): + src = os.path.join("mount", copyfile) + dst = os.path.join("autolab", copyfile) shutil.copy(src, dst) - autolabuser=pwd.getpwnam("autolab") - (r_p, w_p)=os.pipe() - pid=os.fork() + autolabuser = pwd.getpwnam("autolab") + (r_p, w_p) = os.pipe() + pid = os.fork() if pid == 0: os.close(r_p) os.setgroups([]) os.setgid(autolabuser.pw_gid) os.setuid(autolabuser.pw_uid) - args=["autodriver"] + args = ["autodriver"] args.extend(sys.argv[1:]) args.append("autolab") if w_p != 1: @@ -49,19 +50,19 @@ def main(): os.close(w_p) os.execvp(args[0], args) os.close(w_p) - waiter=WaitLoop(pid) - thr=threading.Thread(target=waiter) + waiter = WaitLoop(pid) + thr = threading.Thread(target=waiter) thr.start() - rpf=os.fdopen(r_p) + rpf = os.fdopen(r_p) shutil.copyfileobj(rpf, open("mount/feedback", "w")) #print("Copied output") rpf.close() thr.join() # if core, exit -1, else pass through code. if os.WIFSIGNALED(waiter.status): - status=-1 + status = -1 else: - status=os.WEXITSTATUS(waiter.status) + status = os.WEXITSTATUS(waiter.status) #print("Status is {}".format(status)) sys.exit(status)