10 # Internal server error
22 use BSD
::Resource qw
/setrlimit RLIMIT_AS RLIMIT_FSIZE RLIMIT_NPROC/;
23 use IPC
::Signal qw
/sig_name sig_num/;
28 use Text
::ParseWords qw
/shellwords/;
29 use Time
::HiRes qw
/alarm/;
31 my (@fds, $timeout, $mlimit, $olimit, $nobody);
36 "timeout=f" => \
$timeout,
37 "mlimit=i" => \
$mlimit,
38 "olimit=i" => \
$olimit,
40 "nobody!" => \
$nobody,
43 my $killuser = $ENV{GRUNTMASTER_KILL_USER
};
45 @sudo = (shellwords
($ENV{GRUNTMASTER_SUDO
}), '--') if $ENV{GRUNTMASTER_SUDO
} && $nobody;
46 undef $mlimit if @sudo; # sudo wants a lot of address space
48 my $ret = fork // die 'Cannot fork';
51 local $SIG{ALRM
} = sub {
53 system @sudo, 'pkill', '-KILL', '-u', $killuser;
59 alarm ($timeout || 10);
64 $?
= $?
< 128 || $?
> 128+32 ?
($?
<< 8) : $?
- 128;
67 my $signame = sig_name
$sig;
68 exit !say TLE
, "\nTime Limit Exceeded" if $tle;
69 exit !say OLE
, "\nOutput Limit Exceeded" if $sig && $signame eq 'XFSZ';
70 exit !say DIED
, "\nCrash (SIG$signame)" if $sig && $signame ne 'PIPE';
71 exit !say NZX
, "\nNon-zero exit status: " . ($?
>> 8) if $?
>> 8;
72 exit !say AC
, "\nAll OK";
76 POSIX
::close $_ for 0 .. $^F
;
78 for my $fdstring (@fds) {
79 my ($fd, $file) = split ' ', $fdstring, 2;
80 open my $fh, $file or die $!;
81 my $oldfd = fileno $fh;
83 POSIX
::dup2
$oldfd, $fd or die $!;
84 POSIX
::close $oldfd or die $!;
87 my $nproc = $killuser ?
15 : 1;
88 my $debug = $ENV{TEST_VERBOSE
};
89 %ENV = (ONLINE_JUDGE
=> 1, PATH
=> $ENV{PATH
}, HOME
=> $ENV{HOME
});
90 setrlimit RLIMIT_AS
, $mlimit, $mlimit or die $! if $mlimit;
91 setrlimit RLIMIT_FSIZE
, $olimit, $olimit or die $! if $olimit;
92 setrlimit RLIMIT_NPROC
, $nproc, $nproc or die $! if $nobody;
94 say STDERR
"Executing: ", join ' ', map { "'$_'" } @ARGV if $debug;
105 gruntmaster-exec - Gruntmaster 6000 executor
109 gruntmaster-exec 20000000 111 echo 'Hello, world!'
113 gruntmaster-exec is the script used by gruntmasterd to run programs.
115 The first argument is the address space limit (in bytes), the second argument is the output limit (also in bytes). The rest of the arguments are the command that should be run and its arguments.
117 gruntmaster-exec sets the resource limits, cleans the environment (except for PATH and HOME), adds the ONLINE_JUDGE environment variable with value 1, and finally C<exec>s the given command.
121 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
123 =head1 COPYRIGHT AND LICENSE
125 Copyright (C) 2014 by Marius Gavrilescu
127 This program is free software: you can redistribute it and/or modify
128 it under the terms of the GNU Affero General Public License as published by
129 the Free Software Foundation, either version 3 of the License, or
130 (at your option) any later version.
This page took 0.032624 seconds and 5 git commands to generate.