Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
9 changes: 6 additions & 3 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ fn pline(possible_uid: Option<uid_t>) -> 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<uid_t>) -> io::Result<()> {
let uid = possible_uid.unwrap_or_else(getuid);
Expand All @@ -586,7 +587,8 @@ fn pline(possible_uid: Option<uid_t>) -> 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<()> {
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/uu/nohup/src/nohup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/uu/uptime/src/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, 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);
Expand Down
20 changes: 15 additions & 5 deletions src/uu/who/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
_ => {}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ pub struct FsUsage {

impl FsUsage {
#[cfg(unix)]
#[allow(clippy::unnecessary_cast)]
pub fn new(statvfs: StatFs) -> Self {
{
#[cfg(all(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/safe_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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"))]
Expand Down Expand Up @@ -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"))]
Expand Down
4 changes: 2 additions & 2 deletions src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
#[cfg(unix)]
#[cfg(not(target_os = "openbsd"))]
pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
use crate::utmpx::BOOT_TIME;
use crate::utmpx::Utmpx;
use libc::BOOT_TIME;
use std::fs::File;
use std::io::Read;

Expand Down Expand Up @@ -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| {
Expand Down
45 changes: 33 additions & 12 deletions src/uucore/src/lib/features/utmpx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Loading