diff --git a/src/update_agent/mod.rs b/src/update_agent/mod.rs index 40ccf138..0a1c3821 100644 --- a/src/update_agent/mod.rs +++ b/src/update_agent/mod.rs @@ -68,7 +68,7 @@ lazy_static::lazy_static! { #[derive(Debug, Deserialize)] pub struct SessionJson { user: String, - #[serde(deserialize_with = "empty_string_as_none")] + #[serde(deserialize_with = "empty_or_na_string_as_none")] tty: Option, } @@ -79,14 +79,16 @@ pub struct InteractiveSession { tty_dev: String, } -/// Function to deserialize field to `Option`, where empty strings are -/// deserialized into `None`. -fn empty_string_as_none<'de, D>(deserializer: D) -> Result, D::Error> +/// Function to deserialize field to `Option`, where empty strings or +/// `n/a` (not available) strings are deserialized into `None`. In systemd v254+ +/// loginctl list-sessions --json started outputting `n/a` instead of an empty +/// string for tty. +fn empty_or_na_string_as_none<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let s = String::deserialize(deserializer)?; - if s.is_empty() { + if s.is_empty() || s.eq(&String::from("n/a")) { Ok(None) } else { Ok(Some(s))