From efbf8b02039931ce378bc31c7fd93f93c868f139 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 13 Jan 2026 01:45:26 +0000 Subject: [PATCH] Inline `have_proc_stat` Closes #12319 --- src/builtins/jobs.rs | 6 +++--- src/proc.rs | 11 ++++------- src/reader/reader.rs | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/builtins/jobs.rs b/src/builtins/jobs.rs index cbfd2b7d3..eba37b746 100644 --- a/src/builtins/jobs.rs +++ b/src/builtins/jobs.rs @@ -6,7 +6,7 @@ use crate::job_group::{JobId, MaybeJobId}; use crate::localization::{wgettext, wgettext_fmt}; use crate::parser::Parser; -use crate::proc::{Job, clock_ticks_to_seconds, have_proc_stat, proc_get_jiffies}; +use crate::proc::{HAVE_PROC_STAT, Job, clock_ticks_to_seconds, proc_get_jiffies}; use crate::wgetopt::{ArgType, WGetopter, WOption, wopt}; use crate::wutil::fish_wcstoi; use fish_widestring::{L, WExt, WString, wstr}; @@ -53,7 +53,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut if header { // Print table header before first job. out += wgettext!("Job\tGroup\t"); - if have_proc_stat() { + if *HAVE_PROC_STAT { out += wgettext!("CPU\t"); } out += wgettext!("State\tCommand\n"); @@ -61,7 +61,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut sprintf!(=> &mut out, "%d\t%s\t", j.job_id(), pgid); - if have_proc_stat() { + if *HAVE_PROC_STAT { sprintf!(=> &mut out, "%.0f%%\t", 100.0 * cpu_use(j)); } diff --git a/src/proc.rs b/src/proc.rs index a67db666f..a7ae0c529 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -1010,7 +1010,7 @@ pub fn print_exit_warning_for_jobs(jobs: &JobList) { /// Use the procfs filesystem to look up how many jiffies of cpu time was used by a given pid. This /// function is only available on systems with the procfs file entry 'stat', i.e. Linux. pub fn proc_get_jiffies(inpid: Pid) -> ClockTicks { - if !have_proc_stat() { + if !*HAVE_PROC_STAT { return 0; } @@ -1609,12 +1609,9 @@ fn process_clean_after_marking(parser: &Parser, interactive: bool) -> bool { printed } -pub fn have_proc_stat() -> bool { - // Check for /proc/self/stat to see if we are running with Linux-style procfs. - static HAVE_PROC_STAT_RESULT: LazyLock = - LazyLock::new(|| fs::metadata("/proc/self/stat").is_ok()); - *HAVE_PROC_STAT_RESULT -} +/// Check for /proc/self/stat to see if we are running with Linux-style procfs. +pub static HAVE_PROC_STAT: LazyLock = + LazyLock::new(|| fs::metadata("/proc/self/stat").is_ok()); /// The signals that signify crashes to us. const CRASHSIGNALS: [libc::c_int; 6] = [SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGSYS]; diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 16aa7845f..ac7139641 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -116,7 +116,7 @@ use crate::parser::{BlockType, EvalRes, Parser}; use crate::prelude::*; use crate::proc::{ - have_proc_stat, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit, + HAVE_PROC_STAT, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit, print_exit_warning_for_jobs, proc_update_jiffies, }; use crate::screen::is_dumb; @@ -6321,7 +6321,7 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes { // Provide value for `status current-commandline` parser.libdata_mut().status_vars.commandline = L!("").to_owned(); - if have_proc_stat() { + if *HAVE_PROC_STAT { proc_update_jiffies(parser); }