diff options
Diffstat (limited to 'devices/src/virtio/tpm.rs')
-rw-r--r-- | devices/src/virtio/tpm.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/devices/src/virtio/tpm.rs b/devices/src/virtio/tpm.rs index e8c50f2..e7088ed 100644 --- a/devices/src/virtio/tpm.rs +++ b/devices/src/virtio/tpm.rs @@ -190,6 +190,7 @@ impl Worker { pub struct Tpm { storage: PathBuf, kill_evt: Option<EventFd>, + worker_thread: Option<thread::JoinHandle<()>>, } impl Tpm { @@ -197,6 +198,7 @@ impl Tpm { Tpm { storage, kill_evt: None, + worker_thread: None, } } } @@ -206,6 +208,10 @@ impl Drop for Tpm { if let Some(kill_evt) = self.kill_evt.take() { let _ = kill_evt.write(1); } + + if let Some(worker_thread) = self.worker_thread.take() { + let _ = worker_thread.join(); + } } } @@ -271,9 +277,14 @@ impl VirtioDevice for Tpm { .name("virtio_tpm".to_string()) .spawn(|| worker.run()); - if let Err(e) = worker_result { - error!("vtpm failed to spawn virtio_tpm worker: {}", e); - return; + match worker_result { + Err(e) => { + error!("vtpm failed to spawn virtio_tpm worker: {}", e); + return; + } + Ok(join_handle) => { + self.worker_thread = Some(join_handle); + } } } } |