]>
iEval git - gruntmaster-daemon.git/blob - gruntmaster-exec
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' ;
50 local $SIG { ALRM
} = sub {
52 system @sudo , 'pkill' , '-KILL' , '-u' , $killuser ;
58 alarm ( $timeout || 10 );
63 $ ?
= $ ?
< 128 || $ ?
> 128 + 32 ?
($ ?
<< 8 ) : $ ?
- 128 ;
66 my $signame = sig_name
$sig ;
67 exit ! say TLE
, " \n Time Limit Exceeded" if $tle ;
68 exit ! say OLE
, " \n Output Limit Exceeded" if $sig && $signame eq 'XFSZ' ;
69 exit ! say DIED
, " \n Crash (SIG $signame )" if $sig && $signame ne 'PIPE' ;
70 exit ! say NZX
, " \n Non-zero exit status: " . ($ ?
>> 8 ) if $ ?
>> 8 ;
71 exit ! say AC
, " \n All OK" ;
74 POSIX
:: close 2 unless $keep_stderr ;
75 POSIX
:: close $_ for 0 , 1 , 3 .. $^ F
;
76 for my $fdstring ( @fds ) {
77 my ( $fd , $file ) = split ' ' , $fdstring , 2 ;
78 open my $fh , $file or die $!;
79 my $oldfd = fileno $fh ;
81 POSIX
:: dup2
$oldfd , $fd or die $!;
82 POSIX
:: close $oldfd or die $!;
85 my $nproc = $killuser ?
15 : 1 ;
86 my $debug = $ENV { TEST_VERBOSE
};
87 %ENV = ( ONLINE_JUDGE
=> 1 , PATH
=> $ENV { PATH
}, HOME
=> $ENV { HOME
});
88 setrlimit RLIMIT_AS
, $mlimit , $mlimit or die $! if $mlimit ;
89 setrlimit RLIMIT_FSIZE
, $olimit , $olimit or die $! if $olimit ;
90 setrlimit RLIMIT_NPROC
, $nproc , $nproc or die $! if $sudo ;
92 say STDERR
"Executing: " , join ' ' , map { "' $_ '" } @ARGV if $debug ;
103 gruntmaster-exec - Gruntmaster 6000 executor
107 gruntmaster-exec 20000000 111 echo 'Hello, world!'
111 gruntmaster-exec is the script used by gruntmasterd to run programs.
113 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.
115 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.
119 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
121 =head1 COPYRIGHT AND LICENSE
123 Copyright (C) 2014 by Marius Gavrilescu
125 This program is free software: you can redistribute it and/or modify
126 it under the terms of the GNU Affero General Public License as published by
127 the Free Software Foundation, either version 3 of the License, or
128 (at your option) any later version.
This page took 0.0556 seconds and 4 git commands to generate.