Minor cleanups to platform-specific init and done

Move platform-specific code out of the htop.c main function
and into the platform sub-directories - primarily this is
the Linux procfs path check and sensors setup/teardown; not
needed on any other platforms.  No functional changes here.
This commit is contained in:
Nathan Scott
2020-11-19 12:32:07 +11:00
parent 329011bb98
commit c75c5ef9c6
15 changed files with 157 additions and 86 deletions

View File

@ -56,11 +56,12 @@ in the source distribution for its full text.
#include "zfs/ZfsArcStats.h"
#include "zfs/ZfsCompressedArcMeter.h"
#ifdef HAVE_LIBSENSORS
#include <sensors/sensors.h>
#endif
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
int Platform_numberOfFields = LAST_PROCESSFIELD;
const SignalItem Platform_signals[] = {
@ -107,6 +108,22 @@ static time_t Platform_Battery_cacheTime;
static double Platform_Battery_cacheLevel = NAN;
static ACPresence Platform_Battery_cacheIsOnAC;
void Platform_init(void) {
if (access(PROCDIR, R_OK) != 0) {
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
exit(1);
}
#ifdef HAVE_LIBSENSORS
sensors_init(NULL);
#endif
}
void Platform_done(void) {
#ifdef HAVE_LIBSENSORS
sensors_cleanup();
#endif
}
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
Panel* panel = st->panel;