proto/rwhod: improve de/serialization and datatypes
Build and test / build (push) Successful in 1m5s
Build and test / check (push) Failing after 1m23s
Build and test / test (push) Failing after 1m24s
Build and test / docs (push) Failing after 1m41s

This commit is contained in:
2026-01-04 20:16:59 +09:00
parent b12752bd17
commit 81cabd0723
8 changed files with 274 additions and 40 deletions
+10 -2
View File
@@ -1,5 +1,6 @@
use std::{collections::HashSet, net::IpAddr, path::Path};
use chrono::{Duration, Timelike};
use nix::{ifaddrs::getifaddrs, net::if_::InterfaceFlags, sys::stat::stat};
use uucore::utmpx::Utmpx;
@@ -19,8 +20,15 @@ pub fn generate_rwhod_user_entries() -> anyhow::Result<Vec<WhodUserEntry>> {
.ok_or_else(|| anyhow::anyhow!("Failed to convert login time to UTC"))?;
let idle_time = stat(&Path::new("/dev").join(entry.tty_device()))
.map(|st| (chrono::Utc::now().timestamp() - st.st_atime) as i32)
.unwrap_or(0);
.ok()
.and_then(|st| {
let last_active =
chrono::DateTime::<chrono::Utc>::from_timestamp_secs(st.st_atime)?;
let now = chrono::Utc::now().with_nanosecond(0)?;
Some(now - last_active)
})
.unwrap_or(Duration::zero());
Ok(WhodUserEntry::new(
entry.tty_device(),