mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
3e71f638bc
* fix(uucore): use sysctl kern.boottime on macOS as fallback for uptime If utmpx BOOT_TIME is unavailable, derive boot time via sysctl CTL_KERN.KERN_BOOTTIME to reduce intermittent macOS failures (e.g., #3621). Context (blame/history): -2774274cc2("uptime: Support files in uptime (#6400)"): added macOS utmpxname validation and non-fatal 'unknown uptime' fallback with tests (tests/by-util/test_uptime.rs). -920d29f703("uptime: add support for OpenBSD using utmp"): reorganized uptime.rs and solidified utmp/utmpx-driven paths. * test: add comprehensive macOS tests for sysctl kern.boottime fallback Add unit tests for sysctl boottime availability and get_uptime reliability on macOS, verifying the fallback mechanism works correctly when utmpx BOOT_TIME is unavailable. Add integration tests to ensure uptime command consistently succeeds on macOS with various flags (default, --since) and produces properly formatted output. Enhance documentation of the sysctl fallback code with detailed comments explaining why it exists, the issue it addresses (#3621), and comprehensive SAFETY comments for the unsafe sysctl call. All tests are properly gated with #[cfg(target_os = "macos")] to ensure they only run on macOS and don't interfere with other platforms. * refactor(uucore): replace unsafe sysctl with safe command-line approach for macOS boot time - Remove unsafe libc::sysctl() system call entirely - Replace with safe std::process::Command executing 'sysctl -n kern.boottime' - Parse sysctl output format to extract boot time seconds - Maintains same API and functionality while eliminating unsafe blocks - Addresses reviewer feedback to completely remove unsafe code