Skip to content

Commit

Permalink
reinstall: avoid duplicate users in loginctl_users
Browse files Browse the repository at this point in the history
See #1093

Signed-off-by: Omer Tuchfeld <[email protected]>
  • Loading branch information
omertuc committed Feb 7, 2025
1 parent 69264e0 commit 0c026f0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions system-reinstall-bootc/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use rustix::process::geteuid;
use rustix::process::getuid;
use rustix::thread::set_thread_res_uid;
use serde_json::Value;
use std::collections::HashSet;
use std::fmt::Display;
use std::fmt::Formatter;
use std::process::Command;
use uzers::os::unix::UserExt;

fn loginctl_users() -> Result<Vec<String>> {
fn loginctl_users() -> Result<HashSet<String>> {
let users: Value = Command::new("loginctl")
.arg("list-sessions")
.arg("--output")
Expand All @@ -32,10 +33,10 @@ fn loginctl_users() -> Result<Vec<String>> {
.context("user name field is not a string")
.map(String::from)
})
// Artificially add the root user to the list of users as it doesn't appear in loginctl
// list-sessions
// Artificially add the root user to the list of users as it doesn't always appear in
// `loginctl list-sessions`
.chain(std::iter::once(Ok("root".to_string())))
.collect::<Result<Vec<String>>>()
.collect::<Result<HashSet<String>>>()
.context("error parsing users")
}

Expand Down

0 comments on commit 0c026f0

Please sign in to comment.