]>
iEval git - gruntmaster-daemon.git/blob - gruntmaster-exec
10 # Internal server error
21 # These constants are changed by ex/makevm
22 use constant USER
=> 65534 ;
23 use constant GROUP
=> 65534 ;
25 use BSD
:: Resource qw
/setrlimit RLIMIT_AS RLIMIT_FSIZE RLIMIT_NPROC/ ;
26 use IPC
:: Signal qw
/sig_name sig_num/ ;
31 use Text
:: ParseWords qw
/shellwords/ ;
32 use Time
:: HiRes qw
/alarm/ ;
34 my ( @fds , $timeout , $mlimit , $olimit , $nobody );
39 "timeout=f" => \
$timeout ,
40 "mlimit=i" => \
$mlimit ,
41 "olimit=i" => \
$olimit ,
43 "nobody!" => \
$nobody ,
46 my $killuser = $ENV { GRUNTMASTER_KILL_USER
};
48 @sudo = ( shellwords
( $ENV { GRUNTMASTER_SUDO
}), '--' ) if $ENV { GRUNTMASTER_SUDO
} && $nobody ;
49 undef $mlimit if @sudo ; # sudo wants a lot of address space
51 my $ret = fork // die 'Cannot fork' ;
54 local $SIG { ALRM
} = sub {
56 system @sudo , 'pkill' , '-KILL' , '-u' , $killuser ;
62 alarm ( $timeout || 10 );
67 $ ?
= $ ?
< 128 || $ ?
> 128 + 32 ?
($ ?
<< 8 ) : $ ?
- 128 ;
70 my $signame = sig_name
$sig ;
71 exit ! say TLE
, " \n Time Limit Exceeded" if $tle ;
72 exit ! say OLE
, " \n Output Limit Exceeded" if $sig && $signame eq 'XFSZ' ;
73 exit ! say DIED
, " \n Crash (SIG $signame )" if $sig && $signame ne 'PIPE' ;
74 exit ! say NZX
, " \n Non-zero exit status: " . ($ ?
>> 8 ) if $ ?
>> 8 ;
75 exit ! say AC
, " \n All OK" ;
79 POSIX
:: close $_ for 0 .. $^ F
;
81 for my $fdstring ( @fds ) {
82 my ( $fd , $file ) = split ' ' , $fdstring , 2 ;
83 open my $fh , $file or die $!;
84 my $oldfd = fileno $fh ;
86 POSIX
:: dup2
$oldfd , $fd or die $!;
87 POSIX
:: close $oldfd or die $!;
90 my $nproc = $killuser ?
15 : 1 ;
91 my $debug = $ENV { TEST_VERBOSE
};
92 %ENV = ( ONLINE_JUDGE
=> 1 , PATH
=> $ENV { PATH
}, HOME
=> $ENV { HOME
});
93 setrlimit RLIMIT_AS
, $mlimit , $mlimit or die $! if $mlimit ;
94 setrlimit RLIMIT_FSIZE
, $olimit , $olimit or die $! if $olimit ;
95 setrlimit RLIMIT_NPROC
, $nproc , $nproc or die $! if $nobody ;
96 POSIX
:: setgid
$nobody ?
65534 : USER
;
97 POSIX
:: setuid
$nobody ?
65534 : GROUP
;
99 say STDERR
"Executing: " , join ' ' , map { "' $_ '" } @ARGV if $debug ;
110 gruntmaster-exec - Gruntmaster 6000 executor
114 gruntmaster-exec 20000000 111 echo 'Hello, world!'
118 gruntmaster-exec is the script used by gruntmasterd to run programs.
120 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.
122 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.
126 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
128 =head1 COPYRIGHT AND LICENSE
130 Copyright (C) 2014 by Marius Gavrilescu
132 This program is free software: you can redistribute it and/or modify
133 it under the terms of the GNU Affero General Public License as published by
134 the Free Software Foundation, either version 3 of the License, or
135 (at your option) any later version.
This page took 0.051154 seconds and 5 git commands to generate.