X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=gruntmaster-exec;h=0a2c50c204c12477cd93d574353fe3a7bdeb80bd;hp=bcde8d721321899e0f65cf317ecf8d3d697f4a7e;hb=b4ac22ff03c95b0a2da0131b2fb3134b27379570;hpb=16de3659fc10d654c8b8c9e660393c1f25eb85d0 diff --git a/gruntmaster-exec b/gruntmaster-exec index bcde8d7..0a2c50c 100755 --- a/gruntmaster-exec +++ b/gruntmaster-exec @@ -18,9 +18,6 @@ use constant +{ 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 RLIMIT_NPROC/; use IPC::Signal qw/sig_name sig_num/; @@ -31,7 +28,7 @@ use POSIX qw//; use Text::ParseWords qw/shellwords/; use Time::HiRes qw/alarm/; -my (@fds, $timeout, $mlimit, $olimit, $nobody); +my (@fds, $timeout, $mlimit, $olimit, $sudo); my $close = 1; GetOptions( @@ -40,12 +37,12 @@ GetOptions( "mlimit=i" => \$mlimit, "olimit=i" => \$olimit, "close!" => \$close, - "nobody!" => \$nobody, + "sudo!" => \$sudo, ); my $killuser = $ENV{GRUNTMASTER_KILL_USER}; my @sudo; -@sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $nobody; +@sudo = (shellwords ($ENV{GRUNTMASTER_SUDO}), '--') if $ENV{GRUNTMASTER_SUDO} && $sudo; undef $mlimit if @sudo; # sudo wants a lot of address space my $ret = fork // die 'Cannot fork'; @@ -59,12 +56,12 @@ if ($ret) { } $tle = 1 }; - alarm ($timeout || 5); + alarm ($timeout || 10); waitpid $ret, 0; alarm 0; if (@sudo) { $? = $? >> 8; - $? = $? < 128 ? ($? << 8) : $? - 128; + $? = $? < 128 || $? > 128+32 ? ($? << 8) : $? - 128; } my $sig = $? & 127; my $signame = sig_name $sig; @@ -87,14 +84,12 @@ if ($ret) { POSIX::close $oldfd or die $!; } } - my $nproc = $killuser ? 5 : 1; + 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; - setrlimit RLIMIT_NPROC, $nproc, $nproc or die $! if $nobody; - POSIX::setgid $nobody ? 65534 : USER; - POSIX::setuid $nobody ? 65534 : GROUP; + setrlimit RLIMIT_NPROC, $nproc, $nproc or die $! if $sudo; unshift @ARGV, @sudo; say STDERR "Executing: ", join ' ', map { "'$_'" } @ARGV if $debug; exec @ARGV;