Fix: mac2ip-Aufloesung hat jetzt ein Timeout gegen unbegrenztes Haengen
mac2ip::resolve() rief das externe mac2ip-Binary (das intern einen nmap-Scan ausloesen kann) ohne jedes Timeout auf - anders als mount/umount, die bereits ueber run_with_timeout/MOUNT_TIMEOUT_SECS gegen einen haengenden Subprozess abgesichert sind. Ein nicht mehr reagierendes mac2ip/nmap haette damit smart-mount watch/status unbegrenzt blockieren koennen. Der Aufruf laeuft jetzt (wie mount/umount) ueber die coreutils timeout(1), mit einer klaren Fehlermeldung bei Ueberschreitung. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+17
-1
@@ -19,6 +19,13 @@ use serde::Deserialize;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
/// Timeout in Sekunden für den `mac2ip`-Subprozess (dieselbe `timeout`-Coreutils-Technik wie
|
||||
/// [`crate::mount::run_with_timeout`]). `mac2ip` kann intern einen `nmap`-Scan auslösen -
|
||||
/// gegen ein dauerhaft nicht erreichbares/reagierendes Netz sonst ein unbegrenztes Hängen, das
|
||||
/// `smart-mount watch`/`status` komplett blockieren würde, statt korrekt "nicht auflösbar" zu
|
||||
/// melden.
|
||||
const MAC2IP_TIMEOUT_SECS: u64 = 15;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Mac2IpOutput {
|
||||
@@ -31,7 +38,9 @@ enum Mac2IpOutput {
|
||||
/// `binary` ist der konfigurierte Binary-Name/-Pfad (`GlobalSettings::mac2ip_binary`,
|
||||
/// standardmäßig `"mac2ip"`, per PATH aufgelöst).
|
||||
pub fn resolve(mac: &str, binary: &str) -> Result<Ipv4Addr> {
|
||||
let output = Command::new(binary)
|
||||
let output = Command::new("timeout")
|
||||
.arg(MAC2IP_TIMEOUT_SECS.to_string())
|
||||
.arg(binary)
|
||||
.args(["--json", "--auto-trust-networks", mac])
|
||||
.output()
|
||||
.map_err(|e| Error::Mac2Ip {
|
||||
@@ -39,6 +48,13 @@ pub fn resolve(mac: &str, binary: &str) -> Result<Ipv4Addr> {
|
||||
reason: format!("could not run '{binary}': {e}"),
|
||||
})?;
|
||||
|
||||
if output.status.code() == Some(124) {
|
||||
return Err(Error::Mac2Ip {
|
||||
mac: mac.to_string(),
|
||||
reason: format!("'{binary}' did not respond within {MAC2IP_TIMEOUT_SECS}s (timed out)"),
|
||||
});
|
||||
}
|
||||
|
||||
parse_output(&output.stdout, mac)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user