diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 458ae5dc9ba..a08e4b0cc9a 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -308,7 +308,8 @@ fn set_supplemental_gids(gids: &[libc::gid_t]) -> std::io::Result<()> { target_vendor = "apple", target_os = "freebsd", target_os = "openbsd", - target_os = "cygwin" + target_os = "cygwin", + target_os = "netbsd" ))] let n = gids.len() as libc::c_int; #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 3ff281baa03..ff58c711647 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -562,7 +562,8 @@ fn pline(possible_uid: Option) -> io::Result<()> { target_os = "linux", target_os = "android", target_os = "openbsd", - target_os = "cygwin" + target_os = "cygwin", + target_os = "netbsd" ))] fn pline(possible_uid: Option) -> io::Result<()> { let uid = possible_uid.unwrap_or_else(getuid); @@ -586,7 +587,8 @@ fn pline(possible_uid: Option) -> io::Result<()> { target_os = "linux", target_os = "android", target_os = "openbsd", - target_os = "cygwin" + target_os = "cygwin", + target_os = "netbsd" ))] #[allow(clippy::unnecessary_wraps)] fn auditid() -> io::Result<()> { @@ -597,7 +599,8 @@ fn auditid() -> io::Result<()> { target_os = "linux", target_os = "android", target_os = "openbsd", - target_os = "cygwin" + target_os = "cygwin", + target_os = "netbsd" )))] fn auditid() -> io::Result<()> { use std::mem::MaybeUninit; diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 6280d44e1e3..b39f0251d1e 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -186,7 +186,8 @@ unsafe extern "C" { target_os = "android", target_os = "freebsd", target_os = "openbsd", - target_os = "cygwin" + target_os = "cygwin", + target_os = "netbsd" ))] /// # Safety /// This function is unsafe because it dereferences a raw pointer. diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index c9cdd3f5ae5..71ffd980d66 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -246,8 +246,8 @@ fn process_utmpx(file: Option<&OsString>) -> (Option, usize) { for line in records { match line.record_type() { - USER_PROCESS => nusers += 1, - BOOT_TIME => { + x if x == USER_PROCESS => nusers += 1, + x if x == BOOT_TIME => { let dt = line.login_time(); if dt.unix_timestamp() > 0 { boot_time = Some(dt.unix_timestamp() as time_t); diff --git a/src/uu/who/src/platform/unix.rs b/src/uu/who/src/platform/unix.rs index 0d6ba801363..a91f12fdeb8 100644 --- a/src/uu/who/src/platform/unix.rs +++ b/src/uu/who/src/platform/unix.rs @@ -235,11 +235,21 @@ impl Who { self.print_runlevel(&ut); } } - utmpx::BOOT_TIME if self.need_boottime => self.print_boottime(&ut), - utmpx::NEW_TIME if self.need_clockchange => self.print_clockchange(&ut), - utmpx::INIT_PROCESS if self.need_initspawn => self.print_initspawn(&ut), - utmpx::LOGIN_PROCESS if self.need_login => self.print_login(&ut), - utmpx::DEAD_PROCESS if self.need_deadprocs => self.print_deadprocs(&ut), + x if x == utmpx::BOOT_TIME && self.need_boottime => { + self.print_boottime(&ut); + } + x if x == utmpx::NEW_TIME && self.need_clockchange => { + self.print_clockchange(&ut); + } + x if x == utmpx::INIT_PROCESS && self.need_initspawn => { + self.print_initspawn(&ut); + } + x if x == utmpx::LOGIN_PROCESS && self.need_login => { + self.print_login(&ut); + } + x if x == utmpx::DEAD_PROCESS && self.need_deadprocs => { + self.print_deadprocs(&ut); + } _ => {} } } diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index fd1f3030307..5e10f2ea513 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -164,6 +164,7 @@ impl FileInformation { #[cfg(all(not(any(target_os = "netbsd")), target_pointer_width = "64"))] return self.0.st_ino; #[cfg(any(target_os = "netbsd", not(target_pointer_width = "64")))] + #[allow(clippy::useless_conversion)] return self.0.st_ino.into(); } } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 02dcbeb24d0..5eacc7a4c49 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -556,6 +556,7 @@ pub struct FsUsage { impl FsUsage { #[cfg(unix)] + #[allow(clippy::unnecessary_cast)] pub fn new(statvfs: StatFs) -> Self { { #[cfg(all( @@ -815,10 +816,12 @@ impl FsMeta for StatFs { } #[cfg(any(target_os = "linux", target_os = "android"))] + #[allow(clippy::unnecessary_cast)] fn io_size(&self) -> u64 { self.f_frsize as u64 } #[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] + #[allow(clippy::unnecessary_cast)] fn io_size(&self) -> u64 { #[cfg(target_os = "freebsd")] return self.f_iosize; @@ -864,6 +867,7 @@ impl FsMeta for StatFs { target_os = "android", target_os = "openbsd" )))] + #[allow(clippy::unnecessary_cast)] fn fsid(&self) -> u64 { self.f_fsid as u64 } @@ -877,6 +881,7 @@ impl FsMeta for StatFs { 1024 } #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] + #[allow(clippy::unnecessary_cast)] fn namelen(&self) -> u64 { self.f_namemax as u64 // spell-checker:disable-line } diff --git a/src/uucore/src/lib/features/safe_traversal.rs b/src/uucore/src/lib/features/safe_traversal.rs index 02ba632795a..98fc81dd928 100644 --- a/src/uucore/src/lib/features/safe_traversal.rs +++ b/src/uucore/src/lib/features/safe_traversal.rs @@ -707,7 +707,7 @@ impl std::os::unix::fs::MetadataExt for Metadata { fn atime_nsec(&self) -> i64 { #[cfg(target_os = "netbsd")] { - self.stat.st_atimensec as i64 + self.stat.st_atimensec } #[cfg(not(target_os = "netbsd"))] @@ -737,7 +737,7 @@ impl std::os::unix::fs::MetadataExt for Metadata { fn mtime_nsec(&self) -> i64 { #[cfg(target_os = "netbsd")] { - self.stat.st_mtimensec as i64 + self.stat.st_mtimensec } #[cfg(not(target_os = "netbsd"))] @@ -767,7 +767,7 @@ impl std::os::unix::fs::MetadataExt for Metadata { fn ctime_nsec(&self) -> i64 { #[cfg(target_os = "netbsd")] { - self.stat.st_ctimensec as i64 + self.stat.st_ctimensec } #[cfg(not(target_os = "netbsd"))] diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index 050107642c2..8366f69e2e1 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -136,8 +136,8 @@ pub fn get_uptime(_boot_time: Option) -> UResult { #[cfg(unix)] #[cfg(not(target_os = "openbsd"))] pub fn get_uptime(boot_time: Option) -> UResult { + use crate::utmpx::BOOT_TIME; use crate::utmpx::Utmpx; - use libc::BOOT_TIME; use std::fs::File; use std::io::Read; @@ -298,8 +298,8 @@ pub fn get_formatted_uptime( #[cfg(not(target_os = "openbsd"))] // see: https://gitlab.com/procps-ng/procps/-/blob/4740a0efa79cade867cfc7b32955fe0f75bf5173/library/uptime.c#L63-L115 pub fn get_nusers() -> usize { + use crate::utmpx::USER_PROCESS; use crate::utmpx::Utmpx; - use libc::USER_PROCESS; let mut num_user = 0; Utmpx::iter_all_records().for_each(|ut| { diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index cb9c2139156..6c538f3a7e8 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -172,15 +172,16 @@ mod ut { pub use libc::_UTX_USERSIZE as UT_NAMESIZE; pub use libc::ACCOUNTING; - pub use libc::DEAD_PROCESS; - pub use libc::EMPTY; - pub use libc::INIT_PROCESS; - pub use libc::LOGIN_PROCESS; - pub use libc::NEW_TIME; - pub use libc::OLD_TIME; - pub use libc::RUN_LVL; - pub use libc::SIGNATURE; - pub use libc::USER_PROCESS; + pub const BOOT_TIME: i16 = libc::BOOT_TIME as i16; + pub const DEAD_PROCESS: i16 = libc::DEAD_PROCESS as i16; + pub const EMPTY: i16 = libc::EMPTY as i16; + pub const INIT_PROCESS: i16 = libc::INIT_PROCESS as i16; + pub const LOGIN_PROCESS: i16 = libc::LOGIN_PROCESS as i16; + pub const NEW_TIME: i16 = libc::NEW_TIME as i16; + pub const OLD_TIME: i16 = libc::OLD_TIME as i16; + pub const RUN_LVL: i16 = libc::RUN_LVL as i16; + pub const SIGNATURE: i16 = libc::SIGNATURE as i16; + pub const USER_PROCESS: i16 = libc::USER_PROCESS as i16; } #[cfg(target_os = "cygwin")] @@ -207,10 +208,30 @@ pub struct Utmpx { inner: utmpx, } +#[cfg(target_os = "netbsd")] +impl Utmpx { + fn ut_type(&self) -> i16 { + self.inner.ut_type as i16 + } + fn ut_user(&self) -> String { + chars2string!(self.inner.ut_name) + } +} + +#[cfg(not(target_os = "netbsd"))] +impl Utmpx { + fn ut_type(&self) -> i16 { + self.inner.ut_type + } + fn ut_user(&self) -> String { + chars2string!(self.inner.ut_user) + } +} + impl Utmpx { /// A.K.A. ut.ut_type pub fn record_type(&self) -> i16 { - self.inner.ut_type + self.ut_type() } /// A.K.A. ut.ut_pid pub fn pid(&self) -> i32 { @@ -220,9 +241,9 @@ impl Utmpx { pub fn terminal_suffix(&self) -> String { chars2string!(self.inner.ut_id) } - /// A.K.A. ut.ut_user + /// A.K.A. ut.ut_user / ut.ut_name (NetBSD) pub fn user(&self) -> String { - chars2string!(self.inner.ut_user) + self.ut_user() } /// A.K.A. ut.ut_host pub fn host(&self) -> String {