version 1.32, 2003/03/24 22:43:31
|
version 1.37, 2003/06/09 21:37:54
|
Line 38 ENDEVALUATE
|
Line 38 ENDEVALUATE
|
|
|
sub evaluate { |
sub evaluate { |
my ($expression,$safeeval,$decls) = @_; |
my ($expression,$safeeval,$decls) = @_; |
|
&Apache::lonxml::debug("got $expression and decls $decls"); |
unless (defined($expression)) { return ''; } |
unless (defined($expression)) { return ''; } |
if ($Apache::lonxml::evaluate < 1) { return $expression; } |
if ($Apache::lonxml::evaluate < 1) { return $expression; } |
my $result = ''; |
my $result = ''; |
Line 45 sub evaluate {
|
Line 46 sub evaluate {
|
$Apache::run::timeout=0; |
$Apache::run::timeout=0; |
$main::SIG{'ALRM'} = sub { |
$main::SIG{'ALRM'} = sub { |
$Apache::run::timeout=1; |
$Apache::run::timeout=1; |
Apache->request->print("timeout<br /> \n"); |
die("timeout"); |
}; |
}; |
|
my $innererror; |
eval { |
eval { |
alarm(Apache->request->server->timeout); |
alarm($Apache::lonnet::perlvar{'lonScriptTimeout'}); |
$safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression. |
$safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression. |
"\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}'); |
"\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}'); |
|
$innererror=$@; |
alarm(0); |
alarm(0); |
}; |
}; |
my $error=$@; |
my $error=$@; |
if ($error eq '' && !$Apache::run::timeout) { |
if ($error eq '' && $innererror eq '' && !$Apache::run::timeout) { |
$result = $safeeval->reval('return $_;'); |
$result = $safeeval->reval('return $_;'); |
chomp $result; |
chomp $result; |
} else { |
} else { |
Line 62 sub evaluate {
|
Line 65 sub evaluate {
|
$error = 'Code ran too long. It ran for more than '. |
$error = 'Code ran too long. It ran for more than '. |
Apache->request->server->timeout.' seconds'; |
Apache->request->server->timeout.' seconds'; |
} |
} |
&Apache::lonxml::error('substitution on <pre>'.$expression. |
&Apache::lonxml::error('substitution on <pre>'. |
'</pre> with <pre>'.$decls. |
&HTML::Entities::encode($expression). |
'</pre> caused <pre>'.$error); |
'</pre> with <pre>'. |
|
&HTML::Entities::encode($decls). |
|
'</pre> caused <pre>'. |
|
&HTML::Entities::encode($error).' '. |
|
&HTML::Entities::encode($innererror). |
|
'</pre>'); |
} |
} |
return $result |
return $result |
} |
} |
Line 76 sub run {
|
Line 84 sub run {
|
$Apache::run::timeout=0; |
$Apache::run::timeout=0; |
$main::SIG{'ALRM'} = sub { |
$main::SIG{'ALRM'} = sub { |
$Apache::run::timeout=1; |
$Apache::run::timeout=1; |
Apache->request->print("timeout<br /> \n"); |
die("timeout"); |
}; |
}; |
|
my $innererror; |
eval { |
eval { |
alarm(Apache->request->server->timeout); |
alarm($Apache::lonnet::perlvar{'lonScriptTimeout'}); |
@result=$safeeval->reval($code); |
@result=$safeeval->reval($code); |
|
$innererror=$@; |
alarm(0); |
alarm(0); |
}; |
}; |
my $error=$@; |
my $error=$@; |
if (($Apache::run::timeout || $error ne '') && !$hideerrors) { |
if (($Apache::run::timeout || $error ne '' || $innererror ne '') && !$hideerrors) { |
if ($Apache::run::timeout) { |
if ($Apache::run::timeout) { |
$error = 'Code ran too long. It ran for more than '. |
$error = 'Code ran too long. It ran for more than '. |
Apache->request->server->timeout.' seconds'; |
Apache->request->server->timeout.' seconds'; |
} |
} |
&Apache::lonxml::error('<pre>'.&HTML::Entities::encode($error). |
&Apache::lonxml::error('<pre>'.&HTML::Entities::encode($error).' '. |
|
&HTML::Entities::encode($innererror). |
'</pre> occured while running <pre>'. |
'</pre> occured while running <pre>'. |
&HTML::Entities::encode($code).'</pre>'); |
&HTML::Entities::encode($code).'</pre>'); |
} |
} |