-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
users: support OpenBSD using utmp #6406
Conversation
A few points:
|
Can you please add |
tests/by-util/test_users.rs
Outdated
new_ucmd!() | ||
.args(&["basic_openbsd_utmp"]) | ||
.run() | ||
.stdout_contains("jadi"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what means jadi ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its my user name. no specific meaning. If not appropriate to use it, I can add a new user to my OpenBSD (say test_user), login and use that utmp file instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/uu/users/src/platform/openbsd.rs
Outdated
pub fn uumain(args: impl uucore::Args) -> UResult<()> { | ||
let _matches = uu_app().try_get_matches_from(args)?; | ||
let matches = uu_app() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bunch of code is duplicated from the unix.rs
i would prefer that we have a single file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. they are different only in small parts. Will try to use the same file and merge this into that using a os_name check when reading data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done... tried to do it clean but please do not hesitate to comment & improve.
src/uu/users/Cargo.toml
Outdated
@@ -16,6 +16,7 @@ path = "src/users.rs" | |||
|
|||
[dependencies] | |||
clap = { workspace = true } | |||
utmp-classic = {version = "0.1.5"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please define it in /Cargo.toml and use workspace = true
and make it openbsd only
will work on it. The last time I tested the utmp-classic did not worked using the latest zeroconf. Obviously its cleaner to fix the code to work with the latest version. will work on that. |
done. upgraded to the latest zerocopy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spell-checker exception for testuser
=> prevent error in CI job "Style/spelling (ubuntu-latest, feat_os_unix)" : tests/by-util/test_users.rs:41:27 - Unknown word (testuser)
spell-checker:ignore (words) testuser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edited the sample utmp file to make it cleaner. Now it includes two logins for test
, one for user
and one for root
. cleaner for tests and no need for spell-check ignore I imagine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK with the last version of your tests/fixtures/users/openbsd_utmp
file:
- test
tests/by-util/test_users.rs::test_users_check_name_openbsd
is OK to check usertest
- no need to add an exception for spell-check.
@jadijadi Congrats for your work to add support for OpenBSD on Some comments - review for this PR
$ cargo build --no-default-features --features users
$ ./target/debug/coreutils users -V
users 0.0.26
$ ./target/debug/coreutils users -h
Print the user names of users currently logged in to the current host.
Usage: ./target/debug/coreutils users [FILE]
(...)
$ cargo test --no-default-features --features users
(...)
test test_users::test_invalid_arg ... ok
test test_users::test_users_check_name_openbsd ... ok
test test_users::test_users_no_arg ... ok
test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.14s
With 1 logged user: $ ./target/debug/coreutils users
fox
$ gusers
fox With 3 logged users (user $ ./target/debug/coreutils users
fox fox root
$ gusers
fox fox root => same results for commands NB : with OpenBSD native command |
Great and thanks for the warm words. I'm also working on other utmp related tools on OpenBSD. Will send PRs after this one is finalized.
done. thanks for the hint.
As you mentioned, I kept the GNU compatibility and showing all logged in users and not removing the duplicate user names. |
I have a working implementation for
For
Thanks, please edit also the title of this PR ("users: support OpenBSD using utmp") |
@sylvestre @cakebaker Please, could you do a final review of this PR and merge it if OK? I'm working on a WIP to support |
src/uu/users/src/users.rs
Outdated
let entries = match parse_from_path(&filename) { | ||
Ok(data) => data, | ||
Err(_) => Vec::new(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more idiomatic to use unwrap_or
instead of a match
.
let entries = match parse_from_path(&filename) { | |
Ok(data) => data, | |
Err(_) => Vec::new(), | |
}; | |
let entries = parse_from_path(&filename).unwrap_or(Vec::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done as suggested.
src/uu/users/src/users.rs
Outdated
#[cfg(not(target_os = "openbsd"))] | ||
let default_path: &str = utmpx::DEFAULT_FILE; | ||
#[cfg(target_os = "openbsd")] | ||
let default_path: &str = "/var/log/wtmp"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a mismatch with the default path used in uumain
: /var/run/utmp
(my guess is that this is the correct path). It might make sense to define an OpenBSD specific const with the default path and then use this const in both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cakebaker , fixed this based on your comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the exception of the two details it looks good from my point of view.
OpenBSD uses the original utmp file format so the general `users` does not work there. By using the `utmp-classic` lib, we cna process the current users on the system from the /var/run/utmp and show the list. fixes uutils#5665
GNU testsuite comparison:
|
Thanks! |
OpenBSD uses the original utmp file format so the general
users
does not work there. By using theutmp-classic
lib, we cna process the current users on the system from the /var/run/utmp and show the list.fixes #5665