]>
iEval git - gruntmaster-daemon.git/blob - gruntmaster-exec
10 # Internal server error
22 use BSD
:: Resource qw
/setrlimit RLIMIT_AS RLIMIT_FSIZE/ ;
23 use IPC
:: Signal qw
/sig_name sig_num/ ;
28 use Time
:: HiRes qw
/alarm/ ;
30 my ( @fds , $timeout , $mlimit , $olimit );
35 "timeout=f" => \
$timeout ,
36 "mlimit=i" => \
$mlimit ,
37 "olimit=i" => \
$olimit ,
41 my $ret = fork // die 'Cannot fork' ;
44 local $SIG { ALRM
} = sub { kill KILL
=> $ret ; $tle = 1 };
45 alarm ( $timeout || 5 );
49 my $signame = sig_name
$sig ;
50 exit ! say TLE
, " \n Time Limit Exceeded" if $tle ;
51 exit ! say OLE
, " \n Output Limit Exceeded" if $sig && $signame eq 'XFSZ' ;
52 exit ! say DIED
, " \n Crash (SIG $signame )" if $sig && $signame ne 'PIPE' ;
53 exit ! say NZX
, " \n Non-zero exit status: " . ($ ?
>> 8 ) if $ ?
>> 8 ;
54 exit ! say AC
, " \n All OK" ;
58 POSIX
:: close $_ for 0 .. $^ F
;
60 for my $fdstring ( @fds ) {
61 my ( $fd , $file ) = split ' ' , $fdstring , 2 ;
62 open my $fh , $file or die $!;
63 my $oldfd = fileno $fh ;
65 POSIX
:: dup2
$oldfd , $fd or die $!;
66 POSIX
:: close $oldfd or die $!;
69 %ENV = ( ONLINE_JUDGE
=> 1 , PATH
=> $ENV { PATH
}, HOME
=> $ENV { HOME
});
70 setrlimit RLIMIT_AS
, $mlimit , $mlimit or die $! if $mlimit ;
71 setrlimit RLIMIT_FSIZE
, $olimit , $olimit or die $! if $olimit ;
72 POSIX
:: setgid
65534 ; # Set group id to nogroup
73 POSIX
:: setuid
65534 ; # Set user id to nobody
84 gruntmaster-exec - Gruntmaster 6000 executor
88 gruntmaster-exec 20000000 111 echo 'Hello, world!'
92 gruntmaster-exec is the script used by gruntmasterd to run programs.
94 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.
96 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.
100 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
102 =head1 COPYRIGHT AND LICENSE
104 Copyright (C) 2014 by Marius Gavrilescu
106 This program is free software: you can redistribute it and/or modify
107 it under the terms of the GNU Affero General Public License as published by
108 the Free Software Foundation, either version 3 of the License, or
109 (at your option) any later version.
This page took 0.050472 seconds and 4 git commands to generate.