fd79d8f316c322c9008f14bbe98b402772011c77
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, $sudo, $keep_stderr);
35 "timeout=f" => \
$timeout,
36 "mlimit=i" => \
$mlimit,
37 "olimit=i" => \
$olimit,
38 "keep-stderr!" => \
$keep_stderr,
42 my $killuser = $ENV{GRUNTMASTER_KILL_USER
};
44 @sudo = (shellwords
($ENV{GRUNTMASTER_SUDO
}), '--') if $ENV{GRUNTMASTER_SUDO
} && $sudo;
45 undef $mlimit if @sudo; # sudo wants a lot of address space
47 my $ret = fork // die 'Cannot fork';
49 my ($tle, $child_ready);
50 local $SIG{USR1
} = sub { $child_ready = 1 };
51 sleep 3; # Wait for ready signal (SIGUSR1)
52 unless ($child_ready) {
54 exit !say ERR
, "\nNo response from gruntmaster-exec child";
56 local $SIG{ALRM
} = sub {
58 system @sudo, 'pkill', '-KILL', '-u', $killuser;
64 alarm ($timeout || 10);
69 $?
= $?
< 128 || $?
> 128+32 ?
($?
<< 8) : $?
- 128;
72 my $signame = sig_name
$sig;
73 exit !say TLE
, "\nTime Limit Exceeded" if $tle;
74 exit !say OLE
, "\nOutput Limit Exceeded" if $sig && $signame eq 'XFSZ';
75 exit !say DIED
, "\nCrash (SIG$signame)" if $sig && ($signame ne 'PIPE' || $ARGV[0] !~ /prog/);
76 exit !say NZX
, "\nNon-zero exit status: " . ($?
>> 8) if $?
>> 8;
77 exit !say AC
, "\nAll OK";
80 POSIX
::close 2 unless $keep_stderr;
81 POSIX
::close $_ for 0, 1, 3 .. $^F
;
82 for my $fdstring (@fds) {
83 my ($fd, $file) = split ' ', $fdstring, 2;
84 open my $fh, $file or die $!;
85 my $oldfd = fileno $fh;
87 POSIX
::dup2
$oldfd, $fd or die $!;
88 POSIX
::close $oldfd or die $!;
91 my $nproc = $killuser ?
15 : 1;
92 my $debug = $ENV{TEST_VERBOSE
};
93 %ENV = (ONLINE_JUDGE
=> 1, PATH
=> $ENV{PATH
}, HOME
=> $ENV{HOME
});
94 setrlimit RLIMIT_AS
, $mlimit, $mlimit or die $! if $mlimit;
95 setrlimit RLIMIT_FSIZE
, $olimit, $olimit or die $! if $olimit;
96 setrlimit RLIMIT_NPROC
, $nproc, $nproc or die $! if $sudo;
97 open my $adj, '>', '/proc/self/oom_score_adj';
100 unshift @ARGV, @sudo;
101 kill USR1
=> getppid; # Tell parent process that we're ready
102 say STDERR
"Executing: ", join ' ', map { "'$_'" } @ARGV if $debug;
113 gruntmaster-exec - Gruntmaster 6000 executor
117 gruntmaster-exec 20000000 111 echo 'Hello, world!'
121 gruntmaster-exec is the script used by gruntmasterd to run programs.
123 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.
125 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.
129 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
131 =head1 COPYRIGHT AND LICENSE
133 Copyright (C) 2014 by Marius Gavrilescu
135 This program is free software: you can redistribute it and/or modify
136 it under the terms of the GNU Affero General Public License as published by
137 the Free Software Foundation, either version 3 of the License, or
138 (at your option) any later version.
This page took 0.031612 seconds and 3 git commands to generate.