Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 1 | // Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | //! Runs a virtual machine under KVM |
| 6 | |
Sonny Rao | 2ffa0cb | 2018-02-26 17:27:40 -0800 | [diff] [blame] | 7 | #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] |
| 8 | extern crate aarch64; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 9 | extern crate arch; |
Dylan Reid | 3082e8e | 2019-01-07 10:33:48 -0800 | [diff] [blame] | 10 | extern crate audio_streams; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 11 | extern crate byteorder; |
Dylan Reid | d169a8d | 2017-10-06 15:26:46 -0700 | [diff] [blame] | 12 | extern crate devices; |
Dylan Reid | 61edbbf | 2017-05-12 16:15:53 -0700 | [diff] [blame] | 13 | extern crate io_jail; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 14 | extern crate kernel_cmdline; |
| 15 | extern crate kernel_loader; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 16 | extern crate kvm; |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 17 | extern crate kvm_sys; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 18 | extern crate libc; |
paulhsia | f052cfe | 2019-01-22 15:22:25 +0800 | [diff] [blame] | 19 | extern crate libcras; |
Jason D. Clinton | 865323d | 2017-09-27 22:04:03 -0600 | [diff] [blame] | 20 | extern crate net_util; |
Dylan Reid | 88624f8 | 2018-01-11 09:20:16 -0800 | [diff] [blame] | 21 | extern crate qcow; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 22 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
| 23 | extern crate x86_64; |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 24 | #[macro_use] |
| 25 | extern crate sys_util; |
Zach Reizner | 29ad3c7 | 2017-08-04 15:12:58 -0700 | [diff] [blame] | 26 | extern crate data_model; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 27 | #[cfg(feature = "wl-dmabuf")] |
| 28 | extern crate gpu_buffer; |
Jingkui Wang | e13b180 | 2018-10-03 13:04:47 -0700 | [diff] [blame] | 29 | extern crate msg_socket; |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 30 | #[cfg(feature = "plugin")] |
| 31 | extern crate plugin_proto; |
| 32 | #[cfg(feature = "plugin")] |
| 33 | extern crate protobuf; |
Daniel Prilik | 2200604 | 2019-01-14 14:19:04 -0800 | [diff] [blame] | 34 | extern crate rand_ish; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 35 | extern crate resources; |
David Tolnay | 1d4d44a | 2018-12-03 23:37:46 -0800 | [diff] [blame] | 36 | extern crate sync; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 37 | extern crate vhost; |
| 38 | extern crate vm_control; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 39 | |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 40 | pub mod argument; |
Zach Reizner | 39aa26b | 2017-12-12 18:03:23 -0800 | [diff] [blame] | 41 | pub mod linux; |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 42 | #[cfg(feature = "plugin")] |
| 43 | pub mod plugin; |
Zach Reizner | 29ad3c7 | 2017-08-04 15:12:58 -0700 | [diff] [blame] | 44 | |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 45 | use std::fs::OpenOptions; |
Stephen Barber | 2cfc205 | 2017-06-21 15:16:11 -0700 | [diff] [blame] | 46 | use std::net; |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 47 | use std::os::unix::io::RawFd; |
Zach Reizner | 29ad3c7 | 2017-08-04 15:12:58 -0700 | [diff] [blame] | 48 | use std::os::unix::net::UnixDatagram; |
Zach Reizner | 39aa26b | 2017-12-12 18:03:23 -0800 | [diff] [blame] | 49 | use std::path::PathBuf; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 50 | use std::string::String; |
Zach Reizner | 39aa26b | 2017-12-12 18:03:23 -0800 | [diff] [blame] | 51 | use std::thread::sleep; |
Stephen Barber | 56fbf09 | 2017-06-29 16:12:14 -0700 | [diff] [blame] | 52 | use std::time::Duration; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 53 | |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 54 | use qcow::QcowFile; |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 55 | use sys_util::{getpid, kill_process_group, reap_child, syslog}; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 56 | |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 57 | use argument::{print_help, set_arguments, Argument}; |
Jingkui Wang | e13b180 | 2018-10-03 13:04:47 -0700 | [diff] [blame] | 58 | use msg_socket::{MsgSender, Sender}; |
Zach Reizner | 39aa26b | 2017-12-12 18:03:23 -0800 | [diff] [blame] | 59 | use vm_control::VmRequest; |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 60 | |
Zach Reizner | 39aa26b | 2017-12-12 18:03:23 -0800 | [diff] [blame] | 61 | static SECCOMP_POLICY_DIR: &'static str = "/usr/share/policy/crosvm"; |
Zach Reizner | ee73bf3 | 2017-08-29 16:33:28 -0700 | [diff] [blame] | 62 | |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 63 | struct DiskOption { |
| 64 | path: PathBuf, |
Daniel Verkamp | de9ae03 | 2018-08-09 16:26:59 -0700 | [diff] [blame] | 65 | read_only: bool, |
Dylan Reid | f463bc1 | 2017-07-12 19:24:57 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Daniel Verkamp | bd1a084 | 2019-01-08 15:50:34 -0800 | [diff] [blame] | 68 | #[allow(dead_code)] |
Chirantan Ekbote | d41d726 | 2018-11-16 16:37:45 -0800 | [diff] [blame] | 69 | struct BindMount { |
| 70 | src: PathBuf, |
| 71 | dst: PathBuf, |
| 72 | writable: bool, |
| 73 | } |
| 74 | |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 75 | pub struct Config { |
| 76 | vcpu_count: Option<u32>, |
| 77 | memory: Option<usize>, |
| 78 | kernel_path: PathBuf, |
Tristan Muntsinger | 4133b01 | 2018-12-21 16:01:56 -0800 | [diff] [blame^] | 79 | android_fstab: Option<PathBuf>, |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 80 | params: Vec<String>, |
| 81 | socket_path: Option<PathBuf>, |
| 82 | plugin: Option<PathBuf>, |
| 83 | plugin_root: Option<PathBuf>, |
Chirantan Ekbote | d41d726 | 2018-11-16 16:37:45 -0800 | [diff] [blame] | 84 | plugin_mounts: Vec<BindMount>, |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 85 | disks: Vec<DiskOption>, |
Stephen Barber | 2cfc205 | 2017-06-21 15:16:11 -0700 | [diff] [blame] | 86 | host_ip: Option<net::Ipv4Addr>, |
| 87 | netmask: Option<net::Ipv4Addr>, |
Stephen Barber | 308ff60 | 2018-02-13 22:47:07 -0800 | [diff] [blame] | 88 | mac_address: Option<net_util::MacAddress>, |
Stephen Barber | 5e77e88 | 2017-08-07 17:13:38 -0700 | [diff] [blame] | 89 | vhost_net: bool, |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 90 | tap_fd: Option<RawFd>, |
Dylan Reid | 059a188 | 2018-07-23 17:58:09 -0700 | [diff] [blame] | 91 | cid: Option<u64>, |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 92 | wayland_socket_path: Option<PathBuf>, |
David Reveman | 52ba4e5 | 2018-04-22 21:42:09 -0400 | [diff] [blame] | 93 | wayland_dmabuf: bool, |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 94 | shared_dirs: Vec<(PathBuf, String)>, |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 95 | multiprocess: bool, |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 96 | seccomp_policy_dir: PathBuf, |
Zach Reizner | 3a8100a | 2017-09-13 19:15:43 -0700 | [diff] [blame] | 97 | gpu: bool, |
paulhsia | f052cfe | 2019-01-22 15:22:25 +0800 | [diff] [blame] | 98 | cras_audio: bool, |
Dylan Reid | 3082e8e | 2019-01-07 10:33:48 -0800 | [diff] [blame] | 99 | null_audio: bool, |
Dylan Reid | 059a188 | 2018-07-23 17:58:09 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 102 | impl Default for Config { |
| 103 | fn default() -> Config { |
| 104 | Config { |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 105 | vcpu_count: None, |
| 106 | memory: None, |
| 107 | kernel_path: PathBuf::default(), |
Tristan Muntsinger | 4133b01 | 2018-12-21 16:01:56 -0800 | [diff] [blame^] | 108 | android_fstab: None, |
Zach Reizner | bb67871 | 2018-01-30 18:13:04 -0800 | [diff] [blame] | 109 | params: Vec::new(), |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 110 | socket_path: None, |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 111 | plugin: None, |
Dmitry Torokhov | 0f1770d | 2018-05-11 10:57:16 -0700 | [diff] [blame] | 112 | plugin_root: None, |
Chirantan Ekbote | d41d726 | 2018-11-16 16:37:45 -0800 | [diff] [blame] | 113 | plugin_mounts: Vec::new(), |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 114 | disks: Vec::new(), |
| 115 | host_ip: None, |
| 116 | netmask: None, |
| 117 | mac_address: None, |
| 118 | vhost_net: false, |
| 119 | tap_fd: None, |
| 120 | cid: None, |
| 121 | gpu: false, |
| 122 | wayland_socket_path: None, |
| 123 | wayland_dmabuf: false, |
| 124 | shared_dirs: Vec::new(), |
| 125 | multiprocess: !cfg!(feature = "default-no-sandbox"), |
| 126 | seccomp_policy_dir: PathBuf::from(SECCOMP_POLICY_DIR), |
paulhsia | f052cfe | 2019-01-22 15:22:25 +0800 | [diff] [blame] | 127 | cras_audio: false, |
Dylan Reid | 3082e8e | 2019-01-07 10:33:48 -0800 | [diff] [blame] | 128 | null_audio: false, |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 133 | // Wait for all children to exit. Return true if they have all exited, false |
| 134 | // otherwise. |
| 135 | fn wait_all_children() -> bool { |
Stephen Barber | 49dd2e2 | 2018-10-29 18:29:58 -0700 | [diff] [blame] | 136 | const CHILD_WAIT_MAX_ITER: isize = 100; |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 137 | const CHILD_WAIT_MS: u64 = 10; |
| 138 | for _ in 0..CHILD_WAIT_MAX_ITER { |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 139 | loop { |
Zach Reizner | 56158c8 | 2017-08-24 13:50:14 -0700 | [diff] [blame] | 140 | match reap_child() { |
| 141 | Ok(0) => break, |
| 142 | // We expect ECHILD which indicates that there were no children left. |
| 143 | Err(e) if e.errno() == libc::ECHILD => return true, |
| 144 | Err(e) => { |
| 145 | warn!("error while waiting for children: {:?}", e); |
| 146 | return false; |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 147 | } |
Zach Reizner | 56158c8 | 2017-08-24 13:50:14 -0700 | [diff] [blame] | 148 | // We reaped one child, so continue reaping. |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 149 | _ => {} |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
Zach Reizner | 56158c8 | 2017-08-24 13:50:14 -0700 | [diff] [blame] | 152 | // There's no timeout option for waitpid which reap_child calls internally, so our only |
| 153 | // recourse is to sleep while waiting for the children to exit. |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 154 | sleep(Duration::from_millis(CHILD_WAIT_MS)); |
| 155 | } |
| 156 | |
| 157 | // If we've made it to this point, not all of the children have exited. |
David Tolnay | 5bbbf61 | 2018-12-01 17:49:30 -0800 | [diff] [blame] | 158 | false |
Stephen Barber | a00753b | 2017-07-18 13:57:26 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 161 | fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::Result<()> { |
| 162 | match name { |
| 163 | "" => { |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 164 | if cfg.plugin.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 165 | return Err(argument::Error::TooManyArguments( |
| 166 | "`plugin` can not be used with kernel".to_owned(), |
| 167 | )); |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 168 | } else if !cfg.kernel_path.as_os_str().is_empty() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 169 | return Err(argument::Error::TooManyArguments( |
| 170 | "expected exactly one kernel path".to_owned(), |
| 171 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 172 | } else { |
| 173 | let kernel_path = PathBuf::from(value.unwrap()); |
| 174 | if !kernel_path.exists() { |
| 175 | return Err(argument::Error::InvalidValue { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 176 | value: value.unwrap().to_owned(), |
| 177 | expected: "this kernel path does not exist", |
| 178 | }); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 179 | } |
| 180 | cfg.kernel_path = kernel_path; |
| 181 | } |
| 182 | } |
Tristan Muntsinger | 4133b01 | 2018-12-21 16:01:56 -0800 | [diff] [blame^] | 183 | "android-fstab" => { |
| 184 | if cfg.android_fstab.is_some() |
| 185 | && !cfg.android_fstab.as_ref().unwrap().as_os_str().is_empty() |
| 186 | { |
| 187 | return Err(argument::Error::TooManyArguments( |
| 188 | "expected exactly one android fstab path".to_owned(), |
| 189 | )); |
| 190 | } else { |
| 191 | let android_fstab = PathBuf::from(value.unwrap()); |
| 192 | if !android_fstab.exists() { |
| 193 | return Err(argument::Error::InvalidValue { |
| 194 | value: value.unwrap().to_owned(), |
| 195 | expected: "this android fstab path does not exist", |
| 196 | }); |
| 197 | } |
| 198 | cfg.android_fstab = Some(android_fstab); |
| 199 | } |
| 200 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 201 | "params" => { |
Zach Reizner | bb67871 | 2018-01-30 18:13:04 -0800 | [diff] [blame] | 202 | cfg.params.push(value.unwrap().to_owned()); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 203 | } |
| 204 | "cpus" => { |
| 205 | if cfg.vcpu_count.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 206 | return Err(argument::Error::TooManyArguments( |
| 207 | "`cpus` already given".to_owned(), |
| 208 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 209 | } |
| 210 | cfg.vcpu_count = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 211 | Some( |
| 212 | value |
| 213 | .unwrap() |
| 214 | .parse() |
| 215 | .map_err(|_| argument::Error::InvalidValue { |
| 216 | value: value.unwrap().to_owned(), |
| 217 | expected: "this value for `cpus` needs to be integer", |
| 218 | })?, |
| 219 | ) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 220 | } |
| 221 | "mem" => { |
| 222 | if cfg.memory.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 223 | return Err(argument::Error::TooManyArguments( |
| 224 | "`mem` already given".to_owned(), |
| 225 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 226 | } |
| 227 | cfg.memory = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 228 | Some( |
| 229 | value |
| 230 | .unwrap() |
| 231 | .parse() |
| 232 | .map_err(|_| argument::Error::InvalidValue { |
| 233 | value: value.unwrap().to_owned(), |
| 234 | expected: "this value for `mem` needs to be integer", |
| 235 | })?, |
| 236 | ) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 237 | } |
paulhsia | f052cfe | 2019-01-22 15:22:25 +0800 | [diff] [blame] | 238 | "cras-audio" => { |
| 239 | cfg.cras_audio = true; |
| 240 | } |
Dylan Reid | 3082e8e | 2019-01-07 10:33:48 -0800 | [diff] [blame] | 241 | "null-audio" => { |
| 242 | cfg.null_audio = true; |
| 243 | } |
Dylan Reid | 88624f8 | 2018-01-11 09:20:16 -0800 | [diff] [blame] | 244 | "root" | "disk" | "rwdisk" | "qcow" | "rwqcow" => { |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 245 | let disk_path = PathBuf::from(value.unwrap()); |
| 246 | if !disk_path.exists() { |
| 247 | return Err(argument::Error::InvalidValue { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 248 | value: value.unwrap().to_owned(), |
| 249 | expected: "this disk path does not exist", |
| 250 | }); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 251 | } |
| 252 | if name == "root" { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 253 | if cfg.disks.len() >= 26 { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 254 | return Err(argument::Error::TooManyArguments( |
| 255 | "ran out of letters for to assign to root disk".to_owned(), |
| 256 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 257 | } |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 258 | cfg.params.push(format!( |
| 259 | "root=/dev/vd{} ro", |
David Tolnay | 5bbbf61 | 2018-12-01 17:49:30 -0800 | [diff] [blame] | 260 | char::from(b'a' + cfg.disks.len() as u8) |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 261 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 262 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 263 | cfg.disks.push(DiskOption { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 264 | path: disk_path, |
| 265 | read_only: !name.starts_with("rw"), |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 266 | }); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 267 | } |
| 268 | "host_ip" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 269 | if cfg.host_ip.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 270 | return Err(argument::Error::TooManyArguments( |
| 271 | "`host_ip` already given".to_owned(), |
| 272 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 273 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 274 | cfg.host_ip = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 275 | Some( |
| 276 | value |
| 277 | .unwrap() |
| 278 | .parse() |
| 279 | .map_err(|_| argument::Error::InvalidValue { |
| 280 | value: value.unwrap().to_owned(), |
| 281 | expected: "`host_ip` needs to be in the form \"x.x.x.x\"", |
| 282 | })?, |
| 283 | ) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 284 | } |
| 285 | "netmask" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 286 | if cfg.netmask.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 287 | return Err(argument::Error::TooManyArguments( |
| 288 | "`netmask` already given".to_owned(), |
| 289 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 290 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 291 | cfg.netmask = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 292 | Some( |
| 293 | value |
| 294 | .unwrap() |
| 295 | .parse() |
| 296 | .map_err(|_| argument::Error::InvalidValue { |
| 297 | value: value.unwrap().to_owned(), |
| 298 | expected: "`netmask` needs to be in the form \"x.x.x.x\"", |
| 299 | })?, |
| 300 | ) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 301 | } |
| 302 | "mac" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 303 | if cfg.mac_address.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 304 | return Err(argument::Error::TooManyArguments( |
| 305 | "`mac` already given".to_owned(), |
| 306 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 307 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 308 | cfg.mac_address = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 309 | Some( |
| 310 | value |
| 311 | .unwrap() |
| 312 | .parse() |
| 313 | .map_err(|_| argument::Error::InvalidValue { |
| 314 | value: value.unwrap().to_owned(), |
| 315 | expected: "`mac` needs to be in the form \"XX:XX:XX:XX:XX:XX\"", |
| 316 | })?, |
| 317 | ) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 318 | } |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 319 | "wayland-sock" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 320 | if cfg.wayland_socket_path.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 321 | return Err(argument::Error::TooManyArguments( |
| 322 | "`wayland-sock` already given".to_owned(), |
| 323 | )); |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 324 | } |
| 325 | let wayland_socket_path = PathBuf::from(value.unwrap()); |
| 326 | if !wayland_socket_path.exists() { |
| 327 | return Err(argument::Error::InvalidValue { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 328 | value: value.unwrap().to_string(), |
| 329 | expected: "Wayland socket does not exist", |
| 330 | }); |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 331 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 332 | cfg.wayland_socket_path = Some(wayland_socket_path); |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 333 | } |
David Reveman | 52ba4e5 | 2018-04-22 21:42:09 -0400 | [diff] [blame] | 334 | #[cfg(feature = "wl-dmabuf")] |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 335 | "wayland-dmabuf" => cfg.wayland_dmabuf = true, |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 336 | "socket" => { |
| 337 | if cfg.socket_path.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 338 | return Err(argument::Error::TooManyArguments( |
| 339 | "`socket` already given".to_owned(), |
| 340 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 341 | } |
| 342 | let mut socket_path = PathBuf::from(value.unwrap()); |
| 343 | if socket_path.is_dir() { |
| 344 | socket_path.push(format!("crosvm-{}.sock", getpid())); |
| 345 | } |
| 346 | if socket_path.exists() { |
| 347 | return Err(argument::Error::InvalidValue { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 348 | value: socket_path.to_string_lossy().into_owned(), |
| 349 | expected: "this socket path already exists", |
| 350 | }); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 351 | } |
| 352 | cfg.socket_path = Some(socket_path); |
| 353 | } |
| 354 | "multiprocess" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 355 | cfg.multiprocess = true; |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 356 | } |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 357 | "disable-sandbox" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 358 | cfg.multiprocess = false; |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 359 | } |
Chirantan Ekbote | 88f9cba | 2017-08-28 09:51:18 -0700 | [diff] [blame] | 360 | "cid" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 361 | if cfg.cid.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 362 | return Err(argument::Error::TooManyArguments( |
| 363 | "`cid` alread given".to_owned(), |
| 364 | )); |
Chirantan Ekbote | 88f9cba | 2017-08-28 09:51:18 -0700 | [diff] [blame] | 365 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 366 | cfg.cid = Some( |
| 367 | value |
| 368 | .unwrap() |
| 369 | .parse() |
| 370 | .map_err(|_| argument::Error::InvalidValue { |
| 371 | value: value.unwrap().to_owned(), |
| 372 | expected: "this value for `cid` must be an unsigned integer", |
| 373 | })?, |
| 374 | ); |
Chirantan Ekbote | 88f9cba | 2017-08-28 09:51:18 -0700 | [diff] [blame] | 375 | } |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 376 | "shared-dir" => { |
| 377 | // Formatted as <src:tag>. |
| 378 | let param = value.unwrap(); |
| 379 | let mut components = param.splitn(2, ':'); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 380 | let src = |
| 381 | PathBuf::from( |
| 382 | components |
| 383 | .next() |
| 384 | .ok_or_else(|| argument::Error::InvalidValue { |
| 385 | value: param.to_owned(), |
| 386 | expected: "missing source path for `shared-dir`", |
| 387 | })?, |
| 388 | ); |
| 389 | let tag = components |
| 390 | .next() |
| 391 | .ok_or_else(|| argument::Error::InvalidValue { |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 392 | value: param.to_owned(), |
| 393 | expected: "missing tag for `shared-dir`", |
David Tolnay | 2bac1e7 | 2018-12-12 14:33:42 -0800 | [diff] [blame] | 394 | })? |
| 395 | .to_owned(); |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 396 | |
| 397 | if !src.is_dir() { |
| 398 | return Err(argument::Error::InvalidValue { |
| 399 | value: param.to_owned(), |
| 400 | expected: "source path for `shared-dir` must be a directory", |
| 401 | }); |
| 402 | } |
| 403 | |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 404 | cfg.shared_dirs.push((src, tag)); |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 405 | } |
Dylan Reid | e026ef0 | 2017-10-02 19:03:52 -0700 | [diff] [blame] | 406 | "seccomp-policy-dir" => { |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 407 | // `value` is Some because we are in this match so it's safe to unwrap. |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 408 | cfg.seccomp_policy_dir = PathBuf::from(value.unwrap()); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 409 | } |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 410 | "plugin" => { |
| 411 | if !cfg.kernel_path.as_os_str().is_empty() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 412 | return Err(argument::Error::TooManyArguments( |
| 413 | "`plugin` can not be used with kernel".to_owned(), |
| 414 | )); |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 415 | } else if cfg.plugin.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 416 | return Err(argument::Error::TooManyArguments( |
| 417 | "`plugin` already given".to_owned(), |
| 418 | )); |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 419 | } |
Zach Reizner | cc30d58 | 2018-01-23 21:16:42 -0800 | [diff] [blame] | 420 | let plugin = PathBuf::from(value.unwrap().to_owned()); |
| 421 | if plugin.is_relative() { |
| 422 | return Err(argument::Error::InvalidValue { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 423 | value: plugin.to_string_lossy().into_owned(), |
| 424 | expected: "the plugin path must be an absolute path", |
| 425 | }); |
Zach Reizner | cc30d58 | 2018-01-23 21:16:42 -0800 | [diff] [blame] | 426 | } |
| 427 | cfg.plugin = Some(plugin); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 428 | } |
Dmitry Torokhov | 0f1770d | 2018-05-11 10:57:16 -0700 | [diff] [blame] | 429 | "plugin-root" => { |
| 430 | cfg.plugin_root = Some(PathBuf::from(value.unwrap().to_owned())); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 431 | } |
Chirantan Ekbote | d41d726 | 2018-11-16 16:37:45 -0800 | [diff] [blame] | 432 | "plugin-mount" => { |
| 433 | let components: Vec<&str> = value.unwrap().split(":").collect(); |
| 434 | if components.len() != 3 { |
| 435 | return Err(argument::Error::InvalidValue { |
| 436 | value: value.unwrap().to_owned(), |
| 437 | expected: |
| 438 | "`plugin-mount` must have exactly 3 components: <src>:<dst>:<writable>", |
| 439 | }); |
| 440 | } |
| 441 | |
| 442 | let src = PathBuf::from(components[0]); |
| 443 | if src.is_relative() { |
| 444 | return Err(argument::Error::InvalidValue { |
| 445 | value: components[0].to_owned(), |
| 446 | expected: "the source path for `plugin-mount` must be absolute", |
| 447 | }); |
| 448 | } |
| 449 | if !src.exists() { |
| 450 | return Err(argument::Error::InvalidValue { |
| 451 | value: components[0].to_owned(), |
| 452 | expected: "the source path for `plugin-mount` does not exist", |
| 453 | }); |
| 454 | } |
| 455 | |
| 456 | let dst = PathBuf::from(components[1]); |
| 457 | if dst.is_relative() { |
| 458 | return Err(argument::Error::InvalidValue { |
| 459 | value: components[1].to_owned(), |
| 460 | expected: "the destination path for `plugin-mount` must be absolute", |
| 461 | }); |
| 462 | } |
| 463 | |
| 464 | let writable: bool = |
| 465 | components[2] |
| 466 | .parse() |
| 467 | .map_err(|_| argument::Error::InvalidValue { |
| 468 | value: components[2].to_owned(), |
| 469 | expected: "the <writable> component for `plugin-mount` is not valid bool", |
| 470 | })?; |
| 471 | |
| 472 | cfg.plugin_mounts.push(BindMount { src, dst, writable }); |
| 473 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 474 | "vhost-net" => cfg.vhost_net = true, |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 475 | "tap-fd" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 476 | if cfg.tap_fd.is_some() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 477 | return Err(argument::Error::TooManyArguments( |
| 478 | "`tap-fd` alread given".to_owned(), |
| 479 | )); |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 480 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 481 | cfg.tap_fd = |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 482 | Some( |
| 483 | value |
| 484 | .unwrap() |
| 485 | .parse() |
| 486 | .map_err(|_| argument::Error::InvalidValue { |
| 487 | value: value.unwrap().to_owned(), |
| 488 | expected: "this value for `tap-fd` must be an unsigned integer", |
| 489 | })?, |
| 490 | ); |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 491 | } |
Zach Reizner | 3a8100a | 2017-09-13 19:15:43 -0700 | [diff] [blame] | 492 | "gpu" => { |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 493 | cfg.gpu = true; |
Zach Reizner | 3a8100a | 2017-09-13 19:15:43 -0700 | [diff] [blame] | 494 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 495 | "help" => return Err(argument::Error::PrintHelp), |
| 496 | _ => unreachable!(), |
| 497 | } |
| 498 | Ok(()) |
| 499 | } |
| 500 | |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 501 | fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> { |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 502 | let arguments = |
| 503 | &[Argument::positional("KERNEL", "bzImage of kernel to run"), |
Tristan Muntsinger | 4133b01 | 2018-12-21 16:01:56 -0800 | [diff] [blame^] | 504 | Argument::value("android-fstab", "PATH", "Path to Android fstab"), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 505 | Argument::short_value('p', |
| 506 | "params", |
| 507 | "PARAMS", |
Zach Reizner | bb67871 | 2018-01-30 18:13:04 -0800 | [diff] [blame] | 508 | "Extra kernel or plugin command line arguments. Can be given more than once."), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 509 | Argument::short_value('c', "cpus", "N", "Number of VCPUs. (default: 1)"), |
| 510 | Argument::short_value('m', |
| 511 | "mem", |
| 512 | "N", |
| 513 | "Amount of guest memory in MiB. (default: 256)"), |
| 514 | Argument::short_value('r', |
| 515 | "root", |
| 516 | "PATH", |
| 517 | "Path to a root disk image. Like `--disk` but adds appropriate kernel command line option."), |
| 518 | Argument::short_value('d', "disk", "PATH", "Path to a disk image."), |
Daniel Verkamp | f02fdd1 | 2018-10-10 17:25:14 -0700 | [diff] [blame] | 519 | Argument::value("qcow", "PATH", "Path to a qcow2 disk image. (Deprecated; use --disk instead.)"), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 520 | Argument::value("rwdisk", "PATH", "Path to a writable disk image."), |
Daniel Verkamp | f02fdd1 | 2018-10-10 17:25:14 -0700 | [diff] [blame] | 521 | Argument::value("rwqcow", "PATH", "Path to a writable qcow2 disk image. (Deprecated; use --rwdisk instead.)"), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 522 | Argument::value("host_ip", |
| 523 | "IP", |
| 524 | "IP address to assign to host tap interface."), |
| 525 | Argument::value("netmask", "NETMASK", "Netmask for VM subnet."), |
| 526 | Argument::value("mac", "MAC", "MAC address for VM."), |
paulhsia | f052cfe | 2019-01-22 15:22:25 +0800 | [diff] [blame] | 527 | Argument::flag("cras-audio", "Add an audio device to the VM that plays samples through CRAS server"), |
Dylan Reid | 3082e8e | 2019-01-07 10:33:48 -0800 | [diff] [blame] | 528 | Argument::flag("null-audio", "Add an audio device to the VM that plays samples to /dev/null"), |
Stephen Barber | 28a5a61 | 2017-10-20 17:15:30 -0700 | [diff] [blame] | 529 | Argument::value("wayland-sock", "PATH", "Path to the Wayland socket to use."), |
David Reveman | 52ba4e5 | 2018-04-22 21:42:09 -0400 | [diff] [blame] | 530 | #[cfg(feature = "wl-dmabuf")] |
| 531 | Argument::flag("wayland-dmabuf", "Enable support for DMABufs in Wayland device."), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 532 | Argument::short_value('s', |
| 533 | "socket", |
| 534 | "PATH", |
| 535 | "Path to put the control socket. If PATH is a directory, a name will be generated."), |
Dylan Reid | d0c9adc | 2017-10-02 19:04:50 -0700 | [diff] [blame] | 536 | Argument::short_flag('u', "multiprocess", "Run each device in a child process(default)."), |
| 537 | Argument::flag("disable-sandbox", "Run all devices in one, non-sandboxed process."), |
Chirantan Ekbote | ebd5681 | 2018-04-16 19:32:04 -0700 | [diff] [blame] | 538 | Argument::value("cid", "CID", "Context ID for virtual sockets."), |
| 539 | Argument::value("shared-dir", "PATH:TAG", |
| 540 | "Directory to be shared with a VM as a source:tag pair. Can be given more than once."), |
Dylan Reid | e026ef0 | 2017-10-02 19:03:52 -0700 | [diff] [blame] | 541 | Argument::value("seccomp-policy-dir", "PATH", "Path to seccomp .policy files."), |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 542 | #[cfg(feature = "plugin")] |
Zach Reizner | cc30d58 | 2018-01-23 21:16:42 -0800 | [diff] [blame] | 543 | Argument::value("plugin", "PATH", "Absolute path to plugin process to run under crosvm."), |
Daniel Verkamp | bd1a084 | 2019-01-08 15:50:34 -0800 | [diff] [blame] | 544 | #[cfg(feature = "plugin")] |
Dmitry Torokhov | 0f1770d | 2018-05-11 10:57:16 -0700 | [diff] [blame] | 545 | Argument::value("plugin-root", "PATH", "Absolute path to a directory that will become root filesystem for the plugin process."), |
Daniel Verkamp | bd1a084 | 2019-01-08 15:50:34 -0800 | [diff] [blame] | 546 | #[cfg(feature = "plugin")] |
Chirantan Ekbote | d41d726 | 2018-11-16 16:37:45 -0800 | [diff] [blame] | 547 | Argument::value("plugin-mount", "PATH:PATH:BOOL", "Path to be mounted into the plugin's root filesystem. Can be given more than once."), |
Rob Bradford | 8f002f5 | 2018-02-19 16:31:11 +0000 | [diff] [blame] | 548 | Argument::flag("vhost-net", "Use vhost for networking."), |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 549 | Argument::value("tap-fd", |
| 550 | "fd", |
| 551 | "File descriptor for configured tap device. Mutually exclusive with `host_ip`, `netmask`, and `mac`."), |
Zach Reizner | 3a8100a | 2017-09-13 19:15:43 -0700 | [diff] [blame] | 552 | #[cfg(feature = "gpu")] |
| 553 | Argument::flag("gpu", "(EXPERIMENTAL) enable virtio-gpu device"), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 554 | Argument::short_flag('h', "help", "Print help message.")]; |
| 555 | |
| 556 | let mut cfg = Config::default(); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 557 | let match_res = set_arguments(args, &arguments[..], |name, value| { |
| 558 | set_argument(&mut cfg, name, value) |
David Tolnay | 2bac1e7 | 2018-12-12 14:33:42 -0800 | [diff] [blame] | 559 | }) |
| 560 | .and_then(|_| { |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 561 | if cfg.kernel_path.as_os_str().is_empty() && cfg.plugin.is_none() { |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 562 | return Err(argument::Error::ExpectedArgument("`KERNEL`".to_owned())); |
| 563 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 564 | if cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some() { |
| 565 | if cfg.host_ip.is_none() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 566 | return Err(argument::Error::ExpectedArgument( |
| 567 | "`host_ip` missing from network config".to_owned(), |
| 568 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 569 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 570 | if cfg.netmask.is_none() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 571 | return Err(argument::Error::ExpectedArgument( |
| 572 | "`netmask` missing from network config".to_owned(), |
| 573 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 574 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 575 | if cfg.mac_address.is_none() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 576 | return Err(argument::Error::ExpectedArgument( |
| 577 | "`mac` missing from network config".to_owned(), |
| 578 | )); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
Dmitry Torokhov | 0f1770d | 2018-05-11 10:57:16 -0700 | [diff] [blame] | 581 | if cfg.plugin_root.is_some() && cfg.plugin.is_none() { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 582 | return Err(argument::Error::ExpectedArgument( |
| 583 | "`plugin-root` requires `plugin`".to_owned(), |
| 584 | )); |
Dmitry Torokhov | 0f1770d | 2018-05-11 10:57:16 -0700 | [diff] [blame] | 585 | } |
Daniel Verkamp | aac2813 | 2018-10-15 14:58:48 -0700 | [diff] [blame] | 586 | if cfg.tap_fd.is_some() |
| 587 | && (cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some()) |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 588 | { |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 589 | return Err(argument::Error::TooManyArguments( |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 590 | "`tap_fd` and any of `host_ip`, `netmask`, or `mac` are mutually exclusive" |
| 591 | .to_owned(), |
| 592 | )); |
Chirantan Ekbote | 5f78721 | 2018-05-31 15:31:31 -0700 | [diff] [blame] | 593 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 594 | Ok(()) |
| 595 | }); |
| 596 | |
| 597 | match match_res { |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 598 | #[cfg(feature = "plugin")] |
David Tolnay | 2bac1e7 | 2018-12-12 14:33:42 -0800 | [diff] [blame] | 599 | Ok(()) if cfg.plugin.is_some() => match plugin::run_config(cfg) { |
| 600 | Ok(_) => { |
| 601 | info!("crosvm and plugin have exited normally"); |
| 602 | Ok(()) |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 603 | } |
David Tolnay | 2bac1e7 | 2018-12-12 14:33:42 -0800 | [diff] [blame] | 604 | Err(e) => { |
| 605 | error!("{}", e); |
| 606 | Err(()) |
| 607 | } |
| 608 | }, |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 609 | Ok(()) => match linux::run_config(cfg) { |
| 610 | Ok(_) => { |
| 611 | info!("crosvm has exited normally"); |
| 612 | Ok(()) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 613 | } |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 614 | Err(e) => { |
| 615 | error!("{}", e); |
| 616 | Err(()) |
| 617 | } |
| 618 | }, |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 619 | Err(argument::Error::PrintHelp) => { |
| 620 | print_help("crosvm run", "KERNEL", &arguments[..]); |
| 621 | Ok(()) |
| 622 | } |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 623 | Err(e) => { |
| 624 | println!("{}", e); |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 625 | Err(()) |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 626 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 630 | fn vms_request( |
| 631 | cmd_name: &str, |
| 632 | cmd_help: &str, |
| 633 | request: &VmRequest, |
| 634 | args: std::env::Args, |
| 635 | ) -> std::result::Result<(), ()> { |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 636 | if args.len() == 0 { |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 637 | print_help(cmd_name, "VM_SOCKET...", &[]); |
| 638 | println!("{}", cmd_help); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 639 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 640 | |
| 641 | let mut return_result = Ok(()); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 642 | for socket_path in args { |
| 643 | match UnixDatagram::unbound().and_then(|s| { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 644 | s.connect(&socket_path)?; |
| 645 | Ok(s) |
| 646 | }) { |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 647 | Ok(s) => { |
Jingkui Wang | e13b180 | 2018-10-03 13:04:47 -0700 | [diff] [blame] | 648 | let sender = Sender::<VmRequest>::new(s); |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 649 | if let Err(e) = sender.send(request) { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 650 | error!( |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 651 | "failed to send request to socket at '{}': {:?}", |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 652 | socket_path, e |
| 653 | ); |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 656 | Err(e) => { |
| 657 | error!("failed to connect to socket at '{}': {}", socket_path, e); |
| 658 | return_result = Err(());; |
| 659 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 662 | |
| 663 | return_result |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 666 | fn stop_vms(args: std::env::Args) -> std::result::Result<(), ()> { |
| 667 | vms_request( |
| 668 | "crosvm stop", |
| 669 | "Stops the crosvm instance listening on each `VM_SOCKET` given.", |
| 670 | &VmRequest::Exit, |
| 671 | args, |
| 672 | ) |
| 673 | } |
| 674 | |
| 675 | fn suspend_vms(args: std::env::Args) -> std::result::Result<(), ()> { |
| 676 | vms_request( |
| 677 | "crosvm suspend", |
| 678 | "Suspends the crosvm instance listening on each `VM_SOCKET` given.", |
| 679 | &VmRequest::Suspend, |
| 680 | args, |
| 681 | ) |
| 682 | } |
| 683 | |
| 684 | fn resume_vms(args: std::env::Args) -> std::result::Result<(), ()> { |
| 685 | vms_request( |
| 686 | "crosvm resume", |
| 687 | "Suspends the crosvm instance listening on each `VM_SOCKET` given.", |
| 688 | &VmRequest::Resume, |
| 689 | args, |
| 690 | ) |
| 691 | } |
| 692 | |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 693 | fn balloon_vms(mut args: std::env::Args) -> std::result::Result<(), ()> { |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 694 | if args.len() < 2 { |
Daniel Verkamp | f76869d | 2019-01-03 12:53:04 -0800 | [diff] [blame] | 695 | print_help("crosvm balloon", "SIZE VM_SOCKET...", &[]); |
| 696 | println!("Set the ballon size of the crosvm instance to `SIZE` bytes."); |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 697 | } |
Daniel Verkamp | f76869d | 2019-01-03 12:53:04 -0800 | [diff] [blame] | 698 | let num_bytes = match args.nth(0).unwrap().parse::<u64>() { |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 699 | Ok(n) => n, |
| 700 | Err(_) => { |
Daniel Verkamp | f76869d | 2019-01-03 12:53:04 -0800 | [diff] [blame] | 701 | error!("Failed to parse number of bytes"); |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 702 | return Err(()); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 703 | } |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 704 | }; |
| 705 | |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 706 | let mut return_result = Ok(()); |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 707 | for socket_path in args { |
| 708 | match UnixDatagram::unbound().and_then(|s| { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 709 | s.connect(&socket_path)?; |
| 710 | Ok(s) |
| 711 | }) { |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 712 | Ok(s) => { |
Jingkui Wang | e13b180 | 2018-10-03 13:04:47 -0700 | [diff] [blame] | 713 | let sender = Sender::<VmRequest>::new(s); |
Daniel Verkamp | f76869d | 2019-01-03 12:53:04 -0800 | [diff] [blame] | 714 | if let Err(e) = sender.send(&VmRequest::BalloonAdjust(num_bytes)) { |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 715 | error!( |
| 716 | "failed to send balloon request to socket at '{}': {:?}", |
| 717 | socket_path, e |
| 718 | ); |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 721 | Err(e) => { |
| 722 | error!("failed to connect to socket at '{}': {}", socket_path, e); |
| 723 | return_result = Err(()); |
| 724 | } |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 725 | } |
| 726 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 727 | |
| 728 | return_result |
Dylan Reid | d443204 | 2017-12-06 18:20:09 -0800 | [diff] [blame] | 729 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 730 | |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 731 | fn create_qcow2(mut args: std::env::Args) -> std::result::Result<(), ()> { |
| 732 | if args.len() != 2 { |
| 733 | print_help("crosvm create_qcow2", "PATH SIZE", &[]); |
Dylan Reid | 940259c | 2018-07-20 14:22:33 -0700 | [diff] [blame] | 734 | println!("Create a new QCOW2 image at `PATH` of the specified `SIZE` in bytes."); |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 735 | } |
| 736 | let file_path = args.nth(0).unwrap(); |
| 737 | let size: u64 = match args.nth(0).unwrap().parse::<u64>() { |
| 738 | Ok(n) => n, |
| 739 | Err(_) => { |
| 740 | error!("Failed to parse size of the disk."); |
| 741 | return Err(()); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 742 | } |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 743 | }; |
| 744 | |
| 745 | let file = OpenOptions::new() |
| 746 | .create(true) |
| 747 | .read(true) |
| 748 | .write(true) |
| 749 | .open(&file_path) |
| 750 | .map_err(|e| { |
| 751 | error!("Failed opening qcow file at '{}': {:?}", file_path, e); |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 752 | })?; |
| 753 | |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 754 | QcowFile::new(file, size).map_err(|e| { |
| 755 | error!("Failed to create qcow file at '{}': {:?}", file_path, e); |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 756 | })?; |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 757 | |
| 758 | Ok(()) |
| 759 | } |
| 760 | |
Daniel Verkamp | 92f73d7 | 2018-12-04 13:17:46 -0800 | [diff] [blame] | 761 | fn disk_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> { |
| 762 | if args.len() < 2 { |
| 763 | print_help("crosvm disk", "SUBCOMMAND VM_SOCKET...", &[]); |
| 764 | println!("Manage attached virtual disk devices."); |
| 765 | println!("Subcommands:"); |
| 766 | println!(" resize DISK_INDEX NEW_SIZE VM_SOCKET"); |
| 767 | } |
| 768 | let subcommand: &str = &args.nth(0).unwrap(); |
| 769 | |
| 770 | let request = match subcommand { |
| 771 | "resize" => { |
| 772 | let disk_index = match args.nth(0).unwrap().parse::<usize>() { |
| 773 | Ok(n) => n, |
| 774 | Err(_) => { |
| 775 | error!("Failed to parse disk index"); |
| 776 | return Err(()); |
| 777 | } |
| 778 | }; |
| 779 | |
| 780 | let new_size = match args.nth(0).unwrap().parse::<u64>() { |
| 781 | Ok(n) => n, |
| 782 | Err(_) => { |
| 783 | error!("Failed to parse disk size"); |
| 784 | return Err(()); |
| 785 | } |
| 786 | }; |
| 787 | |
| 788 | VmRequest::DiskResize { |
| 789 | disk_index, |
| 790 | new_size, |
| 791 | } |
| 792 | } |
| 793 | _ => { |
| 794 | error!("Unknown disk subcommand '{}'", subcommand); |
| 795 | return Err(()); |
| 796 | } |
| 797 | }; |
| 798 | |
| 799 | let mut return_result = Ok(()); |
| 800 | for socket_path in args { |
| 801 | match UnixDatagram::unbound().and_then(|s| { |
| 802 | s.connect(&socket_path)?; |
| 803 | Ok(s) |
| 804 | }) { |
| 805 | Ok(s) => { |
| 806 | let sender = Sender::<VmRequest>::new(s); |
| 807 | if let Err(e) = sender.send(&request) { |
| 808 | error!( |
| 809 | "failed to send disk request to socket at '{}': {:?}", |
| 810 | socket_path, e |
| 811 | ); |
| 812 | } |
| 813 | } |
| 814 | Err(e) => { |
| 815 | error!("failed to connect to socket at '{}': {}", socket_path, e); |
| 816 | return_result = Err(()); |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | return_result |
| 822 | } |
| 823 | |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 824 | fn print_usage() { |
| 825 | print_help("crosvm", "[stop|run]", &[]); |
| 826 | println!("Commands:"); |
| 827 | println!(" stop - Stops crosvm instances via their control sockets."); |
| 828 | println!(" run - Start a new crosvm instance."); |
Dylan Reid | 2dcb632 | 2018-07-13 10:42:48 -0700 | [diff] [blame] | 829 | println!(" create_qcow2 - Create a new qcow2 disk image file."); |
Daniel Verkamp | 92f73d7 | 2018-12-04 13:17:46 -0800 | [diff] [blame] | 830 | println!(" disk - Manage attached virtual disk devices.") |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 833 | fn crosvm_main() -> std::result::Result<(), ()> { |
Stephen Barber | 56fbf09 | 2017-06-29 16:12:14 -0700 | [diff] [blame] | 834 | if let Err(e) = syslog::init() { |
Zach Reizner | a1422e6 | 2018-09-20 14:41:40 -0700 | [diff] [blame] | 835 | println!("failed to initialize syslog: {:?}", e); |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 836 | return Err(()); |
Stephen Barber | 56fbf09 | 2017-06-29 16:12:14 -0700 | [diff] [blame] | 837 | } |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 838 | |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 839 | let mut args = std::env::args(); |
| 840 | if args.next().is_none() { |
| 841 | error!("expected executable name"); |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 842 | return Err(()); |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 843 | } |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 844 | |
Zach Reizner | 8864cb0 | 2018-01-16 17:59:03 -0800 | [diff] [blame] | 845 | // Past this point, usage of exit is in danger of leaking zombie processes. |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 846 | let ret = match args.next().as_ref().map(|a| a.as_ref()) { |
| 847 | None => { |
| 848 | print_usage(); |
| 849 | Ok(()) |
| 850 | } |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 851 | Some("stop") => stop_vms(args), |
Zach Reizner | 6a8fdd9 | 2019-01-16 14:38:41 -0800 | [diff] [blame] | 852 | Some("suspend") => suspend_vms(args), |
| 853 | Some("resume") => resume_vms(args), |
Zach Reizner | 55a9e50 | 2018-10-03 10:22:32 -0700 | [diff] [blame] | 854 | Some("run") => run_vm(args), |
| 855 | Some("balloon") => balloon_vms(args), |
| 856 | Some("create_qcow2") => create_qcow2(args), |
Daniel Verkamp | 92f73d7 | 2018-12-04 13:17:46 -0800 | [diff] [blame] | 857 | Some("disk") => disk_cmd(args), |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 858 | Some(c) => { |
| 859 | println!("invalid subcommand: {:?}", c); |
| 860 | print_usage(); |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 861 | Err(()) |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 862 | } |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 863 | }; |
Zach Reizner | efe9578 | 2017-08-26 18:05:48 -0700 | [diff] [blame] | 864 | |
| 865 | // Reap exit status from any child device processes. At this point, all devices should have been |
| 866 | // dropped in the main process and told to shutdown. Try over a period of 100ms, since it may |
| 867 | // take some time for the processes to shut down. |
| 868 | if !wait_all_children() { |
| 869 | // We gave them a chance, and it's too late. |
| 870 | warn!("not all child processes have exited; sending SIGKILL"); |
| 871 | if let Err(e) = kill_process_group() { |
| 872 | // We're now at the mercy of the OS to clean up after us. |
| 873 | warn!("unable to kill all child processes: {:?}", e); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | // WARNING: Any code added after this point is not guaranteed to run |
| 878 | // since we may forcibly kill this process (and its children) above. |
Dylan Reid | bfba993 | 2018-02-05 15:51:59 -0800 | [diff] [blame] | 879 | ret |
| 880 | } |
| 881 | |
| 882 | fn main() { |
| 883 | std::process::exit(if crosvm_main().is_ok() { 0 } else { 1 }); |
Zach Reizner | 639d967 | 2017-05-01 17:57:18 -0700 | [diff] [blame] | 884 | } |