3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

compiler_vm: Limit cpu usage and kill processes using excess cpu

This commit is contained in:
Pragmatic Software 2012-10-07 17:48:18 +00:00
parent f61bb61aeb
commit 7f8b39d20a
2 changed files with 17 additions and 9 deletions

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 386, BUILD_REVISION => 387,
BUILD_DATE => "2012-10-04", BUILD_DATE => "2012-10-07",
}; };
1; 1;

View File

@ -7,22 +7,22 @@ my $USE_LOCAL = defined $ENV{'CC_LOCAL'};
my %languages = ( my %languages = (
'C' => { 'C' => {
'cmdline' => 'gcc $args $file -o prog -ggdb -g3', 'cmdline' => 'gcc $file $args -o prog -ggdb -g3',
'args' => '-Wextra -Wall -Wno-unused -std=gnu89 -lm -Wfatal-errors', 'args' => '-Wextra -Wall -Wno-unused -std=gnu89 -lm -Wfatal-errors',
'file' => 'prog.c', 'file' => 'prog.c',
}, },
'C++' => { 'C++' => {
'cmdline' => 'g++ $args $file -o prog -ggdb', 'cmdline' => 'g++ $file $args -o prog -ggdb',
'args' => '-lm', 'args' => '-lm',
'file' => 'prog.cpp', 'file' => 'prog.cpp',
}, },
'C99' => { 'C99' => {
'cmdline' => 'gcc $args $file -o prog -ggdb -g3', 'cmdline' => 'gcc $file $args -o prog -ggdb -g3',
'args' => '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -std=c99 -lm -Wfatal-errors', 'args' => '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -std=c99 -lm -Wfatal-errors',
'file' => 'prog.c', 'file' => 'prog.c',
}, },
'C11' => { 'C11' => {
'cmdline' => 'gcc $args $file -o prog -ggdb -g3', 'cmdline' => 'gcc $file $args -o prog -ggdb -g3',
'args' => '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -std=c11 -lm -Wfatal-errors', 'args' => '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -std=c11 -lm -Wfatal-errors',
'file' => 'prog.c', 'file' => 'prog.c',
}, },
@ -126,7 +126,7 @@ sub interpret {
$cmdline =~ s/\$file/$languages{$lang}{'file'}/; $cmdline =~ s/\$file/$languages{$lang}{'file'}/;
print "Executing [$cmdline]\n"; print "Executing [$cmdline]\n";
my ($ret, $result) = execute(60, "$cmdline 2>&1"); my ($ret, $result) = execute(60, $cmdline);
# print "Got result: ($ret) [$result]\n"; # print "Got result: ($ret) [$result]\n";
# if exit code was not 0, then there was a problem compiling, such as an error diagnostic # if exit code was not 0, then there was a problem compiling, such as an error diagnostic
@ -146,9 +146,17 @@ sub interpret {
} }
my $user_input_quoted = quotemeta $user_input; my $user_input_quoted = quotemeta $user_input;
($ret, $result) = execute(60, "compiler_watchdog.pl $user_input_quoted"); ($ret, $result) = execute(60, "bash -c 'ulimit -t 1; compiler_watchdog.pl $user_input_quoted > .output'");
$result = "";
open(FILE, '.output');
while(<FILE>) {
$result .= $_;
last if length $result >= 2048 * 20;
}
close(FILE);
#$result =~ s/^\s+//;
$result =~ s/\s+$//; $result =~ s/\s+$//;
# print "Executed prog; got result: ($ret) [$result]\n"; # print "Executed prog; got result: ($ret) [$result]\n";