diff --git a/devices/src/virtio/vhost/user/device/block.rs b/devices/src/virtio/vhost/user/device/block.rs index f7feb1ebf9..9e30226dbe 100644 --- a/devices/src/virtio/vhost/user/device/block.rs +++ b/devices/src/virtio/vhost/user/device/block.rs @@ -342,9 +342,6 @@ pub fn run_block_device(program_name: &str, args: &[&str]) -> anyhow::Result<()> let block = BlockBackend::new(BLOCK_EXECUTOR.clone(), filename, fileopts)?; let handler = DeviceRequestHandler::new(block); - if let Err(e) = ex.run_until(handler.run(opts.socket, &ex)) { - bail!("error occurred: {}", e); - } - - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run(opts.socket, &ex))? } diff --git a/devices/src/virtio/vhost/user/device/console.rs b/devices/src/virtio/vhost/user/device/console.rs index c3b76401d4..e2fb1bb921 100644 --- a/devices/src/virtio/vhost/user/device/console.rs +++ b/devices/src/virtio/vhost/user/device/console.rs @@ -267,10 +267,8 @@ fn run_console(params: &SerialParameters, socket: &str) -> anyhow::Result<()> { let _ = CONSOLE_EXECUTOR.set(ex.clone()); - if let Err(e) = ex.run_until(handler.run(socket, &ex)) { - bail!(e); - } - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run(socket, &ex))? } #[derive(FromArgs)] diff --git a/devices/src/virtio/vhost/user/device/cras_snd.rs b/devices/src/virtio/vhost/user/device/cras_snd.rs index 96aaade641..a2d41051c3 100644 --- a/devices/src/virtio/vhost/user/device/cras_snd.rs +++ b/devices/src/virtio/vhost/user/device/cras_snd.rs @@ -285,7 +285,6 @@ pub fn run_cras_snd_device(program_name: &str, args: &[&str]) -> anyhow::Result< let _ = SND_EXECUTOR.set(ex.clone()); - let _ = ex.run_until(handler.run_with_listener(listener, &ex))?; - - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run_with_listener(listener, &ex))? } diff --git a/devices/src/virtio/vhost/user/device/fs.rs b/devices/src/virtio/vhost/user/device/fs.rs index 5936bb0e32..0f067f0ada 100644 --- a/devices/src/virtio/vhost/user/device/fs.rs +++ b/devices/src/virtio/vhost/user/device/fs.rs @@ -337,9 +337,6 @@ pub fn run_fs_device(program_name: &str, args: &[&str]) -> anyhow::Result<()> { let _ = FS_EXECUTOR.set(ex.clone()); - if let Err(e) = ex.run_until(handler.run_with_listener(listener, &ex)) { - bail!(e); - } - - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run_with_listener(listener, &ex))? } diff --git a/devices/src/virtio/vhost/user/device/gpu.rs b/devices/src/virtio/vhost/user/device/gpu.rs index 988ad2000b..0900193a06 100644 --- a/devices/src/virtio/vhost/user/device/gpu.rs +++ b/devices/src/virtio/vhost/user/device/gpu.rs @@ -489,9 +489,6 @@ pub fn run_gpu_device(program_name: &str, args: &[&str]) -> anyhow::Result<()> { }; let handler = DeviceRequestHandler::new(backend); - if let Err(e) = ex.run_until(handler.run(socket, &ex)) { - error!("error occurred: {}", e); - } - - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run(socket, &ex))? } diff --git a/devices/src/virtio/vhost/user/device/net.rs b/devices/src/virtio/vhost/user/device/net.rs index fe0a982be5..4da05ebeba 100644 --- a/devices/src/virtio/vhost/user/device/net.rs +++ b/devices/src/virtio/vhost/user/device/net.rs @@ -413,20 +413,19 @@ pub fn run_net_device(program_name: &str, args: &[&str]) -> anyhow::Result<()> { let handler = DeviceRequestHandler::new(backend); let ex = Executor::new().context("failed to create executor")?; - threads.push(thread::spawn(move || { + threads.push(thread::spawn(move || -> anyhow::Result<()> { NET_EXECUTOR.with(|thread_ex| { let _ = thread_ex.set(ex.clone()); }); - if let Err(e) = ex.run_until(handler.run(&socket, &ex)) { - bail!("error occurred: {}", e); - } - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run(&socket, &ex))? })); } for t in threads { - if let Err(e) = t.join() { - bail!("failed to join threads: {:?}", e); + match t.join() { + Ok(r) => r?, + Err(e) => bail!("thread panicked: {:?}", e), } } Ok(()) diff --git a/devices/src/virtio/vhost/user/device/wl.rs b/devices/src/virtio/vhost/user/device/wl.rs index 3d0cd08422..377f02f323 100644 --- a/devices/src/virtio/vhost/user/device/wl.rs +++ b/devices/src/virtio/vhost/user/device/wl.rs @@ -361,9 +361,6 @@ pub fn run_wl_device(program_name: &str, args: &[&str]) -> anyhow::Result<()> { let handler = DeviceRequestHandler::new(WlBackend::new(wayland_paths, vm_socket, resource_bridge)); - if let Err(e) = ex.run_until(handler.run(socket, &ex)) { - bail!("error occurred: {}", e); - } - - Ok(()) + // run_until() returns an Result> which the ? operator lets us flatten. + ex.run_until(handler.run(socket, &ex))? }