Commit 555263e1 authored by Kirk Webb's avatar Kirk Webb

tbadb_serv: message cleanup part 3: cleanup sending errors.

parent e178633c
...@@ -49,7 +49,7 @@ sub rpc_unforward($$); ...@@ -49,7 +49,7 @@ sub rpc_unforward($$);
sub rpc_nodewait($$); sub rpc_nodewait($$);
sub rpc_ping($$); sub rpc_ping($$);
sub rpc_exit($$); sub rpc_exit($$);
sub send_error($$$); sub error_exit($$$);
sub do_lru_cleanup($); sub do_lru_cleanup($);
sub unpack_bundle($$$); sub unpack_bundle($$$);
sub enter_fastboot($$); sub enter_fastboot($$);
...@@ -120,7 +120,6 @@ my %NMAP = (); ...@@ -120,7 +120,6 @@ my %NMAP = ();
my %FWDPORTS = (); my %FWDPORTS = ();
my $RPCIN; my $RPCIN;
my $RPCOUT; my $RPCOUT;
my $g_imglock;
my $debug = 0; my $debug = 0;
# Invoke the parent Net::Server class' run routine. # Invoke the parent Net::Server class' run routine.
...@@ -267,14 +266,11 @@ sub process_request($) { ...@@ -267,14 +266,11 @@ sub process_request($) {
# Dispatch function calls # Dispatch function calls
my $func = $data->{FUNCTION}; my $func = $data->{FUNCTION};
if (defined($func)) { if (defined($func)) {
if (!exists($DISPATCH{$func})) { error_exit($data->{FID}, RPCERR_BADFUNC, "Unknown function: $func")
warn "Unkown RPC: $func. Sending error and terminating connection.\n"; if (!exists($DISPATCH{$func}));
send_error($data->{FID}, RPCERR_BADFUNC, "Unknown function: $func");
exit 1;
}
$DISPATCH{$func}->($self,$data); $DISPATCH{$func}->($self,$data);
} else { } else {
warn "Received RPC data that was not a function call. Terminating connection.\n"; warn "Received RPC data that was not a function call.\n";
exit 1; exit 1;
} }
} }
...@@ -301,22 +297,15 @@ sub rpc_lockimage($$) { ...@@ -301,22 +297,15 @@ sub rpc_lockimage($$) {
my $srcname = $data->{ARGS}->{IMG_NAME}; my $srcname = $data->{ARGS}->{IMG_NAME};
# Arg checking and untainting. # Arg checking and untainting.
if (!$proj || !$srcname) { error_exit($data->{FID}, RPCERR_BADARGS, "Argument(s) missing.")
warn "Argument(s) missing from RPC!\n"; if (!$proj || !$srcname);
send_error($data->{FID}, RPCERR_BADARGS, "Argument(s) missing.");
exit 1; error_exit($data->{FID}, RPCERR_BADARGS, "Malformed project argument.")
} if ($proj !~ /^([-\w]+)$/);
if ($proj !~ /^([-\w]+)$/) {
warn "Malformed project argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed project argument.");
exit 1;
}
$proj = $1; $proj = $1;
if ($srcname !~ /^([-\.\w]+)$/) {
warn "Malformed image name argument!\n"; error_exit($data->{FID}, RPCERR_BADARGS, "Malformed image argument.")
send_error($data->{FID}, RPCERR_BADARGS, "Malformed image name argument."); if ($srcname !~ /^([-\.\w]+)$/);
exit 1;
}
$srcname = $1; $srcname = $1;
warn "Locking image: $proj/$srcname\n"; warn "Locking image: $proj/$srcname\n";
...@@ -325,11 +314,8 @@ sub rpc_lockimage($$) { ...@@ -325,11 +314,8 @@ sub rpc_lockimage($$) {
while (1) { while (1) {
last last
if (sysopen(LOCK, $lockfile, O_RDWR|O_CREAT|O_EXCL)); if (sysopen(LOCK, $lockfile, O_RDWR|O_CREAT|O_EXCL));
if (time() - $start > $IMGLOCK_TMO) { error_exit($data->{FID}, RPCERR_BADARGS, "Timed out waiting to acquire image lock.")
warn "timed out trying to get image lock for $proj/$srcname!\n"; if (time() - $start > $IMGLOCK_TMO);
send_error($data->{FID}, RPCERR_BADARGS, "Timed out waiting to acquire image lock.");
exit 1;
}
sleep 5; sleep 5;
} }
close(LOCK); close(LOCK);
...@@ -347,31 +333,19 @@ sub rpc_unlockimage($$) { ...@@ -347,31 +333,19 @@ sub rpc_unlockimage($$) {
my $srcname = $data->{ARGS}->{IMG_NAME}; my $srcname = $data->{ARGS}->{IMG_NAME};
# Arg checking and untainting. # Arg checking and untainting.
if (!$proj || !$srcname) { error_exit($data->{FID}, RPCERR_BADARGS, "Argument(s) missing.")
warn "Argument(s) missing from RPC!\n"; if (!$proj || !$srcname);
send_error($data->{FID}, RPCERR_BADARGS, "Argument(s) missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed project argument.")
exit 1; if ($proj !~ /^([-\w]+)$/);
}
if ($proj !~ /^([-\w]+)$/) {
warn "Malformed project argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed project argument.");
exit 1;
}
$proj = $1; $proj = $1;
if ($srcname !~ /^([-\.\w]+)$/) { error_exit($data->{FID}, RPCERR_BADARGS, "Malformed image name argument.")
warn "Malformed image name argument!\n"; if ($srcname !~ /^([-\.\w]+)$/);
send_error($data->{FID}, RPCERR_BADARGS, "Malformed image name argument.");
exit 1;
}
$srcname = $1; $srcname = $1;
warn "Unlocking image: $proj/$srcname\n"; warn "Unlocking image: $proj/$srcname\n";
my $lockfile = "/tmp/${proj}-${srcname}.imglock"; my $lockfile = "/tmp/${proj}-${srcname}.imglock";
if (!unlink($lockfile)) { error_exit($data->{FID}, RPCERR_BADARGS, "Could not remove image lock file.")
warn "Could not remove image lock file: $lockfile: $!\n"; if (!unlink($lockfile));
send_error($data->{FID}, RPCERR_BADARGS, "Could not remove image lock file.");
exit 1;
}
# Send success result back to caller. # Send success result back to caller.
warn "finished unlocking image: $proj/$srcname\n"; warn "finished unlocking image: $proj/$srcname\n";
...@@ -388,22 +362,13 @@ sub rpc_checkimage($$) { ...@@ -388,22 +362,13 @@ sub rpc_checkimage($$) {
my $srcsize = $data->{ARGS}->{IMG_SIZE}; my $srcsize = $data->{ARGS}->{IMG_SIZE};
# Arg checking and untainting. # Arg checking and untainting.
if (!$proj || !$srcname || !$srctime || !defined($srcsize)) { error_exit($data->{FID}, RPCERR_BADARGS, "Argument(s) missing.")
warn "Argument(s) missing from RPC!\n"; if (!$proj || !$srcname || !$srctime || !defined($srcsize));
send_error($data->{FID}, RPCERR_BADARGS, "Argument(s) missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed project argument.")
exit 1; if ($proj !~ /^([-\w]+)$/);
}
if ($proj !~ /^([-\w]+)$/) {
warn "Malformed project argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed project argument.");
exit 1;
}
$proj = $1; $proj = $1;
if ($srcname !~ /^([-\.\w]+)$/) { error_exit($data->{FID}, RPCERR_BADARGS, "Malformed image name argument.")
warn "Malformed image name argument!\n"; if ($srcname !~ /^([-\.\w]+)$/);
send_error($data->{FID}, RPCERR_BADARGS, "Malformed image name argument.");
exit 1;
}
$srcname = $1; $srcname = $1;
# Caller should have called the "lockimage" RPC already before calling # Caller should have called the "lockimage" RPC already before calling
...@@ -411,11 +376,8 @@ sub rpc_checkimage($$) { ...@@ -411,11 +376,8 @@ sub rpc_checkimage($$) {
warn "Image check requested for $proj/$srcname\n"; warn "Image check requested for $proj/$srcname\n";
my $projdir = "$IMAGE_CACHE/$proj"; my $projdir = "$IMAGE_CACHE/$proj";
if (!-d $projdir) { if (!-d $projdir) {
if (!mkdir($projdir, 0750)) { error_exit($data->{FID}, RPCERR_INTERNAL, "Internal file handling error.")
warn "Failed to create project image directory: $projdir: $!\n"; if (!mkdir($projdir, 0750));
send_error($data->{FID}, RPCERR_INTERNAL, "Internal file handling error.");
exit 1;
}
} }
my $lrufile = "$projdir/.$srcname.lru"; my $lrufile = "$projdir/.$srcname.lru";
...@@ -438,29 +400,19 @@ sub rpc_checkimage($$) { ...@@ -438,29 +400,19 @@ sub rpc_checkimage($$) {
return; return;
} else { } else {
# Delete older existing image to make way for new version. # Delete older existing image to make way for new version.
if (!unlink($imgfile)) { error_exit($data->{FID}, RPCERR_INTERNAL, "Failed to remove older version of image.")
warn "Could not remove old image: $imgfile\n"; if (!unlink($imgfile));
send_error($data->{FID}, RPCERR_INTERNAL, "Failed to remove older version of image.");
exit 1;
}
} }
} }
# Touch image's LRU file (even though the image may not have been # Touch image's LRU file (even though the image may not have been
# transferred yet; presumably it will be shortly). # transferred yet; presumably it will be shortly).
if (system($TOUCH, "$lrufile") != 0) { error_exit($data->{FID}, RPCERR_INTERNAL, "Internal file handling error.")
warn "Could not update timestamp on $lrufile!\n"; if (system($TOUCH, "$lrufile") != 0);
send_error($data->{FID}, RPCERR_INTERNAL, "Internal file handling error.");
exit 1;
}
# Check to see if we are over quota, and LRU prune if so. # Check to see if we are over quota, and LRU prune if so.
if (!$self->do_lru_cleanup()) { error_exit($data->{FID}, RPCERR_INTERNAL, "Failed while cleaning up image cache.")
warn "Error cleaning up cache. Exiting!\n"; if (!$self->do_lru_cleanup());
send_error($data->{FID}, RPCERR_INTERNAL,
"Failed while cleaning up image cache.");
exit 1;
}
# If we need/want to enforce some concurrency limits from this side, # If we need/want to enforce some concurrency limits from this side,
# we could send back a "WAIT" result here, which would tell the caller # we could send back a "WAIT" result here, which would tell the caller
...@@ -485,40 +437,22 @@ sub rpc_loadimage($$) { ...@@ -485,40 +437,22 @@ sub rpc_loadimage($$) {
my $proj = $data->{ARGS}->{IMG_PROJ}; my $proj = $data->{ARGS}->{IMG_PROJ};
# Check and untaint arguments # Check and untaint arguments
if (!$bundle_name || !$node_id || !$proj) { error_exit($data->{FID}, RPCERR_BADARGS, "Missing arguments.")
warn "missing RPC arguments!\n"; if (!$bundle_name || !$node_id || !$proj);
send_error($data->{FID}, RPCERR_BADARGS, "Missing arguments."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed project argument.")
exit 1; if ($proj !~ /^([-\w]+)$/);
}
if ($proj !~ /^([-\w]+)$/) {
warn "Malformed project argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed project argument.");
exit 1;
}
$proj = $1; $proj = $1;
if ($bundle_name !~ /^([-\.\w]+)$/) { error_exit($data->{FID}, RPCERR_BADARGS, "Malformed image bundle argument.")
warn "Malformed image bundle argument!\n"; if ($bundle_name !~ /^([-\.\w]+)$/);
send_error($data->{FID}, RPCERR_BADARGS, "Malformed image bundle argument.");
exit 1;
}
$bundle_name = $1; $bundle_name = $1;
my $bundle_path = "$IMAGE_CACHE/$proj/$bundle_name"; my $bundle_path = "$IMAGE_CACHE/$proj/$bundle_name";
if (!-f $bundle_path) { error_exit($data->{FID}, RPCERR_BADARGS, "No such image bundle.")
warn "no such bundle image: $bundle_path\n"; if (!-f $bundle_path);
send_error($data->{FID}, RPCERR_BADARGS, "No such image bundle."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.")
exit 1; if ($node_id !~ /^([-\w]+)$/);
}
if ($node_id !~ /^([-\w]+)$/) {
warn "Malformed node_id argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.");
exit 1;
}
$node_id = $1; $node_id = $1;
if (!exists($NMAP{$node_id})) { error_exit($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.")
warn "unknown/bad node_id: $node_id\n"; if (!exists($NMAP{$node_id}));
send_error($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.");
exit 1;
}
my $serial = $NMAP{$node_id}; my $serial = $NMAP{$node_id};
# Load image on to unit and report success/fail to caller. # Load image on to unit and report success/fail to caller.
...@@ -526,11 +460,8 @@ sub rpc_loadimage($$) { ...@@ -526,11 +460,8 @@ sub rpc_loadimage($$) {
# Step 1: Unpack image bundle (if necessary). This may block. # Step 1: Unpack image bundle (if necessary). This may block.
my $bundle_staging_dir = "$bundle_path.work"; my $bundle_staging_dir = "$bundle_path.work";
if (!$self->unpack_bundle($bundle_path, $bundle_staging_dir)) { error_exit($data->{FID}, RPCERR_INTERNAL, "Bundle unpack failed.")
warn "Could not unpack image bundle: $bundle_path\n"; if (!$self->unpack_bundle($bundle_path, $bundle_staging_dir));
send_error($data->{FID}, RPCERR_INTERNAL, "Bundle unpack failed.");
exit 1;
}
# Step 2: Make sure all required image files are present. # Step 2: Make sure all required image files are present.
my @todo_imgs = (); my @todo_imgs = ();
...@@ -542,9 +473,7 @@ sub rpc_loadimage($$) { ...@@ -542,9 +473,7 @@ sub rpc_loadimage($$) {
$imgpath = $defaultpath; $imgpath = $defaultpath;
} }
elsif ($required) { elsif ($required) {
warn "${imgpart}.img missing from bundle!\n"; error_exit($data->{FID}, RPCERR_BADARGS, "${imgpart}.img missing from bundle.");
send_error($data->{FID}, RPCERR_BADARGS, "${imgpart}.img missing from bundle.");
exit 1;
} }
else { else {
next; next;
...@@ -554,30 +483,21 @@ sub rpc_loadimage($$) { ...@@ -554,30 +483,21 @@ sub rpc_loadimage($$) {
} }
# Step 3: Reboot the device into fastboot mode. # Step 3: Reboot the device into fastboot mode.
if (!$self->enter_fastboot($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Node failed to load into fastboot.")
warn "failed to boot $node_id into fastboot!\n"; if (!$self->enter_fastboot($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "Node failed to load into fastboot.");
exit 1;
}
# Step 4: Reload the partitions based on the images we setup above. # Step 4: Reload the partitions based on the images we setup above.
foreach my $imgdata (@todo_imgs) { foreach my $imgdata (@todo_imgs) {
my ($imgpart, $imgpath) = @{$imgdata}; my ($imgpart, $imgpath) = @{$imgdata};
warn "loading $imgpart partition on $node_id\n" warn "loading $imgpart partition on $node_id\n"
if $debug; if $debug;
if (!$self->load_android_image($node_id, $imgpart, $imgpath)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Failed to load $imgpart.")
warn "failed to load $imgpart on $node_id!\n"; if (!$self->load_android_image($node_id, $imgpart, $imgpath));
send_error($data->{FID}, RPCERR_NODE_ERR, "Failed to load $imgpart.");
exit 1;
}
} }
# Step 5: reboot into newly loaded image # Step 5: reboot into newly loaded image
if (!$self->reboot_android($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Failed to boot newly loaded image.")
warn "newly loaded image failed to boot!\n"; if (!$self->reboot_android($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "Failed to boot newly loaded image.");
exit 1;
}
# Send success result back to caller. # Send success result back to caller.
warn "finished loading $proj/$bundle_name on $node_id\n"; warn "finished loading $proj/$bundle_name on $node_id\n";
...@@ -591,8 +511,7 @@ sub rpc_captureimage($$) { ...@@ -591,8 +511,7 @@ sub rpc_captureimage($$) {
# XXX: fill me in! # XXX: fill me in!
warn "Called...\n"; warn "Called...\n";
send_error($data->{FID}, RPCERR_NOTIMPL, "captureimage not implemented yet."); error_exit($data->{FID}, RPCERR_NOTIMPL, "captureimage not implemented yet.");
return;
} }
...@@ -606,43 +525,28 @@ sub rpc_reboot($$) { ...@@ -606,43 +525,28 @@ sub rpc_reboot($$) {
# Do a bit of arg checking. # Do a bit of arg checking.
$dowait = defined($dowait) && int($dowait) ? 1 : 0; $dowait = defined($dowait) && int($dowait) ? 1 : 0;
$fastboot = defined($fastboot) && int($fastboot) ? 1 : 0; $fastboot = defined($fastboot) && int($fastboot) ? 1 : 0;
if (!$node_id) { error_exit($data->{FID}, RPCERR_BADARGS, "node_id missing.")
warn "No node_id provided in RPC args!\n"; if (!$node_id);
send_error($data->{FID}, RPCERR_BADARGS, "node_id missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.")
exit 1; if (!exists($NMAP{$node_id}));
}
if (!exists($NMAP{$node_id})) {
warn "unknown/bad node_id: $node_id\n";
send_error($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.");
exit 1;
}
my $serial = $NMAP{$node_id}; my $serial = $NMAP{$node_id};
# Reboot the unit as directed. # Reboot the unit as directed.
if ($fastboot) { if ($fastboot) {
warn "rebooting node into fastboot: $node_id\n"; warn "rebooting node into fastboot: $node_id\n";
if (!$self->enter_fastboot($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Reboot (fastboot) failed.")
warn "failed to enter fastboot: $node_id!\n"; if (!$self->enter_fastboot($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "Reboot (fastboot) failed.");
exit 1;
}
} }
else { else {
warn "rebooting node $node_id\n"; warn "rebooting node $node_id\n";
if (!$self->reboot_android($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Reboot failed.")
warn "failed to reboot $node_id!\n"; if (!$self->reboot_android($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "Reboot failed.");
exit 1;
}
# Wait for device to boot up, if requested to do so. # Wait for device to boot up, if requested to do so.
if ($dowait) { if ($dowait) {
warn "waiting for $node_id to come up.\n"; warn "waiting for $node_id to come up.\n";
if (!wait_for_node($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "Boot failed.")
warn "failed waiting for $node_id to boot!\n"; if (!wait_for_node($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "Boot failed.");
exit 1;
}
} }
} }
...@@ -659,39 +563,24 @@ sub rpc_forward($$) { ...@@ -659,39 +563,24 @@ sub rpc_forward($$) {
my $node_id = $data->{ARGS}->{NODE_ID}; my $node_id = $data->{ARGS}->{NODE_ID};
my $thost = $data->{ARGS}->{TARGET_HOST}; my $thost = $data->{ARGS}->{TARGET_HOST};
if (!$node_id || !$thost) { error_exit($data->{FID}, RPCERR_BADARGS, "One or more arguments missing.")
warn "Missing RPC args!\n"; if (!$node_id || !$thost);
send_error($data->{FID}, RPCERR_BADARGS, "One or more arguments missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.")
exit 1; if ($node_id !~ /^([-\w]+)$/);
}
if ($node_id !~ /^([-\w]+)$/) {
warn "Malformed node_id argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.");
exit 1;
}
$node_id = $1; $node_id = $1;
if ($thost !~ /^([-\.\w]+)$/) { error_exit($data->{FID}, RPCERR_BADARGS, "Malformed target host argument.")
warn "Malformed target host argument!\n"; if ($thost !~ /^([-\.\w]+)$/);
send_error($data->{FID}, RPCERR_BADARGS, "Malformed target host argument.");
exit 1;
}
$thost = $1; $thost = $1;
if (!exists($NMAP{$node_id})) { error_exit($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.")
warn "Unknown/bad node_id: $node_id\n"; if (!exists($NMAP{$node_id}));
send_error($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.");
exit 1;
}
my $serial = $NMAP{$node_id}; my $serial = $NMAP{$node_id};
# Setup forwarding from the ADB daemon on the unit to the # Setup forwarding from the ADB daemon on the unit to the
# destionation port, and report back to caller! # destionation port, and report back to caller!
warn "fowarding ADB on node $node_id to destination host $thost\n"; warn "fowarding ADB on node $node_id to destination host $thost\n";
my $port = $self->setup_android_forward($node_id, $thost); my $port = $self->setup_android_forward($node_id, $thost);
if (!$port) { error_exit($data->{FID}, RPCERR_NODE_ERR, "adb forwarding failed.")
warn "failed to setup adb port forwarding for $node_id to $thost\n"; if (!$port);
send_error($data->{FID}, RPCERR_NODE_ERR, "adb forwarding failed.");
exit 1;
}
# Report success. # Report success.
warn "forwarding setup for $node_id finished.\n"; warn "forwarding setup for $node_id finished.\n";
...@@ -705,26 +594,17 @@ sub rpc_unforward($$) { ...@@ -705,26 +594,17 @@ sub rpc_unforward($$) {
my $node_id = $data->{ARGS}->{NODE_ID}; my $node_id = $data->{ARGS}->{NODE_ID};
if (!$node_id) { error_exit($data->{FID}, RPCERR_BADARGS, "node_id argument missing.")
warn "Missing node_id argument!\n"; if (!$node_id);
send_error($data->{FID}, RPCERR_BADARGS, "node_id argument missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.")
exit 1; if ($node_id !~ /^([-\w]+)$/);
}
if ($node_id !~ /^([-\w]+)$/) {
warn "Malformed node_id argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.");
exit 1;
}
$node_id = $1; $node_id = $1;
# Setup forwarding from the ADB daemon on the unit to the # Setup forwarding from the ADB daemon on the unit to the
# destionation port, and report back to caller! # destionation port, and report back to caller!
warn "removing ADB forwarding setup for node $node_id\n"; warn "removing ADB forwarding setup for node $node_id\n";
if (!$self->remove_android_forward($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "adb forwarding removal failed.")
warn "failed to clear adb port forwarding for $node_id!\n"; if (!$self->remove_android_forward($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "adb forwarding removal failed.");
exit 1;
}
# Report success. # Report success.
warn "forwarding cleared for $node_id\n"; warn "forwarding cleared for $node_id\n";
...@@ -738,25 +618,16 @@ sub rpc_nodewait($$) { ...@@ -738,25 +618,16 @@ sub rpc_nodewait($$) {
my $node_id = $data->{ARGS}->{NODE_ID}; my $node_id = $data->{ARGS}->{NODE_ID};
if (!$node_id) { error_exit($data->{FID}, RPCERR_BADARGS, "node_id argument missing.")
warn "Missing node_id argument!\n"; if (!$node_id);
send_error($data->{FID}, RPCERR_BADARGS, "node_id argument missing."); error_exit($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.")
exit 1; if ($node_id !~ /^([-\w]+)$/);
}
if ($node_id !~ /^([-\w]+)$/) {
warn "Malformed node_id argument!\n";
send_error($data->{FID}, RPCERR_BADARGS, "Malformed node_id argument.");
exit 1;
}
$node_id = $1; $node_id = $1;
# Wait for a while for the node to appear in adb. # Wait for a while for the node to appear in adb.
warn "waiting for $node_id to become available.\n"; warn "waiting for $node_id to become available.\n";
if (!$self->wait_for_android($node_id)) { error_exit($data->{FID}, RPCERR_NODE_ERR, "node wait failed.")
warn "failed while waiting for $node_id!\n"; if (!$self->wait_for_android($node_id));
send_error($data->{FID}, RPCERR_NODE_ERR, "node wait failed.");
exit 1;
}
# Report success. # Report success.
warn "$node_id is now ready.\n"; warn "$node_id is now ready.\n";
...@@ -786,10 +657,13 @@ sub rpc_exit($$) { ...@@ -786,10 +657,13 @@ sub rpc_exit($$) {
# Helper functions follow. # Helper functions follow.
# #
# Simple shorthand wrapper that sends an error back to the caller. # Simple shorthand wrapper that logs and sends an error back to the caller.
sub send_error($$$) { sub error_exit($$$) {
my ($fid, $code, $message) = @_; my ($fid, $code, $message) = @_;
# log the error locally.
warn "$message\n";
# Send failure result back. # Send failure result back.
return SendRPCData($RPCOUT, EncodeError($fid, $code, $message)); return SendRPCData($RPCOUT, EncodeError($fid, $code, $message));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment