Fix passing back of errors from remote functional calls
authorJamie Cameron <jcameron@webmin.com>
Sat, 4 Dec 2010 00:48:47 +0000 (16:48 -0800)
committerJamie Cameron <jcameron@webmin.com>
Sat, 4 Dec 2010 00:48:47 +0000 (16:48 -0800)
fastrpc.cgi
web-lib-funcs.pl

index ab8b7c5..c00cb39 100755 (executable)
@@ -234,8 +234,8 @@ while(1) {
                # execute a function
                print STDERR "fastrpc: call $arg->{'module'}::$arg->{'func'}(",join(",", @{$arg->{'args'}}),")\n" if ($gconfig{'rpcdebug'});
                local @rv;
-               local $main::error_must_die = 1;
                eval {
+                       local $main::error_must_die = 1;
                        @rv = &foreign_call($arg->{'module'},
                                            $arg->{'func'},
                                            @{$arg->{'args'}});
@@ -269,8 +269,14 @@ while(1) {
                        $rv = eval $arg->{'code'};
                        }
                print STDERR "fastrpc: eval $arg->{'module'} $arg->{'code'} done = $rv error = $@\n" if ($gconfig{'rpcdebug'});
-               $rawrv = &serialise_variable(
-                       { 'status' => 1, 'rv' => $rv } );
+               if ($@) {
+                       $rawrv = &serialise_variable(
+                               { 'status' => 0, 'rv' => $@ } );
+                       }
+               else {
+                       $rawrv = &serialise_variable(
+                               { 'status' => 1, 'rv' => $rv } );
+                       }
                }
        elsif ($arg->{'action'} eq 'quit') {
                print STDERR "fastrpc: quit\n" if ($gconfig{'rpcdebug'});
index 1782fea..f1ddd18 100755 (executable)
@@ -6195,8 +6195,19 @@ if ($serv->{'fast'} || !$sn) {
                }
        my $from = &unserialise_variable($fromstr);
        if (!$from) {
+               # No response at all
                return &$main::remote_error_handler("Remote Webmin error");
                }
+       elsif (ref($from) ne 'HASH') {
+               # Not a hash?!
+               return &$main::remote_error_handler(
+                       "Invalid remote Webmin response : $from");
+               }
+       elsif (!$from->{'status'}) {
+               # Call failed
+               $from->{'rv'} =~ s/\s+at\s+(\S+)\s+line\s+(\d+)(,\s+<\S+>\s+line\s+(\d+))?//;
+               return &$main::remote_error_handler($from->{'rv'});
+               }
        if (defined($from->{'arv'})) {
                return @{$from->{'arv'}};
                }