mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-17 20:26:18 +00:00
users: tool unsupported on OpenBSD
- utmpx not supported on OpenBSD - add src/uu/users/src/platform directory and platform/mod.rs for conditional compilation according to target_os - platform/openbsd.rs: implementation on OpenBSD (unsupported tool) - platform/unix.rs: implementation on other OS - src/uu/users/src/users.rs: use platform module for uucore::main function
This commit is contained in:
parent
8c6d722916
commit
fdd6ecb713
4 changed files with 87 additions and 41 deletions
14
src/uu/users/src/platform/mod.rs
Normal file
14
src/uu/users/src/platform/mod.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// This file is part of the uutils coreutils package.
|
||||||
|
//
|
||||||
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "openbsd"))]
|
||||||
|
mod unix;
|
||||||
|
#[cfg(not(target_os = "openbsd"))]
|
||||||
|
pub use self::unix::*;
|
||||||
|
|
||||||
|
#[cfg(target_os = "openbsd")]
|
||||||
|
mod openbsd;
|
||||||
|
#[cfg(target_os = "openbsd")]
|
||||||
|
pub use self::openbsd::*;
|
17
src/uu/users/src/platform/openbsd.rs
Normal file
17
src/uu/users/src/platform/openbsd.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// This file is part of the uutils coreutils package.
|
||||||
|
//
|
||||||
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
// Specific implementation for OpenBSD: tool unsupported (utmpx not supported)
|
||||||
|
|
||||||
|
use crate::uu_app;
|
||||||
|
|
||||||
|
use uucore::error::UResult;
|
||||||
|
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
let _matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
|
println!("unsupported command on OpenBSD");
|
||||||
|
Ok(())
|
||||||
|
}
|
53
src/uu/users/src/platform/unix.rs
Normal file
53
src/uu/users/src/platform/unix.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// This file is part of the uutils coreutils package.
|
||||||
|
//
|
||||||
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
// spell-checker:ignore (paths) wtmp
|
||||||
|
|
||||||
|
use crate::uu_app;
|
||||||
|
|
||||||
|
use std::ffi::OsString;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use uucore::error::UResult;
|
||||||
|
use uucore::utmpx::{self, Utmpx};
|
||||||
|
|
||||||
|
static ARG_FILES: &str = "files";
|
||||||
|
|
||||||
|
fn get_long_usage() -> String {
|
||||||
|
format!(
|
||||||
|
"Output who is currently logged in according to FILE.
|
||||||
|
If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
|
||||||
|
utmpx::DEFAULT_FILE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
let matches = uu_app()
|
||||||
|
.after_help(get_long_usage())
|
||||||
|
.try_get_matches_from(args)?;
|
||||||
|
|
||||||
|
let files: Vec<&Path> = matches
|
||||||
|
.get_many::<OsString>(ARG_FILES)
|
||||||
|
.map(|v| v.map(AsRef::as_ref).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let filename = if files.is_empty() {
|
||||||
|
utmpx::DEFAULT_FILE.as_ref()
|
||||||
|
} else {
|
||||||
|
files[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut users = Utmpx::iter_all_records_from(filename)
|
||||||
|
.filter(Utmpx::is_user_process)
|
||||||
|
.map(|ut| ut.user())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if !users.is_empty() {
|
||||||
|
users.sort();
|
||||||
|
println!("{}", users.join(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -5,57 +5,19 @@
|
||||||
|
|
||||||
// spell-checker:ignore (paths) wtmp
|
// spell-checker:ignore (paths) wtmp
|
||||||
|
|
||||||
use std::ffi::OsString;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use clap::builder::ValueParser;
|
use clap::builder::ValueParser;
|
||||||
use clap::{crate_version, Arg, Command};
|
use clap::{crate_version, Arg, Command};
|
||||||
use uucore::error::UResult;
|
|
||||||
use uucore::utmpx::{self, Utmpx};
|
|
||||||
use uucore::{format_usage, help_about, help_usage};
|
use uucore::{format_usage, help_about, help_usage};
|
||||||
|
|
||||||
|
mod platform;
|
||||||
|
|
||||||
const ABOUT: &str = help_about!("users.md");
|
const ABOUT: &str = help_about!("users.md");
|
||||||
const USAGE: &str = help_usage!("users.md");
|
const USAGE: &str = help_usage!("users.md");
|
||||||
|
|
||||||
static ARG_FILES: &str = "files";
|
static ARG_FILES: &str = "files";
|
||||||
|
|
||||||
fn get_long_usage() -> String {
|
|
||||||
format!(
|
|
||||||
"Output who is currently logged in according to FILE.
|
|
||||||
If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
|
|
||||||
utmpx::DEFAULT_FILE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
use platform::uumain;
|
||||||
let matches = uu_app()
|
|
||||||
.after_help(get_long_usage())
|
|
||||||
.try_get_matches_from(args)?;
|
|
||||||
|
|
||||||
let files: Vec<&Path> = matches
|
|
||||||
.get_many::<OsString>(ARG_FILES)
|
|
||||||
.map(|v| v.map(AsRef::as_ref).collect())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let filename = if files.is_empty() {
|
|
||||||
utmpx::DEFAULT_FILE.as_ref()
|
|
||||||
} else {
|
|
||||||
files[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut users = Utmpx::iter_all_records_from(filename)
|
|
||||||
.filter(Utmpx::is_user_process)
|
|
||||||
.map(|ut| ut.user())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
if !users.is_empty() {
|
|
||||||
users.sort();
|
|
||||||
println!("{}", users.join(" "));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn uu_app() -> Command {
|
pub fn uu_app() -> Command {
|
||||||
Command::new(uucore::util_name())
|
Command::new(uucore::util_name())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue