Fix long/short cpu stat init

Fixes #1630.
This commit is contained in:
Brenden Matthews 2023-09-30 14:24:23 -04:00
parent 53973402b4
commit aac26b549e
3 changed files with 11 additions and 12 deletions

View File

@ -747,15 +747,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(diskiograph_write, &update_diskio) parse_diskiograph_arg(obj, arg);
obj->callbacks.graphval = &diskiographval_write;
#endif /* BUILD_GUI */
END OBJ(color, nullptr)
if (false
END OBJ(color, nullptr) if (false
#ifdef BUILD_GUI
|| out_to_gui(*state)
|| out_to_gui(*state)
#endif /* BUILD_GUI */
#ifdef BUILD_NCURSES
|| out_to_ncurses.get(*state)
|| out_to_ncurses.get(*state)
#endif /* BUILD_NCURSES */
) {
) {
Colour c = arg != nullptr ? parse_color(arg) : default_color.get(*state);
obj->data.l = c.to_argb32();
set_current_text_color(c);
@ -1058,9 +1057,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
* nothing else than just that, using an ugly switch(). */
if (strncmp(s, "top", 3) == EQUAL) {
if (parse_top_args(s, arg, obj) != 0) {
#ifdef __linux__
determine_longstat_file();
#endif
obj->cb_handle = create_cb_handle(update_top);
} else {
free(obj);

View File

@ -903,6 +903,10 @@ void determine_longstat_file(void) {
FILE *stat_fp;
static int reported = 0;
char buf[MAX_PROCSTAT_LINELEN + 1];
static int stat_initialized = 0;
/* only execute once */
if (stat_initialized) return;
if (!(stat_fp = open_file("/proc/stat", &reported))) return;
while (!feof(stat_fp) &&
@ -913,6 +917,7 @@ void determine_longstat_file(void) {
}
}
fclose(stat_fp);
stat_initialized = 1;
}
void get_cpu_count(void) {
@ -1000,6 +1005,7 @@ int update_stat(void) {
}
if (!stat_template) {
determine_longstat_file();
stat_template =
KFLAG_ISSET(KFLAG_IS_LONGSTAT) ? TMPL_LONGSTAT : TMPL_SHORTSTAT;
}
@ -1216,8 +1222,7 @@ static void get_dev_path(const char *dir, const char *dev, char *out_buf) {
if (name_fd < 0) {
snprintf(path, 512, "%s%s/device/name", dir, namelist[i]->d_name);
name_fd = open(path, O_RDONLY);
if (name_fd < 0)
continue;
if (name_fd < 0) continue;
}
size = read(name_fd, name, strlen(dev));
if (size < strlen(dev)) {

View File

@ -58,8 +58,6 @@ int update_stat(void);
void print_distribution(struct text_object *, char *, unsigned int);
void determine_longstat_file(void);
extern char e_iface[64];
extern char interfaces_arr[MAX_NET_INTERFACES][64];