Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uptime: add support for OpenBSD using utmp #6514

Merged
merged 2 commits into from
Jun 30, 2024

Conversation

lcheylus
Copy link
Contributor

@lcheylus lcheylus commented Jun 30, 2024

  • Add OpenBSD support for uptime using utmp-classic crate to parse UTMP file (/var/run/utmp by default): get uptime and count of logged users.
  • Enable tests for uptime (previously disabled on OpenBSD) and add a new specific test for OpenBSD (parse UTMP file, same as used for users test).

Fix #5664


Build and tests OK on OpenBSD current/amd64 and Linux Debian/testing with Rust 1.79.0

  • Unit tests:
$ cargo test -v --no-default-features --features uptime
  (...)
  test test_uptime::test_failed ... ok
  test test_uptime::test_invalid_arg ... ok
  test test_uptime::test_uptime ... ok
  test test_uptime::test_uptime_check_users_openbsd ... ok
  test test_uptime::test_uptime_with_dir ... ok
  test test_uptime::test_uptime_since ... ok
  test test_uptime::test_uptime_with_extra_argument ... ok
  test test_uptime::test_uptime_with_non_existent_file ... ok

  test result: ok. 34 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.19s
  • Test for uptime --since
$ target/debug/coreutils uptime -s
2024-06-29 08:57:30
  • Comparison with GNU uptime (binary = guptime on OpenBSD, installed via coreutils-9.5 package)
$ target/debug/coreutils uptime && guptime
 17:57:50  up 1 day,  9:00,  1 user,  load average: 0.07, 0.16, 0.14
 17:57:50  up 1 day,  9:00,  1 user,  load average: 0.07, 0.16, 0.14

lcheylus added 2 commits June 30, 2024 16:17
OpenBSD uses the original utmp file format when the other OS use utmpx
format to get infos for boot time and logged users.

By using the `utmp-classic` crate, we can process the logged users
on system from the /var/run/utmp file.

Signed-off-by: Laurent Cheylus <foxy@free.fr>
Signed-off-by: Laurent Cheylus <foxy@free.fr>
@sylvestre
Copy link
Contributor

Thanks!

@sylvestre sylvestre merged commit 96fa8e9 into uutils:main Jun 30, 2024
67 of 68 checks passed
@lcheylus lcheylus deleted the openbsd-uptime branch July 1, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uptime: support on OpenBSD
2 participants