commit 074fe29ac2db156f3e337d33706d168b55f6c434 from: Benjamin Stürz date: Thu Jul 25 12:40:47 2024 UTC bedstatus: fix linux backend commit - 1c6e3bba12887eb116f03ff72477cb1c0494cfc5 commit + 074fe29ac2db156f3e337d33706d168b55f6c434 blob - 369d994ba1c77bf6e935c97128eb318dac099588 blob + 04be504742757262058d46bc8fd422e8f239e547 --- bedstatus/linux.c +++ bedstatus/linux.c @@ -113,6 +113,9 @@ static bool cpu_usage (int *usage) total += diff.times[i]; } + if (total == 0) + return false; + *usage = 100 - 100 * diff.times[3] / total; old = new; return true; @@ -156,6 +159,10 @@ void init_backend (void) ncpu = get_nprocs_conf (); cpufreqs = calloc (ncpu, sizeof (FILE *)); + // disable buffering + setvbuf (meminfo, NULL, _IONBF, 0); + setvbuf (stat, NULL, _IONBF, 0); + for (int i = 0; i < ncpu; ++i) { snprintf (path, sizeof (path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i); cpufreqs[i] = fopen (path, "r");