Make have_proc_stat an ordinary function

Removes a mutable global variable.
This commit is contained in:
ridiculousfish 2019-05-12 14:59:30 -07:00
parent 5158ee812b
commit be41407610
5 changed files with 11 additions and 10 deletions

View file

@ -54,7 +54,7 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_
if (header) {
// Print table header before first job.
streams.out.append(_(L"Job\tGroup\t"));
if (have_proc_stat) {
if (have_proc_stat()) {
streams.out.append(_(L"CPU\t"));
}
streams.out.append(_(L"State\tCommand\n"));
@ -62,7 +62,7 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_
streams.out.append_format(L"%d\t%d\t", j->job_id, j->pgid);
if (have_proc_stat) {
if (have_proc_stat()) {
streams.out.append_format(L"%d%%\t", cpu_use(j));
}

View file

@ -219,10 +219,6 @@ void misc_init() {
fflush(stdout);
setvbuf(stdout, NULL, _IONBF, 0);
}
// Check for /proc/self/stat to see if we are running with Linux-style procfs
if (access("/proc/self/stat", R_OK) == 0) {
have_proc_stat = true;
}
}
/// Ensure the content of the magic path env vars is reasonable. Specifically, that empty path

View file

@ -59,7 +59,12 @@ bool is_breakpoint = false;
bool is_login = false;
int is_event = 0;
int no_exec = 0;
bool have_proc_stat = false;
bool have_proc_stat() {
// Check for /proc/self/stat to see if we are running with Linux-style procfs.
static const bool s_result = (access("/proc/self/stat", R_OK) == 0);
return s_result;
}
static relaxed_atomic_t<job_control_t> job_control_mode{job_control_t::interactive};
@ -623,7 +628,7 @@ bool job_reap(parser_t &parser, bool allow_interactive) {
/// Get the CPU time for the specified process.
unsigned long proc_get_jiffies(process_t *p) {
if (!have_proc_stat) return 0;
if (!have_proc_stat()) return 0;
if (p->pid <= 0) return 0;
wchar_t fn[FN_SIZE];

View file

@ -517,6 +517,6 @@ void add_disowned_pgid(pid_t pgid);
/// function
enum { INVALID_PID = -2 };
extern bool have_proc_stat;
bool have_proc_stat();
#endif

View file

@ -1963,7 +1963,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) {
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
parser.vars().set_one(L"_", ENV_GLOBAL, program_name);
if (have_proc_stat) {
if (have_proc_stat()) {
proc_update_jiffies(parser);
}
}