diff --git a/src/docker/container.rs b/src/docker/container.rs index 3fe8540..9b81a3e 100644 --- a/src/docker/container.rs +++ b/src/docker/container.rs @@ -1,3 +1,4 @@ +use std::pin::pin; use std::time::Duration; use super::{IoStream, IoStreamSource}; @@ -240,29 +241,31 @@ impl Container { pub async fn pipe_signals(&self) -> JoinHandle> { let container = self.clone(); - let handle = spawn(async move { - let stream = tokio_stream::empty() - .merge(signal_stream(SignalKind::alarm())) + let signal_handler = async move { + let mut stream = pin!(signal_stream(SignalKind::alarm()) .merge(signal_stream(SignalKind::hangup())) .merge(signal_stream(SignalKind::interrupt())) .merge(signal_stream(SignalKind::quit())) .merge(signal_stream(SignalKind::terminate())) .merge(signal_stream(SignalKind::user_defined1())) - .merge(signal_stream(SignalKind::user_defined2())); + .merge(signal_stream(SignalKind::user_defined2()))); - tokio::pin!(stream); while let Some(signal) = stream.next().await { container.kill(signal?.as_raw_value()).await?; } - Err::<(), Error>(anyhow!("Failed to listen for signals")) - }); + Err::<_, Error>(anyhow!("Failed to listen for signals")) + }; let container = self.clone(); + let wait_for_exit = async move { container.wait().await }; + spawn(async move { - let _ = container.wait().await; - handle.abort(); - Ok::<(), Error>(()) + tokio::select! { + result = signal_handler => result, + result = wait_for_exit => result, + }?; + Ok(()) }) } } diff --git a/src/hotplug/pluggable_device.rs b/src/hotplug/pluggable_device.rs index e2209ba..ad6ff5f 100644 --- a/src/hotplug/pluggable_device.rs +++ b/src/hotplug/pluggable_device.rs @@ -52,7 +52,7 @@ impl PluggableDevice { } pub fn syspath(&self) -> &Path { - &self.device.syspath() + self.device.syspath() } pub fn devnum(&self) -> (u32, u32) { diff --git a/src/hotplug/udev_streams.rs b/src/hotplug/udev_streams.rs index f8a067d..55ac67e 100644 --- a/src/hotplug/udev_streams.rs +++ b/src/hotplug/udev_streams.rs @@ -15,12 +15,12 @@ pub enum UdevEvent { pub fn enumerate(hub_path: PathBuf) -> impl tokio_stream::Stream> { try_stream! { let mut enumerator = Enumerator::new()?; - let mut devices = enumerator + let devices = enumerator .scan_devices()? .filter(|device| device.syspath().starts_with(&hub_path)) .filter_map(|device| PluggableDevice::from_device(&device)); - while let Some(device) = devices.next() { + for device in devices { yield device; } } diff --git a/src/main.rs b/src/main.rs index e676955..b0418d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,7 +104,7 @@ async fn run(param: cli::Run, verbosity: Verbosity) -> Result { let docker = Docker::connect_with_defaults()?; let container = docker.run(param.docker_args).await?; - let _ = container.pipe_signals(); + drop(container.pipe_signals()); let hub_path = param.root_device.hub()?.syspath().to_owned(); let hotplug_stream = run_hotplug(