[LON-CAPA-cvs] cvs: modules /gerd/maxima lonmaxima maximatestclient.pl

www lon-capa-cvs@mail.lon-capa.org
Sat, 04 Mar 2006 02:33:57 -0000


www		Fri Mar  3 21:33:57 2006 EDT

  Modified files:              
    /modules/gerd/maxima	lonmaxima maximatestclient.pl 
  Log:
  Works.
  
  
Index: modules/gerd/maxima/lonmaxima
diff -u modules/gerd/maxima/lonmaxima:1.6 modules/gerd/maxima/lonmaxima:1.7
--- modules/gerd/maxima/lonmaxima:1.6	Fri Mar  3 18:47:55 2006
+++ modules/gerd/maxima/lonmaxima	Fri Mar  3 21:33:54 2006
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Connect to MAXIMA CAS
 #
-# $Id: lonmaxima,v 1.6 2006/03/03 23:47:55 albertel Exp $
+# $Id: lonmaxima,v 1.7 2006/03/04 02:33:54 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,9 +52,10 @@
 my $port;                              # path to UNIX socket file
 my %perlvar;                           # configuration file info
 my $lastlog;                           # last string that was logged
-
+my $maximapid;                         # PID of maxima process
+my $selector;                          # open3's selector
 use vars qw($PREFORK $MAX_CLIENTS_PER_CHILD %children $children $status
-	    $pidfile $port %perlvar $lastlog);
+	    $pidfile $port %perlvar $lastlog $maximapid $selector);
  
 sub maximareply {
     my ($cmd) = @_;
@@ -65,15 +66,20 @@
     unless ($cmd=~/\;\n$/) { $cmd.=";\n"; }
 
     my ($cmd_in, $cmd_out, $cmd_err);
-    my $pid = open3($cmd_in, $cmd_out, $cmd_err, 'maxima');
-    $children{$pid} = 1;
+    $maximapid = open3($cmd_in, $cmd_out, $cmd_err, 'maxima');
+    $children{$maximapid} = 1;
     
     print $cmd_in $cmd;
     close($cmd_in);
 
     &status("Command sent");
 
-    my $selector = IO::Select->new();
+    $SIG{ALRM} = sub { kill 9 => $maximapid; }; 
+    alarm(5);
+    no strict 'refs';
+
+    $selector = IO::Select->new();
+
     $selector->add($cmd_err, $cmd_out);
     
     while (my @ready = $selector->can_read()) {
@@ -90,8 +96,11 @@
 	    $selector->remove($fh) if eof($fh);
 	}
     }
+    alarm(0);
+    $SIG{ALRM} = 'DEFAULT';
     close($cmd_out);
     close($cmd_err);
+    use strict 'refs';
     &status("Command processed");
     return ($reply,$error,$exitstatus);
 }
@@ -240,7 +249,6 @@
 &status('Starting');
      
 
-
 # Fork off our children.
 for (1 .. $PREFORK) {
     &make_new_child($server);
Index: modules/gerd/maxima/maximatestclient.pl
diff -u modules/gerd/maxima/maximatestclient.pl:1.1 modules/gerd/maxima/maximatestclient.pl:1.2
--- modules/gerd/maxima/maximatestclient.pl:1.1	Fri Mar  3 17:35:09 2006
+++ modules/gerd/maxima/maximatestclient.pl	Fri Mar  3 21:33:54 2006
@@ -5,8 +5,9 @@
 
 while ($in=<STDIN>) {
     chomp($in);
-    print $socket &escape($cmd)."\n";
-    print &unescape(<$socket>);
+    print $socket &escape($in)."\n";
+    $reply=<$socket>;
+    print &unescape($reply);
 }
 close($socket);