]>
iEval git - gruntmaster-daemon.git/blob - gruntmaster-exec
e7d7363d4c44308c0622a32e4ecbb7565682c88c
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/ ;
26 use IPC
:: Signal qw
/sig_name sig_num/ ;
31 use Time
:: HiRes qw
/alarm/ ;
33 my ( @fds , $timeout , $mlimit , $olimit , $nobody );
38 "timeout=f" => \
$timeout ,
39 "mlimit=i" => \
$mlimit ,
40 "olimit=i" => \
$olimit ,
42 "nobody!" => \
$nobody ,
45 my $ret = fork // die 'Cannot fork' ;
48 local $SIG { ALRM
} = sub { kill KILL
=> $ret ; $tle = 1 };
49 alarm ( $timeout || 5 );
53 my $signame = sig_name
$sig ;
54 exit ! say TLE
, " \n Time Limit Exceeded" if $tle ;
55 exit ! say OLE
, " \n Output Limit Exceeded" if $sig && $signame eq 'XFSZ' ;
56 exit ! say DIED
, " \n Crash (SIG $signame )" if $sig && $signame ne 'PIPE' ;
57 exit ! say NZX
, " \n Non-zero exit status: " . ($ ?
>> 8 ) if $ ?
>> 8 ;
58 exit ! say AC
, " \n All OK" ;
62 POSIX
:: close $_ for 0 .. $^ F
;
64 for my $fdstring ( @fds ) {
65 my ( $fd , $file ) = split ' ' , $fdstring , 2 ;
66 open my $fh , $file or die $!;
67 my $oldfd = fileno $fh ;
69 POSIX
:: dup2
$oldfd , $fd or die $!;
70 POSIX
:: close $oldfd or die $!;
73 %ENV = ( ONLINE_JUDGE
=> 1 , PATH
=> $ENV { PATH
}, HOME
=> $ENV { HOME
});
74 setrlimit RLIMIT_AS
, $mlimit , $mlimit or die $! if $mlimit ;
75 setrlimit RLIMIT_FSIZE
, $olimit , $olimit or die $! if $olimit ;
76 POSIX
:: setgid
$nobody ?
65534 : USER
;
77 POSIX
:: setuid
$nobody ?
65534 : GROUP
;
88 gruntmaster-exec - Gruntmaster 6000 executor
92 gruntmaster-exec 20000000 111 echo 'Hello, world!'
96 gruntmaster-exec is the script used by gruntmasterd to run programs.
98 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.
100 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.
104 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
106 =head1 COPYRIGHT AND LICENSE
108 Copyright (C) 2014 by Marius Gavrilescu
110 This program is free software: you can redistribute it and/or modify
111 it under the terms of the GNU Affero General Public License as published by
112 the Free Software Foundation, either version 3 of the License, or
113 (at your option) any later version.
This page took 0.049536 seconds and 4 git commands to generate.