Skip to content

Commit

Permalink
Fix #164: Add Utmpx::is_active() as a workaround on BSD
Browse files Browse the repository at this point in the history
  • Loading branch information
starscouts committed Jun 30, 2024
1 parent e5cb3a4 commit 76285a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions coreutils_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "coreutils_core"
version = "0.1.1"
version = "0.1.2"
authors = [
"GrayJack <[email protected]>",
"Gab David <[email protected]>",
]
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"]
Expand Down
11 changes: 10 additions & 1 deletion coreutils_core/src/os/utmpx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 76285a2

Please sign in to comment.