From 26135c1c75f3fb0055c485a872b6270937f3c01e Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 15 Sep 2026 02:14:02 +0100 Subject: [PATCH 1/2] build: use systemd_logind instead of feat_systemd_logind --- Cargo.toml | 12 ++++----- src/uu/pinky/Cargo.toml | 2 +- src/uu/uptime/Cargo.toml | 2 +- src/uu/users/Cargo.toml | 2 +- src/uu/who/Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- src/uucore/src/lib/features.rs | 2 +- src/uucore/src/lib/features/utmpx.rs | 38 ++++++++++++++-------------- src/uucore/src/lib/lib.rs | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2516e91ea15..6858c31c475 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -454,13 +454,13 @@ feat_diagnostics = ["uucore/diagnostics"] ## Optional feature for stdbuf # "feat_external_libstdbuf" == use an external libstdbuf.so for stdbuf instead of embedding it feat_external_libstdbuf = ["stdbuf/feat_external_libstdbuf"] -# "feat_systemd_logind" == enable feat_systemd_logind support for utmpx replacement +# "feat_systemd_logind" == enable systemd_logind support for utmpx replacement feat_systemd_logind = [ - "pinky/feat_systemd_logind", - "uptime/feat_systemd_logind", - "users/feat_systemd_logind", - "uucore/feat_systemd_logind", - "who/feat_systemd_logind", + "pinky/systemd_logind", + "uptime/systemd_logind", + "users/systemd_logind", + "uucore/systemd_logind", + "who/systemd_logind", ] # "feat_selinux" == enable support for SELinux Security Context (by using `--features feat_selinux`) # NOTE: diff --git a/src/uu/pinky/Cargo.toml b/src/uu/pinky/Cargo.toml index 73c8470cec1..515c65db03c 100644 --- a/src/uu/pinky/Cargo.toml +++ b/src/uu/pinky/Cargo.toml @@ -23,7 +23,7 @@ fluent = { workspace = true } uucore = { workspace = true, features = ["utmpx", "entries"] } [features] -feat_systemd_logind = ["uucore/feat_systemd_logind"] +systemd_logind = ["uucore/systemd_logind"] [lints] workspace = true diff --git a/src/uu/uptime/Cargo.toml b/src/uu/uptime/Cargo.toml index 37c818dfb9b..cde8b1159f3 100644 --- a/src/uu/uptime/Cargo.toml +++ b/src/uu/uptime/Cargo.toml @@ -26,7 +26,7 @@ thiserror = { workspace = true } uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] } [features] -feat_systemd_logind = ["uucore/feat_systemd_logind"] +systemd_logind = ["uucore/systemd_logind"] [lints] workspace = true diff --git a/src/uu/users/Cargo.toml b/src/uu/users/Cargo.toml index ca70debe352..a049fed31a0 100644 --- a/src/uu/users/Cargo.toml +++ b/src/uu/users/Cargo.toml @@ -30,7 +30,7 @@ uucore = { workspace = true, features = [] } utmp-classic = { workspace = true } [features] -feat_systemd_logind = ["uucore/feat_systemd_logind"] +systemd_logind = ["uucore/systemd_logind"] [lints] workspace = true diff --git a/src/uu/who/Cargo.toml b/src/uu/who/Cargo.toml index c3c36788106..1e8d2d2298d 100644 --- a/src/uu/who/Cargo.toml +++ b/src/uu/who/Cargo.toml @@ -25,7 +25,7 @@ rustix = { workspace = true, features = ["fs", "termios"] } uucore = { workspace = true, features = ["utmpx"] } [features] -feat_systemd_logind = ["uucore/feat_systemd_logind"] +systemd_logind = ["uucore/systemd_logind"] [lints] workspace = true diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index baa3b204cd8..b1867dae76e 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -164,7 +164,6 @@ fsext = ["libc", "windows-sys", "bstr", "wide"] fsxattr = ["xattr", "itertools", "libc"] hardware = [] lines = [] -feat_systemd_logind = ["utmpx", "libc"] format = [ "bigdecimal", "extendedbigdecimal", @@ -219,6 +218,7 @@ sum = [ "crc-fast", "data-encoding", ] +systemd_logind = ["utmpx", "libc"] # Use OpenSSL (libcrypto) for md5/sha1/sha2-family digests instead of the # pure-Rust crates. This dramatically speeds up checksum utilities on CPUs # without SHA-NI by using OpenSSL's optimized assembly implementations. diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 702705e8d95..ba84048caa1 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -129,7 +129,7 @@ pub mod selinux; pub mod signals; #[cfg(all(feature = "smack", target_os = "linux"))] pub mod smack; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(feature = "systemd_logind")] pub mod systemd_logind; #[cfg(all( feature = "utmpx", diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 9471680dd24..0b913039c22 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -41,7 +41,7 @@ use std::path::Path; use std::ptr; use std::sync::{Mutex, MutexGuard}; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(feature = "systemd_logind")] use crate::features::systemd_logind; pub use self::ut::*; @@ -328,13 +328,13 @@ impl Utmpx { /// Only one instance of [`UtmpxIter`] may be active at a time. This /// function will block as long as one is still active. Beware! pub fn iter_all_records() -> UtmpxIter { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] { // Use systemd-logind instead of traditional utmp when feature is enabled UtmpxIter::new_systemd() } - #[cfg(not(feature = "feat_systemd_logind"))] + #[cfg(not(feature = "systemd_logind"))] { let iter = UtmpxIter::new(); unsafe { @@ -360,7 +360,7 @@ impl Utmpx { /// /// The same caveats as for [`Utmpx::iter_all_records`] apply. pub fn iter_all_records_from>(path: P) -> UtmpxIter { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] { // Use systemd-logind for default utmp file when feature is enabled if path.as_ref() == Path::new(DEFAULT_FILE) { @@ -409,7 +409,7 @@ pub struct UtmpxIter { /// Ensure UtmpxIter is !Send. Technically redundant because MutexGuard /// is also !Send. phantom: PhantomData>, - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] systemd_iter: Option, } @@ -422,12 +422,12 @@ impl UtmpxIter { Self { guard, phantom: PhantomData, - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] systemd_iter: None, } } - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] fn new_systemd() -> Self { // PoisonErrors can safely be ignored let guard = LOCK @@ -452,7 +452,7 @@ impl UtmpxIter { /// Wrapper type that can hold either traditional utmpx records or systemd records pub enum UtmpxRecord { Traditional(Box), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Systemd(systemd_logind::SystemdUtmpxCompat), } @@ -461,7 +461,7 @@ impl UtmpxRecord { pub fn record_type(&self) -> i16 { match self { Self::Traditional(utmpx) => utmpx.record_type(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.record_type(), } } @@ -470,7 +470,7 @@ impl UtmpxRecord { pub fn pid(&self) -> i32 { match self { Self::Traditional(utmpx) => utmpx.pid(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.pid(), } } @@ -479,7 +479,7 @@ impl UtmpxRecord { pub fn terminal_suffix(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.terminal_suffix(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.terminal_suffix(), } } @@ -488,7 +488,7 @@ impl UtmpxRecord { pub fn user(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.user(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.user(), } } @@ -497,7 +497,7 @@ impl UtmpxRecord { pub fn host(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.host(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.host(), } } @@ -506,7 +506,7 @@ impl UtmpxRecord { pub fn tty_device(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.tty_device(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.tty_device(), } } @@ -515,7 +515,7 @@ impl UtmpxRecord { pub fn login_time(&self) -> time::OffsetDateTime { match self { Self::Traditional(utmpx) => utmpx.login_time(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.login_time(), } } @@ -526,7 +526,7 @@ impl UtmpxRecord { pub fn exit_status(&self) -> (i16, i16) { match self { Self::Traditional(utmpx) => utmpx.exit_status(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.exit_status(), } } @@ -535,7 +535,7 @@ impl UtmpxRecord { pub fn is_user_process(&self) -> bool { match self { Self::Traditional(utmpx) => utmpx.is_user_process(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => systemd.is_user_process(), } } @@ -544,7 +544,7 @@ impl UtmpxRecord { pub fn canon_host(&self) -> IOResult { match self { Self::Traditional(utmpx) => utmpx.canon_host(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] Self::Systemd(systemd) => Ok(systemd.canon_host()), } } @@ -553,7 +553,7 @@ impl UtmpxRecord { impl Iterator for UtmpxIter { type Item = UtmpxRecord; fn next(&mut self) -> Option { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(feature = "systemd_logind")] { if let Some(ref mut systemd_iter) = self.systemd_iter { // We have a systemd iterator - use it exclusively (never fall back to traditional utmp) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 6e241d5101e..fcad2cb316e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -79,7 +79,7 @@ pub use crate::features::ranges; pub use crate::features::ringbuffer; #[cfg(feature = "sum")] pub use crate::features::sum; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(feature = "systemd_logind")] pub use crate::features::systemd_logind; #[cfg(feature = "time")] pub use crate::features::time; From d86605d314af7439de3aaf467a7f726b6c1501c6 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 9 Aug 2026 13:43:50 +0100 Subject: [PATCH 2/2] build: restrict systemd_logind feature to Linux targets --- .github/workflows/freebsd.yml | 6 +---- .github/workflows/openbsd.yml | 4 +-- src/uucore/src/lib/features.rs | 2 +- src/uucore/src/lib/features/utmpx.rs | 38 ++++++++++++++-------------- src/uucore/src/lib/lib.rs | 2 +- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 95a80c29893..3f9267044e7 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -183,11 +183,7 @@ jobs: export RUST_BACKTRACE=1 export CARGO_TERM_COLOR=always if (test -z "\$FAULT"); then cargo nextest run --hide-progress-bar --profile ci --features '${{ matrix.job.features }}' || FAULT=1 ; fi - # There is no systemd-logind on FreeBSD, so test all features except feat_systemd_logind ( https://github.com/rust-lang/cargo/issues/3126#issuecomment-2523441905 ) - if (test -z "\$FAULT"); then - UUCORE_FEATURES=\$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "uucore") | .features | keys | .[]' | grep -v "feat_systemd_logind" | paste -s -d "," -) - cargo nextest run --hide-progress-bar --profile ci --features "\$UUCORE_FEATURES" -p uucore || FAULT=1 - fi + if (test -z "\$FAULT"); then cargo nextest run --hide-progress-bar --profile ci --all-features -p uucore || FAULT=1 ; fi # Test building with make if (test -z "\$FAULT"); then make || FAULT=1 ; fi # Clean to avoid to rsync back the files diff --git a/.github/workflows/openbsd.yml b/.github/workflows/openbsd.yml index 73120728818..640d5faf498 100644 --- a/.github/workflows/openbsd.yml +++ b/.github/workflows/openbsd.yml @@ -215,11 +215,9 @@ jobs: cargo test --features '${{ matrix.job.features }}' || FAULT=1 echo "::endgroup::" fi - # There is no systemd-logind on OpenBSD, so test all features except feat_systemd_logind if (test -z "\$FAULT"); then echo "::group::cargo test (uucore)" - UUCORE_FEATURES=\$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "uucore") | .features | keys | .[]' | grep -v "feat_systemd_logind" | paste -s -d "," -) - cargo test --features "\$UUCORE_FEATURES" -p uucore || FAULT=1 + cargo test --all-features -p uucore || FAULT=1 echo "::endgroup::" fi # Test building with make diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index ba84048caa1..4bce7676bd3 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -129,7 +129,7 @@ pub mod selinux; pub mod signals; #[cfg(all(feature = "smack", target_os = "linux"))] pub mod smack; -#[cfg(feature = "systemd_logind")] +#[cfg(all(feature = "systemd_logind", target_os = "linux"))] pub mod systemd_logind; #[cfg(all( feature = "utmpx", diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 0b913039c22..34c4703b707 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -41,7 +41,7 @@ use std::path::Path; use std::ptr; use std::sync::{Mutex, MutexGuard}; -#[cfg(feature = "systemd_logind")] +#[cfg(all(feature = "systemd_logind", target_os = "linux"))] use crate::features::systemd_logind; pub use self::ut::*; @@ -328,13 +328,13 @@ impl Utmpx { /// Only one instance of [`UtmpxIter`] may be active at a time. This /// function will block as long as one is still active. Beware! pub fn iter_all_records() -> UtmpxIter { - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] { // Use systemd-logind instead of traditional utmp when feature is enabled UtmpxIter::new_systemd() } - #[cfg(not(feature = "systemd_logind"))] + #[cfg(not(all(feature = "systemd_logind", target_os = "linux")))] { let iter = UtmpxIter::new(); unsafe { @@ -360,7 +360,7 @@ impl Utmpx { /// /// The same caveats as for [`Utmpx::iter_all_records`] apply. pub fn iter_all_records_from>(path: P) -> UtmpxIter { - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] { // Use systemd-logind for default utmp file when feature is enabled if path.as_ref() == Path::new(DEFAULT_FILE) { @@ -409,7 +409,7 @@ pub struct UtmpxIter { /// Ensure UtmpxIter is !Send. Technically redundant because MutexGuard /// is also !Send. phantom: PhantomData>, - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] systemd_iter: Option, } @@ -422,12 +422,12 @@ impl UtmpxIter { Self { guard, phantom: PhantomData, - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] systemd_iter: None, } } - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] fn new_systemd() -> Self { // PoisonErrors can safely be ignored let guard = LOCK @@ -452,7 +452,7 @@ impl UtmpxIter { /// Wrapper type that can hold either traditional utmpx records or systemd records pub enum UtmpxRecord { Traditional(Box), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Systemd(systemd_logind::SystemdUtmpxCompat), } @@ -461,7 +461,7 @@ impl UtmpxRecord { pub fn record_type(&self) -> i16 { match self { Self::Traditional(utmpx) => utmpx.record_type(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.record_type(), } } @@ -470,7 +470,7 @@ impl UtmpxRecord { pub fn pid(&self) -> i32 { match self { Self::Traditional(utmpx) => utmpx.pid(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.pid(), } } @@ -479,7 +479,7 @@ impl UtmpxRecord { pub fn terminal_suffix(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.terminal_suffix(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.terminal_suffix(), } } @@ -488,7 +488,7 @@ impl UtmpxRecord { pub fn user(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.user(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.user(), } } @@ -497,7 +497,7 @@ impl UtmpxRecord { pub fn host(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.host(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.host(), } } @@ -506,7 +506,7 @@ impl UtmpxRecord { pub fn tty_device(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.tty_device(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.tty_device(), } } @@ -515,7 +515,7 @@ impl UtmpxRecord { pub fn login_time(&self) -> time::OffsetDateTime { match self { Self::Traditional(utmpx) => utmpx.login_time(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.login_time(), } } @@ -526,7 +526,7 @@ impl UtmpxRecord { pub fn exit_status(&self) -> (i16, i16) { match self { Self::Traditional(utmpx) => utmpx.exit_status(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.exit_status(), } } @@ -535,7 +535,7 @@ impl UtmpxRecord { pub fn is_user_process(&self) -> bool { match self { Self::Traditional(utmpx) => utmpx.is_user_process(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => systemd.is_user_process(), } } @@ -544,7 +544,7 @@ impl UtmpxRecord { pub fn canon_host(&self) -> IOResult { match self { Self::Traditional(utmpx) => utmpx.canon_host(), - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] Self::Systemd(systemd) => Ok(systemd.canon_host()), } } @@ -553,7 +553,7 @@ impl UtmpxRecord { impl Iterator for UtmpxIter { type Item = UtmpxRecord; fn next(&mut self) -> Option { - #[cfg(feature = "systemd_logind")] + #[cfg(all(feature = "systemd_logind", target_os = "linux"))] { if let Some(ref mut systemd_iter) = self.systemd_iter { // We have a systemd iterator - use it exclusively (never fall back to traditional utmp) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index fcad2cb316e..85ccbaa332d 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -79,7 +79,7 @@ pub use crate::features::ranges; pub use crate::features::ringbuffer; #[cfg(feature = "sum")] pub use crate::features::sum; -#[cfg(feature = "systemd_logind")] +#[cfg(all(feature = "systemd_logind", target_os = "linux"))] pub use crate::features::systemd_logind; #[cfg(feature = "time")] pub use crate::features::time;