X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=gruntmaster-exec;h=e7d7363d4c44308c0622a32e4ecbb7565682c88c;hp=a4ae94d4ce0335575dd4dcfa50b7a208078a1a69;hb=4e08f696f0c0f2419809e5d4b66882fce57bb2f2;hpb=7be8c37d42b6782bc5d94ea4e52dd1261ce6e3ae diff --git a/gruntmaster-exec b/gruntmaster-exec index a4ae94d..e7d7363 100755 --- a/gruntmaster-exec +++ b/gruntmaster-exec @@ -18,6 +18,9 @@ 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/; use IPC::Signal qw/sig_name sig_num/; @@ -27,12 +30,16 @@ use Getopt::Long; use POSIX qw//; use Time::HiRes qw/alarm/; -my (@fds, $timeout, $mlimit, $olimit); +my (@fds, $timeout, $mlimit, $olimit, $nobody); +my $close = 1; + GetOptions( "fd=s" => \@fds, "timeout=f" => \$timeout, "mlimit=i" => \$mlimit, "olimit=i" => \$olimit, + "close!" => \$close, + "nobody!" => \$nobody, ); my $ret = fork // die 'Cannot fork'; @@ -51,7 +58,9 @@ if ($ret) { exit !say AC, "\nAll OK"; } else { $^F = 50; - POSIX::close $_ for 0 .. $^F; + if ($close) { + POSIX::close $_ for 0 .. $^F; + } for my $fdstring (@fds) { my ($fd, $file) = split ' ', $fdstring, 2; open my $fh, $file or die $!; @@ -64,8 +73,8 @@ 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; - POSIX::setgid 65534; # Set group id to nogroup - POSIX::setuid 65534; # Set user id to nobody + POSIX::setgid $nobody ? 65534 : USER; + POSIX::setuid $nobody ? 65534 : GROUP; exec @ARGV; }