]> iEval git - gruntmaster-daemon.git/blame - gruntmaster-exec
Only update problem statuses for non-private problems
[gruntmaster-daemon.git] / gruntmaster-exec
CommitLineData
c40a2dd0 1#!/usr/bin/perl
da905f9e
MG
2use v5.14;
3use strict;
c40a2dd0 4use warnings;
da905f9e 5
c40a2dd0
MG
6use constant +{
7 # Accepted
8 AC => 0,
da905f9e 9
c40a2dd0
MG
10 # Internal server error
11 ERR => -1,
da905f9e 12
c40a2dd0
MG
13 # All other errors
14 WA => 1,
15 NZX => 2,
16 TLE => 3,
17 OLE => 4,
18 DIED => 5,
19 REJ => 10,
20};
50cdf3cb 21
c40a2dd0
MG
22use BSD::Resource qw/setrlimit RLIMIT_AS RLIMIT_FSIZE/;
23use IPC::Signal qw/sig_name sig_num/;
24use sigtrap qw/XFSZ/;
69c25408 25
c40a2dd0
MG
26use Getopt::Long;
27use POSIX qw//;
28use Time::HiRes qw/alarm/;
29
30my (@fds, $timeout, $mlimit, $olimit);
1fe52cde
MG
31my $close = 1;
32
c40a2dd0
MG
33GetOptions(
34 "fd=s" => \@fds,
35 "timeout=f" => \$timeout,
36 "mlimit=i" => \$mlimit,
37 "olimit=i" => \$olimit,
1fe52cde 38 "close!" => \$close,
c40a2dd0
MG
39);
40
41my $ret = fork // die 'Cannot fork';
42if ($ret) {
43 my $tle;
44 local $SIG{ALRM} = sub { kill KILL => $ret; $tle = 1};
45 alarm ($timeout || 5);
46 waitpid $ret, 0;
47 alarm 0;
48 my $sig = $? & 127;
49 my $signame = sig_name $sig;
50 exit !say TLE, "\nTime Limit Exceeded" if $tle;
51 exit !say OLE, "\nOutput Limit Exceeded" if $sig && $signame eq 'XFSZ';
52 exit !say DIED, "\nCrash (SIG$signame)" if $sig && $signame ne 'PIPE';
53 exit !say NZX, "\nNon-zero exit status: " . ($? >> 8) if $? >> 8;
54 exit !say AC, "\nAll OK";
55} else {
56 $^F = 50;
1fe52cde
MG
57 if ($close) {
58 POSIX::close $_ for 0 .. $^F;
59 }
c40a2dd0
MG
60 for my $fdstring (@fds) {
61 my ($fd, $file) = split ' ', $fdstring, 2;
62 open my $fh, $file or die $!;
63 my $oldfd = fileno $fh;
64 if ($oldfd != $fd) {
65 POSIX::dup2 $oldfd, $fd or die $!;
66 POSIX::close $oldfd or die $!;
67 }
68 }
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;
7be8c37d
MG
72 POSIX::setgid 65534; # Set group id to nogroup
73 POSIX::setuid 65534; # Set user id to nobody
c40a2dd0
MG
74 exec @ARGV;
75}
76
771;
69c25408
MG
78__END__
79
80=encoding utf-8
81
82=head1 NAME
83
84gruntmaster-exec - Gruntmaster 6000 executor
85
86=head1 SYNOPSIS
87
88 gruntmaster-exec 20000000 111 echo 'Hello, world!'
89
90=head1 DESCRIPTION
91
92gruntmaster-exec is the script used by gruntmasterd to run programs.
93
94The 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.
95
96gruntmaster-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.
97
98=head1 AUTHOR
99
100Marius Gavrilescu E<lt>marius@ieval.roE<gt>
101
102=head1 COPYRIGHT AND LICENSE
103
104Copyright (C) 2014 by Marius Gavrilescu
105
106This program is free software: you can redistribute it and/or modify
107it under the terms of the GNU Affero General Public License as published by
108the Free Software Foundation, either version 3 of the License, or
109(at your option) any later version.
This page took 0.040857 seconds and 4 git commands to generate.