summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJianxun Zhang <jianxun.zhang@intel.com>2019-03-04 14:38:24 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-05 05:53:36 -0800
commit56497d23ad18f9675d9b8bc7a3f4b3920acc206c (patch)
tree9b05c69add6bcbee9cb18d6103a043d6de9aa9fd /src/main.rs
parente4ece32798ba436fbfa88466c571f46dab99e2be (diff)
downloadcrosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar.gz
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar.bz2
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar.lz
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar.xz
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.tar.zst
crosvm-56497d23ad18f9675d9b8bc7a3f4b3920acc206c.zip
main: return error on invalid length of arguments
For the commands that verify the length of arguments, returning
Ok on an invalid length will confuse any external programs that
launch crosvm because they still get exit code of success from
crosvm even when the command failed.

Also add a missed return of 'create_qcow2' sub-command.

BUG=None
TEST=some basic tests:
() cargo check
() verify the return value from changed sub-commands is not 0 with
an invalid argument length.
() launch a VM with concierge_client from a root shell

Change-Id: I8278107a4d2fcf3cb6fafb65f30f431f97f7deb1
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1501552
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index dec98d1..c2e294f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -799,7 +799,7 @@ fn stop_vms(args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() == 0 {
         print_help("crosvm stop", "VM_SOCKET...", &[]);
         println!("Stops the crosvm instance listening on each `VM_SOCKET` given.");
-        return Ok(());
+        return Err(());
     }
     vms_request(&VmRequest::Exit, args)
 }
@@ -808,7 +808,7 @@ fn suspend_vms(args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() == 0 {
         print_help("crosvm suspend", "VM_SOCKET...", &[]);
         println!("Suspends the crosvm instance listening on each `VM_SOCKET` given.");
-        return Ok(());
+        return Err(());
     }
     vms_request(&VmRequest::Suspend, args)
 }
@@ -817,7 +817,7 @@ fn resume_vms(args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() == 0 {
         print_help("crosvm resume", "VM_SOCKET...", &[]);
         println!("Resumes the crosvm instance listening on each `VM_SOCKET` given.");
-        return Ok(());
+        return Err(());
     }
     vms_request(&VmRequest::Resume, args)
 }
@@ -826,7 +826,7 @@ fn balloon_vms(mut args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() < 2 {
         print_help("crosvm balloon", "SIZE VM_SOCKET...", &[]);
         println!("Set the ballon size of the crosvm instance to `SIZE` bytes.");
-        return Ok(());
+        return Err(());
     }
     let num_bytes = match args.nth(0).unwrap().parse::<u64>() {
         Ok(n) => n,
@@ -843,6 +843,7 @@ fn create_qcow2(mut args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() != 2 {
         print_help("crosvm create_qcow2", "PATH SIZE", &[]);
         println!("Create a new QCOW2 image at `PATH` of the specified `SIZE` in bytes.");
+        return Err(());
     }
     let file_path = args.nth(0).unwrap();
     let size: u64 = match args.nth(0).unwrap().parse::<u64>() {
@@ -875,7 +876,7 @@ fn disk_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> {
         println!("Manage attached virtual disk devices.");
         println!("Subcommands:");
         println!("  resize DISK_INDEX NEW_SIZE VM_SOCKET");
-        return Ok(());
+        return Err(());
     }
     let subcommand: &str = &args.nth(0).unwrap();