Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #164: Add Utmpx::is_active() as a workaround on BSD #165

Merged
merged 2 commits into from
Jul 2, 2024
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
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/dev/coreutils_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
Loading