Skip to content

Commit

Permalink
Merge pull request #1059 from dustymabe/dusty-fix-loginctl
Browse files Browse the repository at this point in the history
update_agent: handle new output format for loginctl
  • Loading branch information
cgwalters authored Aug 15, 2023
2 parents ec7705c + f0c479f commit a62dd13
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/update_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "deserialize_systemd_tty_canonicalized")]
tty: Option<String>,
}

Expand All @@ -79,14 +79,18 @@ pub struct InteractiveSession {
tty_dev: String,
}

/// Function to deserialize field to `Option<String>`, where empty strings are
/// deserialized into `None`.
fn empty_string_as_none<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
/// Function to deserialize field to `Option<String>`, where empty strings or
/// `n/a` (not applicable) strings are deserialized into `None`. In systemd v254+
/// loginctl list-sessions --json started outputting `n/a` instead of an empty
/// string for tty.
fn deserialize_systemd_tty_canonicalized<'de, D>(
deserializer: D,
) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s.is_empty() {
if s.is_empty() || s == "n/a" {
Ok(None)
} else {
Ok(Some(s))
Expand Down

0 comments on commit a62dd13

Please sign in to comment.