X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=gruntmaster-exec;h=5235e8e5ed3430fa06b37a73a8bc5304c78d54ae;hp=9590b4e34173feaa8198bfa13e84e424d810bea6;hb=cd0623f030026cc4a5c2c03d4464bb2d3cb75ca8;hpb=74ab88697ef110b659d15e266649f162bc1c6103 diff --git a/gruntmaster-exec b/gruntmaster-exec index 9590b4e..5235e8e 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,21 +28,20 @@ use POSIX qw//; use Text::ParseWords qw/shellwords/; use Time::HiRes qw/alarm/; -my (@fds, $timeout, $mlimit, $olimit, $nobody); -my $close = 1; +my (@fds, $timeout, $mlimit, $olimit, $sudo, $keep_stderr); GetOptions( - "fd=s" => \@fds, - "timeout=f" => \$timeout, - "mlimit=i" => \$mlimit, - "olimit=i" => \$olimit, - "close!" => \$close, - "nobody!" => \$nobody, + "fd=s" => \@fds, + "timeout=f" => \$timeout, + "mlimit=i" => \$mlimit, + "olimit=i" => \$olimit, + "keep-stderr!" => \$keep_stderr, + "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,7 +55,7 @@ if ($ret) { } $tle = 1 }; - alarm ($timeout || 5); + alarm ($timeout || 10); waitpid $ret, 0; alarm 0; if (@sudo) { @@ -75,9 +71,8 @@ if ($ret) { exit !say AC, "\nAll OK"; } else { $^F = 50; - if ($close) { - POSIX::close $_ for 0 .. $^F; - } + POSIX::close 2 unless $keep_stderr; + POSIX::close $_ for 0, 1, 3 .. $^F; for my $fdstring (@fds) { my ($fd, $file) = split ' ', $fdstring, 2; open my $fh, $file or die $!; @@ -92,9 +87,10 @@ if ($ret) { %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; + open my $adj, '>', '/proc/self/oom_score_adj'; + print $adj 900; + close $adj; unshift @ARGV, @sudo; say STDERR "Executing: ", join ' ', map { "'$_'" } @ARGV if $debug; exec @ARGV;