From 76285a2e4859d10c6e92f1efc9462aa24a831d2b Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Sun, 30 Jun 2024 10:12:15 +0200 Subject: [PATCH 1/2] Fix #164: Add `Utmpx::is_active()` as a workaround on BSD --- coreutils_core/Cargo.toml | 4 ++-- coreutils_core/src/os/utmpx.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/coreutils_core/Cargo.toml b/coreutils_core/Cargo.toml index 198fbb74..5ee07316 100644 --- a/coreutils_core/Cargo.toml +++ b/coreutils_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "coreutils_core" -version = "0.1.1" +version = "0.1.2" authors = [ "GrayJack ", "Gab David ", @@ -8,7 +8,7 @@ authors = [ description = "A crate with abstractions to implement UNIX core utilities" readme = "README.md" license = "MPL-2.0-no-copyleft-exception" -repository = "https://github.com/GrayJack/coreutils/coreutils_core" +repository = "https://github.com/GrayJack/coreutils/tree/devcoreutils_core" documentation = "https://docs.rs/coreutils_core" homepage = "https://crates.io/crates/coreutils_core" keywords = ["unix", "coreutils"] diff --git a/coreutils_core/src/os/utmpx.rs b/coreutils_core/src/os/utmpx.rs index b3976f14..86f62a59 100644 --- a/coreutils_core/src/os/utmpx.rs +++ b/coreutils_core/src/os/utmpx.rs @@ -14,7 +14,7 @@ use std::{ error::Error as StdError, fmt::{self, Display}, io, - path::Path, + path::{Path, PathBuf}, }; #[cfg(not(any( target_os = "linux", @@ -196,6 +196,15 @@ impl Utmpx { pub const fn timeval(&self) -> TimeVal { self.timeval } + + /// Check if the device name of the entry is really active. Works around a quirk of + /// BSD systems where the entry type would be USER_PROCESS after it gets killed. + #[inline] + pub fn is_active(&self) -> bool { + let mut path = PathBuf::from("/dev"); + path.push(&self.line.to_string()); + path.exists() + } /// Get the time where the entry was created (often login time) in a more complete /// structure. From d0dc9ebf1af4b65ed6666194949e7d41dc8c3524 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Sun, 30 Jun 2024 10:17:35 +0200 Subject: [PATCH 2/2] Fix a small typo in coreutils_core/Cargo.toml --- coreutils_core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils_core/Cargo.toml b/coreutils_core/Cargo.toml index 5ee07316..c5effb18 100644 --- a/coreutils_core/Cargo.toml +++ b/coreutils_core/Cargo.toml @@ -8,7 +8,7 @@ authors = [ description = "A crate with abstractions to implement UNIX core utilities" readme = "README.md" license = "MPL-2.0-no-copyleft-exception" -repository = "https://github.com/GrayJack/coreutils/tree/devcoreutils_core" +repository = "https://github.com/GrayJack/coreutils/tree/dev/coreutils_core" documentation = "https://docs.rs/coreutils_core" homepage = "https://crates.io/crates/coreutils_core" keywords = ["unix", "coreutils"]