mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-30 14:53:11 +00:00
Make have_proc_stat an ordinary function
Removes a mutable global variable.
This commit is contained in:
parent
5158ee812b
commit
be41407610
5 changed files with 11 additions and 10 deletions
|
@ -54,7 +54,7 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_
|
||||||
if (header) {
|
if (header) {
|
||||||
// Print table header before first job.
|
// Print table header before first job.
|
||||||
streams.out.append(_(L"Job\tGroup\t"));
|
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"CPU\t"));
|
||||||
}
|
}
|
||||||
streams.out.append(_(L"State\tCommand\n"));
|
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);
|
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));
|
streams.out.append_format(L"%d%%\t", cpu_use(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,10 +219,6 @@ void misc_init() {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
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
|
/// Ensure the content of the magic path env vars is reasonable. Specifically, that empty path
|
||||||
|
|
|
@ -59,7 +59,12 @@ bool is_breakpoint = false;
|
||||||
bool is_login = false;
|
bool is_login = false;
|
||||||
int is_event = 0;
|
int is_event = 0;
|
||||||
int no_exec = 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};
|
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.
|
/// Get the CPU time for the specified process.
|
||||||
unsigned long proc_get_jiffies(process_t *p) {
|
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;
|
if (p->pid <= 0) return 0;
|
||||||
|
|
||||||
wchar_t fn[FN_SIZE];
|
wchar_t fn[FN_SIZE];
|
||||||
|
|
|
@ -517,6 +517,6 @@ void add_disowned_pgid(pid_t pgid);
|
||||||
/// function
|
/// function
|
||||||
enum { INVALID_PID = -2 };
|
enum { INVALID_PID = -2 };
|
||||||
|
|
||||||
extern bool have_proc_stat;
|
bool have_proc_stat();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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`
|
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
|
||||||
parser.vars().set_one(L"_", ENV_GLOBAL, program_name);
|
parser.vars().set_one(L"_", ENV_GLOBAL, program_name);
|
||||||
|
|
||||||
if (have_proc_stat) {
|
if (have_proc_stat()) {
|
||||||
proc_update_jiffies(parser);
|
proc_update_jiffies(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue