Handle multiple concurrent sessions to the same host
authorJamie Cameron <jcameron@webmin.com>
Sat, 12 May 2007 05:26:58 +0000 (05:26 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 12 May 2007 05:26:58 +0000 (05:26 +0000)
fastrpc.cgi
web-lib-funcs.pl

index 5557db6..fc15fa0 100755 (executable)
@@ -207,17 +207,35 @@ while(1) {
        elsif ($arg->{'action'} eq 'require') {
                # require a library
                print STDERR "fastrpc: require $arg->{'module'}/$arg->{'file'}\n" if ($gconfig{'rpcdebug'});
-               &foreign_require($arg->{'module'},
-                                $arg->{'file'});
-               $rawrv = &serialise_variable( { 'status' => 1 });
+               eval {
+                       &foreign_require($arg->{'module'},
+                                        $arg->{'file'});
+                       };
+               if ($@) {
+                       print STDERR "fastrpc: require error $@\n" if ($gconfig{'rpcdebug'});
+                       $rawrv = &serialise_variable( { 'status' => 0,
+                                                       'rv' => $@ });
+                       }
+               else {
+                       print STDERR "fastrpc: require done\n" if ($gconfig{'rpcdebug'});
+                       $rawrv = &serialise_variable( { 'status' => 1 });
+                       }
                }
        elsif ($arg->{'action'} eq 'call') {
                # execute a function
                print STDERR "fastrpc: call $arg->{'module'}::$arg->{'func'}(",join(",", @{$arg->{'args'}}),")\n" if ($gconfig{'rpcdebug'});
-               local @rv = &foreign_call($arg->{'module'},
-                                   $arg->{'func'},
-                                   @{$arg->{'args'}});
-               if (@rv == 1) {
+               local @rv;
+               eval {
+                       @rv = &foreign_call($arg->{'module'},
+                                           $arg->{'func'},
+                                           @{$arg->{'args'}});
+                       };
+               if ($@) {
+                       print STDERR "fastrpc: call error $@\n" if ($gconfig{'rpcdebug'});
+                       $rawrv = &serialise_variable(
+                               { 'status' => 0, 'rv' => $@ } );
+                       }
+               elsif (@rv == 1) {
                        $rawrv = &serialise_variable(
                                { 'status' => 1, 'rv' => $rv[0] } );
                        }
index 44d78c7..f1adca0 100755 (executable)
@@ -1912,6 +1912,12 @@ if (!$main::file_cache{$realfile}) {
         $main::file_cache{$realfile} = \@lines;
        $main::file_cache_noflush{$realfile} = $_[1];
         }
+else {
+       # Make read-write if currently readonly
+       if (!$_[1]) {
+               $main::file_cache_noflush{$realfile} = 0;
+               }
+       }
 return $main::file_cache{$realfile};
 }
 
@@ -3795,11 +3801,12 @@ return wantarray ? ($ok, $err) : $ok;
 }
 
 # remote_session_name(host|&server)
+# Generates a unix session ID for some server
 sub remote_session_name
 {
 return ref($_[0]) && $_[0]->{'host'} && $_[0]->{'port'} ?
-               "$_[0]->{'host'}:$_[0]->{'port'}" :
-       ref($_[0]) ? "" : $_[0];
+               "$_[0]->{'host'}:$_[0]->{'port'}.$$" :
+       ref($_[0]) ? "" : "$_[0].$$";
 }
 
 # remote_foreign_require(server, module, file)