--- loncom/xml/run.pm 2003/03/24 22:43:31 1.32 +++ loncom/xml/run.pm 2003/10/01 21:34:53 1.41 @@ -1,6 +1,6 @@ package Apache::run; # -# $Id: run.pm,v 1.32 2003/03/24 22:43:31 albertel Exp $ +# $Id: run.pm,v 1.41 2003/10/01 21:34:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,16 +45,18 @@ sub evaluate { $Apache::run::timeout=0; $main::SIG{'ALRM'} = sub { $Apache::run::timeout=1; - Apache->request->print("timeout
\n"); + die("timeout"); }; + my $innererror; eval { - alarm(Apache->request->server->timeout); + alarm($Apache::lonnet::perlvar{'lonScriptTimeout'}); $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression. "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}'); + $innererror=$@; alarm(0); }; my $error=$@; - if ($error eq '' && !$Apache::run::timeout) { + if ($error eq '' && $innererror eq '' && !$Apache::run::timeout) { $result = $safeeval->reval('return $_;'); chomp $result; } else { @@ -62,9 +64,14 @@ sub evaluate { $error = 'Code ran too long. It ran for more than '. Apache->request->server->timeout.' seconds'; } - &Apache::lonxml::error('substitution on
'.$expression.
-			       '
with
'.$decls.
-			       '
caused
'.$error);
+	&Apache::lonxml::error('substitution on 
'.
+			       &HTML::Entities::encode($expression).
+			       '
with
'.
+			       &HTML::Entities::encode($decls).
+			       '
caused
'.
+			       &HTML::Entities::encode($error).' '.
+			       &HTML::Entities::encode($innererror).
+			       '
'); } return $result } @@ -76,22 +83,33 @@ sub run { $Apache::run::timeout=0; $main::SIG{'ALRM'} = sub { $Apache::run::timeout=1; - Apache->request->print("timeout
\n"); + die("timeout"); }; + my $innererror; eval { - alarm(Apache->request->server->timeout); + alarm($Apache::lonnet::perlvar{'lonScriptTimeout'}); @result=$safeeval->reval($code); + $innererror=$@; alarm(0); }; my $error=$@; - if (($Apache::run::timeout || $error ne '') && !$hideerrors) { + if (($Apache::run::timeout || $error ne '' || $innererror ne '') && !$hideerrors) { if ($Apache::run::timeout) { $error = 'Code ran too long. It ran for more than '. Apache->request->server->timeout.' seconds'; } - &Apache::lonxml::error('
'.&HTML::Entities::encode($error).
-			       '
occured while running
'.
-			       &HTML::Entities::encode($code).'
'); + my $errormsg='
'.&HTML::Entities::encode($error).' '.
+	    &HTML::Entities::encode($innererror).
+	    '
occured while running
';
+	$code=&HTML::Entities::encode($code);
+	if ($innererror=~/line (\d+)/) {
+	    my $linenumber=$1;
+	    my @code=split("\n",$code);
+	    $code[$linenumber-1]=''.
+		$code[$linenumber-1].'';
+	    $code=join("\n",@code);
+	}
+	&Apache::lonxml::error($errormsg.$code.'
'); } if ( $#result < '1') { return $result[0]; @@ -120,7 +138,7 @@ sub dump { $symname.'{$_} } sort keys %'. $symname.')').")" } - if ($line ne '') { $dump.=&HTML::Entities::encode($line)."
\n"; } + if ($line ne '') { $dump.=&HTML::Entities::encode($line)."
"; } } } $dump.='';