mirror of https://github.com/xzeldon/htop.git
sanity checks
This commit is contained in:
parent
f7fe4b4722
commit
978019d34f
|
@ -20,13 +20,16 @@ int LoadMeter_attributes[] = { LOAD };
|
||||||
|
|
||||||
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
|
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
|
||||||
int activeProcs, totalProcs, lastProc;
|
int activeProcs, totalProcs, lastProc;
|
||||||
|
*one = 0; *five = 0; *fifteen = 0;
|
||||||
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
||||||
|
if (fd) {
|
||||||
int total = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
|
int total = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
|
||||||
&activeProcs, &totalProcs, &lastProc);
|
&activeProcs, &totalProcs, &lastProc);
|
||||||
(void) total;
|
(void) total;
|
||||||
assert(total == 6);
|
assert(total == 6);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||||
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
|
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
|
||||||
|
|
|
@ -21,8 +21,10 @@ int UptimeMeter_attributes[] = {
|
||||||
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||||
double uptime = 0;
|
double uptime = 0;
|
||||||
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
||||||
|
if (fd) {
|
||||||
fscanf(fd, "%lf", &uptime);
|
fscanf(fd, "%lf", &uptime);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
}
|
||||||
int totalseconds = (int) ceil(uptime);
|
int totalseconds = (int) ceil(uptime);
|
||||||
int seconds = totalseconds % 60;
|
int seconds = totalseconds % 60;
|
||||||
int minutes = (totalseconds/60) % 60;
|
int minutes = (totalseconds/60) % 60;
|
||||||
|
|
Loading…
Reference in New Issue