Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
PROJECT_NAME: coreutils
PROJECT_DESC: "Core universal (cross-platform) utilities"
PROJECT_AUTH: "uutils"
RUST_MIN_SRV: "1.88.0"
RUST_MIN_SRV: "1.89"
CARGO_INCREMENTAL: "0"
# * style job configuration
STYLE_FAIL_ON_FAULT: true ## (bool) fail the build if a style job contains a fault (error or warning); may be overridden on a per-job basis
Expand Down Expand Up @@ -42,6 +42,27 @@ jobs:
persist-credentials: false
- uses: EmbarkStudios/cargo-deny-action@v2

logind:
name: Logind/${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_SRV }}
- uses: Swatinem/rust-cache@v2
- name: Compare with systemd commands
shell: bash
run: |
cargo test --locked --no-default-features --features test_logind --test tests --no-run --message-format=json > "$RUNNER_TEMP/logind-tests.json"
logind_test_binary=$(jq -r 'select(.reason == "compiler-artifact" and .target.name == "tests" and .executable != null) | .executable' "$RUNNER_TEMP/logind-tests.json")
bash util/test-logind.sh "$logind_test_binary"

style_deps:
## ToDO: [2021-11-10; rivy] 'Style/deps' needs more informative output and better integration of results into the GHA dashboard
name: Style/deps
Expand Down Expand Up @@ -233,7 +254,7 @@ jobs:
cargo +stable fetch --locked --quiet --target $(rustc --print host-tuple)
cargo +stable tree --no-dedupe --locked -e=no-dev --prefix=none ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} | grep -vE "$PWD" | sort --unique
- name: Test
run: cargo nextest run --hide-progress-bar --profile ci ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -p uucore -p coreutils
run: cargo nextest run --hide-progress-bar --profile ci ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --features test_logind -p uucore -p coreutils
env:
RUSTFLAGS: "-Awarnings"
RUST_BACKTRACE: "1"
Expand Down Expand Up @@ -305,6 +326,9 @@ jobs:
run: cargo nextest run --hide-progress-bar --profile ci --features ${{ matrix.job.features }}
env:
RUST_BACKTRACE: "1"
- name: Test utmpx with systemd-logind
if: runner.os == 'Linux'
run: cargo test -p uucore --lib --locked --features systemd-logind
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v7
Expand Down
5 changes: 5 additions & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# * cargo
cdylib
doctest
libloading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You no nonger dlopen.

@mattsu2020 mattsu2020 Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because the spell checker reported an error.

nocapture

# * uutils project
uutils
Expand All @@ -11,6 +13,7 @@ ucmd
uumain
rlimit
mkfifo
logind
urandom
uchild
ello
Expand Down Expand Up @@ -203,6 +206,8 @@ inode
inodes
isatty
lchown
libsystemd
ohos
pathlen
setgid
setgroups
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ members = [
[workspace.package]
categories = ["command-line-utilities"]
edition = "2024"
rust-version = "1.88.0"
rust-version = "1.89"
homepage = "https://github.com/uutils/coreutils"
keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"]
license = "MIT"
Expand Down Expand Up @@ -85,6 +85,7 @@ jiff = "0.2.18"
jiff-icu = "0.2.2"
jiff-tzdb = "0.1"
libc = "0.2.191"
libloading = "0.8.9"
lscolors = { version = "0.21.0", default-features = false, features = [
"gnu_legacy",
] }
Expand Down Expand Up @@ -435,6 +436,8 @@ openssl = [
]
# "test_risky_names" == enable tests that create problematic file names (would make a network share inaccessible to Windows, breaks SVN on Mac OS, etc.)
test_risky_names = []
# Linux logind integration tests.
test_logind = ["who", "pinky", "users", "uptime"]
# * only build `uudoc` when `--feature uudoc` is activated
uudoc = [
"dep:clap_complete",
Expand All @@ -458,14 +461,6 @@ 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 systemd_logind support for utmpx replacement
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:
# * The selinux(-sys) crate requires `libselinux` headers and shared library to be accessible in the C toolchain at compile time.
Expand Down
25 changes: 25 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ If you would prefer to test a select few utilities:
cargo test --features "chmod mv tail" --no-default-features
```

The logind record assembly and error tests run as `uucore` unit tests without a running
systemd instance or compiled shared-library fixtures:

```shell
cargo test -p uucore --features 'utmpx systemd-logind' --lib
```

The comparison against real systemd commands requires Linux with systemd as
PID 1, an active systemd-logind/D-Bus service, and a PAM `login` stack including
pam_systemd. Enable the four utilities and build the integration test executable:

```shell
cargo test --no-default-features --features test_logind --test tests --no-run
bash util/test-logind.sh /absolute/path/to/target/debug/deps/tests-HASH
```

Use the executable path printed by Cargo. This runs the otherwise ignored
`sessions_match_loginctl` test as a system service, using sudo when needed.
An empty utmp is mounted only inside that service's namespace. The test creates
a temporary PAM/TTY session with systemd-run, compares session metadata with
loginctl and the four utilities, then stops its session. The Logind CI jobs run
this comparison on Ubuntu 22.04 and 24.04 to cover older and newer sd-login APIs.
Older libraries cannot supply session timestamps or PIDs; the comparison checks
that the utilities show `?` for these fields.

If you also want to test the core utilities:

```shell
Expand Down
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub fn main() {
}
"default" | "macos" | "unix" | "windows" | "selinux" | "zip" | "clap_complete"
| "clap_mangen" | "fluent_syntax" | "openssl" => continue, // common/standard feature names
"nightly" | "test_unimplemented" | "expensive_tests" | "test_risky_names" => {
"nightly" | "test_unimplemented" | "expensive_tests" | "test_risky_names"
| "test_logind" => {
continue;
} // crate-local custom features
"uudoc" => continue, // is not a utility
Expand Down
5 changes: 5 additions & 0 deletions docs/src/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ Note that for some utilities, not all functionality is supported on each
platform. This is documented per utility.

{{ #include platform_table.md }}

## Linux login records

On Linux, `who`, `pinky`, `users`, and `uptime` prefer traditional login records
and try systemd-logind when the default file is empty or unavailable.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
default = pkgsFor.${system}.pkgs.mkShell {
packages = build_deps ++ gnu_testing_deps;

RUSTC_VERSION = "1.88";
RUSTC_VERSION = "1.89";
LIBCLANG_PATH = pkgsFor.${system}.lib.makeLibraryPath [pkgsFor.${system}.llvmPackages_latest.libclang.lib];
shellHook = ''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = ["."]

[workspace.package]
edition = "2024"
rust-version = "1.88.0"
rust-version = "1.89"
license = "MIT"

# Enable debug symbols in release builds for readable backtraces
Expand Down
5 changes: 1 addition & 4 deletions src/uu/pinky/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ doctest = false
[dependencies]
clap = { workspace = true }
fluent = { workspace = true }
uucore = { workspace = true, features = ["utmpx", "entries"] }

[features]
systemd_logind = ["uucore/systemd_logind"]
uucore = { workspace = true, features = ["utmpx", "systemd-logind", "entries"] }

[lints]
workspace = true
Expand Down
51 changes: 49 additions & 2 deletions src/uu/pinky/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ fn format_timestamp(ut: &UtmpxRecord) -> String {
};
}

TIME_FORMAT.with(|description| ut.login_time().format(description).unwrap())
ut.try_login_time().map_or_else(
|| "?".into(),
|time| TIME_FORMAT.with(|description| time.format(description).unwrap()),
)
}

/// Pull the real name out of a password entry's comment field: it is the part
Expand Down Expand Up @@ -299,7 +302,10 @@ impl Pinky {
if self.layout.header {
writeln!(writer, "{}", self.header_row())?;
}
for ut in Utmpx::iter_all_records() {
for ut in Utmpx::iter_all_records_with_options(utmpx::ReadOptions {
session_time: true,
session_pid: false,
}) {
if ut.is_user_process()
&& (self.names.is_empty() || self.names.iter().any(|n| n.as_str() == ut.user()))
{
Expand Down Expand Up @@ -368,6 +374,47 @@ impl Pinky {
mod tests {
use super::{format_quiet_time, real_name};

#[test]
#[cfg(target_os = "linux")]
fn missing_session_time_is_displayed_as_unknown() {
use super::*;
use uucore::systemd_logind::{SystemdLoginRecord, SystemdRecordType, SystemdUtmpxCompat};

let record = UtmpxRecord::Systemd(SystemdUtmpxCompat::new(SystemdLoginRecord {
user: "user".into(),
session_id: "legacy".into(),
seat_or_tty: "pts/test".into(),
raw_device: "pts/test".into(),
host: "alias.test".into(),
login_time: std::time::UNIX_EPOCH,
pid: 0,
session_leader_pid: 0,
record_type: SystemdRecordType::UserProcess,
}));
let pinky = Pinky {
resolve_hosts: false,
layout: Layout {
header: false,
real_name: false,
idle: true,
origin: true,
},
details: Details {
home_and_shell: false,
project: false,
plan: false,
},
names: Vec::new(),
};
assert_eq!(
pinky
.session_row(&record)
.split_whitespace()
.collect::<Vec<_>>(),
["user", "?pts/test", "?????", "?", "alias.test"]
);
}

#[test]
fn idle_under_a_minute_is_blank() {
assert_eq!(format_quiet_time(0), " ");
Expand Down
10 changes: 6 additions & 4 deletions src/uu/uptime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ clap = { workspace = true }
fluent = { workspace = true }
jiff = { workspace = true }
thiserror = { workspace = true }
uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] }

[features]
systemd_logind = ["uucore/systemd_logind"]
uucore = { workspace = true, features = [
"libc",
"utmpx",
"systemd-logind",
"uptime",
] }

[lints]
workspace = true
Expand Down
11 changes: 6 additions & 5 deletions src/uu/uptime/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use uucore::error::UResult;
use uucore::translate;
use uucore::uptime::get_uptime;
#[cfg(not(any(target_os = "openbsd", target_os = "android")))]
use uucore::utmpx::{BOOT_TIME, USER_PROCESS, Utmpx};
use uucore::utmpx::{BOOT_TIME, ReadOptions, USER_PROCESS, Utmpx};

use crate::{UptimeError, options, print_loadavg, print_nusers, print_time, print_uptime};

Expand Down Expand Up @@ -153,16 +153,17 @@ fn process_utmpx(file: Option<&OsString>) -> (Option<i64>, usize) {
let mut boot_time = None;

let records = match file {
Some(f) => Utmpx::iter_all_records_from(f),
None => Utmpx::iter_all_records(),
Some(f) => Utmpx::iter_all_records_from_with_options(f, ReadOptions::BASIC),
None => Utmpx::iter_all_records_with_options(ReadOptions::BASIC),
};

for line in records {
match line.record_type() {
x if x == USER_PROCESS => nusers += 1,
x if x == BOOT_TIME => {
let dt = line.login_time();
if dt.unix_timestamp() > 0 {
if let Some(dt) = line.try_login_time()
&& dt.unix_timestamp() > 0
{
boot_time = Some(dt.unix_timestamp());
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/uu/users/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test = false
doctest = false

[target.'cfg(any(target_vendor = "apple", target_os = "cygwin", target_os = "freebsd", target_os = "linux", target_os = "netbsd"))'.dependencies]
uucore = { workspace = true, features = ["utmpx"] }
uucore = { workspace = true, features = ["utmpx", "systemd-logind"] }

[target.'cfg(any(target_vendor = "apple", target_os = "cygwin", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
clap = { workspace = true }
Expand All @@ -29,9 +29,6 @@ uucore = { workspace = true, features = [] }
[target.'cfg(target_os = "openbsd")'.dependencies]
utmp-classic = { workspace = true }

[features]
systemd_logind = ["uucore/systemd_logind"]

[lints]
workspace = true

Expand Down
2 changes: 1 addition & 1 deletion src/uu/users/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
{
let filename = maybe_file.unwrap_or(utmpx::DEFAULT_FILE.as_ref());

users = Utmpx::iter_all_records_from(filename)
users = Utmpx::iter_all_records_from_with_options(filename, utmpx::ReadOptions::BASIC)
.filter(utmpx::UtmpxRecord::is_user_process)
.map(|ut| ut.user())
.collect::<Vec<_>>();
Expand Down
6 changes: 1 addition & 5 deletions src/uu/who/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ readme.workspace = true

[lib]
path = "src/who.rs"
test = false
doctest = false

[dependencies]
clap = { workspace = true }
fluent = { workspace = true }
rustix = { workspace = true, features = ["fs", "termios"] }
uucore = { workspace = true, features = ["utmpx"] }

[features]
systemd_logind = ["uucore/systemd_logind"]
uucore = { workspace = true, features = ["utmpx", "systemd-logind"] }

[lints]
workspace = true
Expand Down
Loading
Loading