summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-11-27 19:41:14 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-11-27 19:41:14 -0200
commitca03094bb2d60c6ee1558bd2bcfb9038244b38cb (patch)
treec2cecf055fb8c769b2e3c96f4153dc1a57a9e39d
parent2dcdd87658cdc38b2df5535cce85976e963fbd30 (diff)
Make UptimeMeter cross-platform again.
-rw-r--r--Makefile.am10
-rw-r--r--UptimeMeter.c15
-rw-r--r--linux/Platform.c11
-rw-r--r--unsupported/Platform.c5
-rw-r--r--unsupported/Platform.h1
5 files changed, 26 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index 6374fafa..5ce4c23a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,7 +20,7 @@ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
-SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
+SignalsPanel.c String.c SwapMeter.c TasksMeter.c UptimeMeter.c TraceScreen.c \
UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c
@@ -30,17 +30,15 @@ CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
-TraceScreen.h UsersTable.h Vector.h Process.h AffinityPanel.h \
+UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h AffinityPanel.h \
HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h
if HTOP_LINUX
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
-linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c \
-linux/UptimeMeter.c
+linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
-linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h \
-linux/UptimeMeter.h
+linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h
endif
if HTOP_UNSUPPORTED
diff --git a/UptimeMeter.c b/UptimeMeter.c
index 9e288171..a033b171 100644
--- a/UptimeMeter.c
+++ b/UptimeMeter.c
@@ -6,12 +6,9 @@ in the source distribution for its full text.
*/
#include "UptimeMeter.h"
-
-#include "ProcessList.h"
+#include "Platform.h"
#include "CRT.h"
-#include <math.h>
-
/*{
#include "Meter.h"
}*/
@@ -21,13 +18,11 @@ int UptimeMeter_attributes[] = {
};
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
- double uptime = 0;
- FILE* fd = fopen(PROCDIR "/uptime", "r");
- if (fd) {
- fscanf(fd, "%64lf", &uptime);
- fclose(fd);
+ int totalseconds = Platform_getUptime();
+ if (totalseconds == -1) {
+ snprintf(buffer, len, "(unknown)");
+ return;
}
- int totalseconds = (int) ceil(uptime);
int seconds = totalseconds % 60;
int minutes = (totalseconds/60) % 60;
int hours = (totalseconds/3600) % 24;
diff --git a/linux/Platform.c b/linux/Platform.c
index d39e2e96..f6c88170 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -20,6 +20,8 @@ in the source distribution for its full text.
#include "ClockMeter.h"
#include "HostnameMeter.h"
+#include <math.h>
+
/*{
#include "Action.h"
}*/
@@ -67,3 +69,12 @@ MeterClass* Platform_meterTypes[] = {
NULL
};
+int Platform_getUptime() {
+ double uptime = 0;
+ FILE* fd = fopen(PROCDIR "/uptime", "r");
+ if (fd) {
+ fscanf(fd, "%64lf", &uptime);
+ fclose(fd);
+ }
+ int totalseconds = (int) floor(uptime);
+}
diff --git a/unsupported/Platform.c b/unsupported/Platform.c
index 5e568025..8d4b3a0d 100644
--- a/unsupported/Platform.c
+++ b/unsupported/Platform.c
@@ -14,6 +14,7 @@ in the source distribution for its full text.
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
+#include "UptimeMeter.h"
/*{
#include "Action.h"
@@ -33,6 +34,7 @@ MeterClass* Platform_meterTypes[] = {
&TasksMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &UptimeMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&LeftCPUsMeter_class,
@@ -43,3 +45,6 @@ MeterClass* Platform_meterTypes[] = {
NULL
};
+int Platform_getUptime() {
+ return -1;
+}
diff --git a/unsupported/Platform.h b/unsupported/Platform.h
index 1a2b81f0..026c45fb 100644
--- a/unsupported/Platform.h
+++ b/unsupported/Platform.h
@@ -15,5 +15,6 @@ void Platform_setBindings(Htop_Action* keys);
extern MeterClass* Platform_meterTypes[];
+int Platform_getUptime();
#endif

© 2014-2024 Faster IT GmbH | imprint | privacy policy