Skip to content

Commit 56b3fef

Browse files
committed
timeout lscpi
1 parent 74c544e commit 56b3fef

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/store/root_store.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// You can copy/paste this file every time you need a simple GObject
22
// to hold some data
33

4+
use anyhow::Context;
45
use futures::prelude::*;
56
use glib::subclass::prelude::*;
67
use glib::Properties;
@@ -10,9 +11,9 @@ use std::cell::OnceCell;
1011
use std::cell::RefCell;
1112
use std::path::Path;
1213
use std::time::Duration;
14+
use tracing::{debug, warn};
1315
use tracing::error;
1416
use tracing::info;
15-
use tracing::{debug, warn};
1617

1718
use crate::container::Container;
1819
use crate::distrobox;
@@ -400,15 +401,20 @@ impl RootStore {
400401
// uses lspci to check if the host has an NVIDIA GPU
401402
debug!("Checking if host is NVIDIA");
402403
let cmd = Command::new("lspci");
403-
let output = self.run_to_string(cmd).await;
404+
let output = glib::future_with_timeout(Duration::from_secs(2), async move {
405+
self.run_to_string(cmd).await.context("Calling lspci")
406+
})
407+
.await
408+
.context("timeout")
409+
.flatten();
404410
match output {
405411
Ok(output) => {
406412
let is_nvidia = output.contains("NVIDIA") || output.contains("nVidia");
407-
debug!(is_nvidia, "Checked if host is NVIDIA");
413+
debug!(is_nvidia, "lspci ran successfully");
408414
is_nvidia
409415
}
410416
Err(e) => {
411-
debug!(?e, "Failed to check if host is NVIDIA");
417+
warn!(?e, "Failed to check if host is NVIDIA");
412418
false // If we can't run lspci, we assume it's not NVIDIA
413419
}
414420
}

0 commit comments

Comments
 (0)