Permalink
Browse files

Added support for custom run_cmd

  • Loading branch information...
ironcamel committed Mar 28, 2013
1 parent 0da2073 commit 46a89ade21a6b6c0907523c77bcf87964da8b294
Showing with 21 additions and 14 deletions.
  1. +1 −1 bin/app.pl
  2. +19 −12 bin/codejail.pl
  3. +1 −1 config.example.yml
View
@@ -3,7 +3,7 @@
use Dancer::Plugin::Stomp qw(stomp_send);
post '/' => sub {
- stomp_send { destination => '/queue/codejail', body => request->body };
+ stomp_send { destination => config->{queue}, body => request->body };
status 202;
};
View
@@ -73,6 +73,9 @@ sub process_msg {
sub run_code {
my ($data) = @_;
+ sys("rm -rf $jail/home/sandbox/runs/*");
+ #sys("tar -xf $jail.tar -C /var") or die "Could not build chroot jail: $!";
+
my $pid = open my $child_process, '-|';
if (!$pid) { # child process starts here
try {
@@ -98,22 +101,20 @@ sub run_code {
}
# Lets clean up after ourselves.
- #sys("rm -rf $jail");
+ #sys("rm -rf $jail/home/sandbox/runs/*");
return $result;
}
sub run_in_chroot {
my ($data) = @_;
- my $lang = $data->{language};
- my $code = $data->{code};
- my $file_name = $data->{file_name};
- my $problem = $data->{problem};
- my $input = $problem->{input};
-
- debug("Setting up chroot ...");
- #sys("rm -rf $jail");
- #sys("tar -xf $jail.tar -C /var") or die "Could not build chroot jail: $!";
+ my $lang = $data->{language};
+ my $code = $data->{code};
+ my $file_name = $data->{file_name} // 'foo';
+ my $problem = $data->{problem};
+ my $compile_cmd = $data->{compile_cmd};
+ my $run_cmd = $data->{run_cmd};
+ my $input = $problem->{input};
chdir $jail or die "Failed to chdir into $jail: $!";
@@ -189,13 +190,19 @@ sub run_in_chroot {
@cmd =($lang, $path);
}
default {
- die "Language [$lang] is not supported yet\n";
+ open my $f, '>', $file_name;
+ print $f $code;
+ if ($compile_cmd) {
+ debug("compiling: ", $compile_cmd);
+ run $compile_cmd;
+ }
+ @cmd = @$run_cmd;
}
}
debug("going to run: @cmd");
try {
- run(\@cmd, \$input, \$out, \$err, timeout(3));
+ run \@cmd, \$input, \$out, \$err, timeout(3);
} catch {
print "Took too long $_\n";
};
View
@@ -1,6 +1,6 @@
charset: UTF-8
-#queue: /queue/codejail
+queue: '/queue/codejail'
jail_path: '/var/arch-chroot'
plugins:
Stomp:

0 comments on commit 46a89ad

Please sign in to comment.