projects
/
gruntmaster-daemon.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Prevent extraneous empty lines in compiler output
[gruntmaster-daemon.git]
/
gruntmaster-exec
diff --git
a/gruntmaster-exec
b/gruntmaster-exec
index dec8be38835c02ed0913078584cce3c1aee16b03..46ac491a674ebb1eb3672783e913d1f08e6d8a30 100755
(executable)
--- a/
gruntmaster-exec
+++ b/
gruntmaster-exec
@@
-18,16
+18,20
@@
use constant +{
DIED => 5,
REJ => 10,
};
DIED => 5,
REJ => 10,
};
+# These constants are changed by ex/makevm
+use constant USER => 65534;
+use constant GROUP => 65534;
-use BSD::Resource qw/setrlimit RLIMIT_AS RLIMIT_FSIZE/;
+use BSD::Resource qw/setrlimit RLIMIT_AS RLIMIT_FSIZE
RLIMIT_NPROC
/;
use IPC::Signal qw/sig_name sig_num/;
use sigtrap qw/XFSZ/;
use Getopt::Long;
use POSIX qw//;
use IPC::Signal qw/sig_name sig_num/;
use sigtrap qw/XFSZ/;
use Getopt::Long;
use POSIX qw//;
+use Text::ParseWords qw/shellwords/;
use Time::HiRes qw/alarm/;
use Time::HiRes qw/alarm/;
-my (@fds, $timeout, $mlimit, $olimit);
+my (@fds, $timeout, $mlimit, $olimit
, $nobody
);
my $close = 1;
GetOptions(
my $close = 1;
GetOptions(
@@
-36,15
+40,32
@@
GetOptions(
"mlimit=i" => \$mlimit,
"olimit=i" => \$olimit,
"close!" => \$close,
"mlimit=i" => \$mlimit,
"olimit=i" => \$olimit,
"close!" => \$close,
+ "nobody!" => \$nobody,
);
);
+my $killuser = $ENV{GRUNTMASTER_KILL_USER};
+my @sudo;
+@sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $nobody;
+undef $mlimit if @sudo; # sudo wants a lot of address space
+
my $ret = fork // die 'Cannot fork';
if ($ret) {
my $tle;
my $ret = fork // die 'Cannot fork';
if ($ret) {
my $tle;
- local $SIG{ALRM} = sub { kill KILL => $ret; $tle = 1};
+ local $SIG{ALRM} = sub {
+ if ($killuser) {
+ system @sudo, 'pkill', '-KILL', '-u', $killuser;
+ } else {
+ kill KILL => $ret
+ }
+ $tle = 1
+ };
alarm ($timeout || 5);
waitpid $ret, 0;
alarm 0;
alarm ($timeout || 5);
waitpid $ret, 0;
alarm 0;
+ if (@sudo) {
+ $? = $? >> 8;
+ $? = $? < 128 ? ($? << 8) : $? - 128;
+ }
my $sig = $? & 127;
my $signame = sig_name $sig;
exit !say TLE, "\nTime Limit Exceeded" if $tle;
my $sig = $? & 127;
my $signame = sig_name $sig;
exit !say TLE, "\nTime Limit Exceeded" if $tle;
@@
-66,11
+87,16
@@
if ($ret) {
POSIX::close $oldfd or die $!;
}
}
POSIX::close $oldfd or die $!;
}
}
+ my $nproc = $killuser ? 15 : 1;
+ my $debug = $ENV{TEST_VERBOSE};
%ENV = (ONLINE_JUDGE => 1, PATH => $ENV{PATH}, HOME => $ENV{HOME});
setrlimit RLIMIT_AS, $mlimit, $mlimit or die $! if $mlimit;
setrlimit RLIMIT_FSIZE, $olimit, $olimit or die $! if $olimit;
%ENV = (ONLINE_JUDGE => 1, PATH => $ENV{PATH}, HOME => $ENV{HOME});
setrlimit RLIMIT_AS, $mlimit, $mlimit or die $! if $mlimit;
setrlimit RLIMIT_FSIZE, $olimit, $olimit or die $! if $olimit;
- POSIX::setgid 65534; # Set group id to nogroup
- POSIX::setuid 65534; # Set user id to nobody
+ setrlimit RLIMIT_NPROC, $nproc, $nproc or die $! if $nobody;
+ POSIX::setgid $nobody ? 65534 : USER;
+ POSIX::setuid $nobody ? 65534 : GROUP;
+ unshift @ARGV, @sudo;
+ say STDERR "Executing: ", join ' ', map { "'$_'" } @ARGV if $debug;
exec @ARGV;
}
exec @ARGV;
}
This page took
0.009924 seconds
and
4
git commands to generate.