summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahgamut <41098605+ahgamut@users.noreply.github.com>2021-01-27 15:15:48 +0530
committerBenBE <BenBE@geshi.org>2021-01-31 20:08:09 +0100
commit51e79ddc07c0b3e070b5fe395703ce7ffe1878b9 (patch)
tree247d028a3be0a3e63ac64bd8bd1438647bf379e5
parent7bfa466abe65ff14d530ae16c344cdc06d5145ea (diff)
[#480] SysArchMeter to view kernel/arch info
At start, SysArchMeter calls the uname function to obtain the kernel version and architecture. If available, the distro version is obtained by calling lsb_release. The obtained values are stored in static variables and used when updating the meter.
-rw-r--r--Makefile.am2
-rw-r--r--SysArchMeter.c83
-rw-r--r--SysArchMeter.h14
-rw-r--r--darwin/Platform.c2
-rw-r--r--dragonflybsd/Platform.c2
-rw-r--r--freebsd/Platform.c2
-rw-r--r--linux/Platform.c2
-rw-r--r--openbsd/Platform.c2
-rw-r--r--solaris/Platform.c2
-rw-r--r--unsupported/Platform.c2
10 files changed, 113 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index e9ddbf02..e83773f9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,7 @@ myhtopsources = \
Settings.c \
SignalsPanel.c \
SwapMeter.c \
+ SysArchMeter.c \
TasksMeter.c \
TraceScreen.c \
UptimeMeter.c \
@@ -121,6 +122,7 @@ myhtopheaders = \
Settings.h \
SignalsPanel.h \
SwapMeter.h \
+ SysArchMeter.h \
TasksMeter.h \
TraceScreen.h \
UptimeMeter.h \
diff --git a/SysArchMeter.c b/SysArchMeter.c
new file mode 100644
index 00000000..083d079d
--- /dev/null
+++ b/SysArchMeter.c
@@ -0,0 +1,83 @@
+/*
+htop - SysArchMeter.c
+(C) 2021 htop dev team
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+#include "config.h" // IWYU pragma: keep
+
+#include "SysArchMeter.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+#include "XUtils.h"
+
+
+static const int SysArchMeter_attributes[] = {HOSTNAME};
+
+static void SysArchMeter_updateValues(Meter* this, char* buffer, size_t size) {
+ static struct utsname uname_info;
+ static int uname_result;
+ static char distro[3][64] = { {'\0'}, {'\0'}, {'\0'} };
+ static bool loaded_data = false;
+
+ (void)this;
+
+ if(!loaded_data) {
+ uname_result = uname(&uname_info);
+ FILE* fp = popen("lsb_release --id --release --codename", "r");
+ if(fp) {
+ char line[96] = {'\0'};
+ size_t n = 0;
+
+ while(fgets(line, sizeof(line), fp)) {
+ n = strcspn(line, ":");
+ if(n > 0 && (n + 1) < strlen(line)) {
+ char* value = String_trim(&line[n + 1]);
+ line[n] = '\0';
+
+ if(String_eq(line, "Distributor ID"))
+ snprintf(distro[0], sizeof(distro[0]), "%s", value);
+ else if(String_eq(line, "Release"))
+ snprintf(distro[1], sizeof(distro[1]), "%s", value);
+ else if(String_eq(line, "Codename"))
+ snprintf(distro[2], sizeof(distro[2]), "%s", value);
+
+ free(value);
+ }
+ }
+ if(!distro[0][0])
+ snprintf(distro[0], sizeof(distro[0]), "Unknown");
+ pclose(fp);
+ }
+ loaded_data = true;
+ }
+
+ if(uname_result == 0) {
+ if (distro[1][0] && distro[2][0])
+ snprintf(buffer, size, "%s %s [%s] / %s %s (%s)", uname_info.sysname, uname_info.release, uname_info.machine, distro[0], distro[1], distro[2]);
+ else if(distro[1][0])
+ snprintf(buffer, size, "%s %s [%s] / %s %s", uname_info.sysname, uname_info.release, uname_info.machine, distro[0], distro[1]);
+ else
+ snprintf(buffer, size, "%s %s [%s]", uname_info.sysname, uname_info.release, uname_info.machine);
+ } else {
+ snprintf(buffer, size, "Unknown");
+ }
+}
+
+const MeterClass SysArchMeter_class = {
+ .super = {
+ .extends = Class(Meter),
+ .delete = Meter_delete
+ },
+ .updateValues = SysArchMeter_updateValues,
+ .defaultMode = TEXT_METERMODE,
+ .maxItems = 0,
+ .total = 100.0,
+ .attributes = SysArchMeter_attributes,
+ .name = "System",
+ .uiName = "System",
+ .caption = "System: ",
+};
diff --git a/SysArchMeter.h b/SysArchMeter.h
new file mode 100644
index 00000000..fa6adfe3
--- /dev/null
+++ b/SysArchMeter.h
@@ -0,0 +1,14 @@
+#ifndef HEADER_SysArchMeter
+#define HEADER_SysArchMeter
+/*
+htop - SysArchMeter.h
+(C) 2021 htop dev team
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+#include "Meter.h"
+
+
+extern const MeterClass SysArchMeter_class;
+
+#endif
diff --git a/darwin/Platform.c b/darwin/Platform.c
index a4ed4647..d73cdcc7 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -31,6 +31,7 @@ in the source distribution for its full text.
#include "MemoryMeter.h"
#include "ProcessLocksScreen.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
#include "zfs/ZfsArcMeter.h"
@@ -93,6 +94,7 @@ const MeterClass* const Platform_meterTypes[] = {
&TasksMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&UptimeMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c
index 2abf4de3..08132716 100644
--- a/dragonflybsd/Platform.c
+++ b/dragonflybsd/Platform.c
@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "DateMeter.h"
#include "DateTimeMeter.h"
#include "HostnameMeter.h"
+#include "SysArchMeter.h"
#include "DragonFlyBSDProcess.h"
#include "DragonFlyBSDProcessList.h"
@@ -85,6 +86,7 @@ const MeterClass* const Platform_meterTypes[] = {
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&AllCPUs4Meter_class,
diff --git a/freebsd/Platform.c b/freebsd/Platform.c
index 934ca32f..9f8c051f 100644
--- a/freebsd/Platform.c
+++ b/freebsd/Platform.c
@@ -42,6 +42,7 @@ in the source distribution for its full text.
#include "ProcessList.h"
#include "Settings.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
#include "XUtils.h"
@@ -103,6 +104,7 @@ const MeterClass* const Platform_meterTypes[] = {
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&AllCPUs4Meter_class,
diff --git a/linux/Platform.c b/linux/Platform.c
index e5a87552..7bf93b17 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -49,6 +49,7 @@ in the source distribution for its full text.
#include "SELinuxMeter.h"
#include "Settings.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "SystemdMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
@@ -162,6 +163,7 @@ const MeterClass* const Platform_meterTypes[] = {
&LoadMeter_class,
&MemoryMeter_class,
&SwapMeter_class,
+ &SysArchMeter_class,
&HugePageMeter_class,
&TasksMeter_class,
&UptimeMeter_class,
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index 84a5e3d0..a50aa345 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -37,6 +37,7 @@ in the source distribution for its full text.
#include "Settings.h"
#include "SignalsPanel.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
#include "XUtils.h"
@@ -99,6 +100,7 @@ const MeterClass* const Platform_meterTypes[] = {
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&AllCPUs4Meter_class,
diff --git a/solaris/Platform.c b/solaris/Platform.c
index b3c83312..5f7f0edb 100644
--- a/solaris/Platform.c
+++ b/solaris/Platform.c
@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "DateMeter.h"
#include "DateTimeMeter.h"
#include "HostnameMeter.h"
+#include "SysArchMeter.h"
#include "UptimeMeter.h"
#include "zfs/ZfsArcMeter.h"
#include "zfs/ZfsCompressedArcMeter.h"
@@ -100,6 +101,7 @@ const MeterClass* const Platform_meterTypes[] = {
&TasksMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&UptimeMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
diff --git a/unsupported/Platform.c b/unsupported/Platform.c
index de231b5c..f32b7660 100644
--- a/unsupported/Platform.c
+++ b/unsupported/Platform.c
@@ -21,6 +21,7 @@ in the source distribution for its full text.
#include "Macros.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
@@ -45,6 +46,7 @@ const MeterClass* const Platform_meterTypes[] = {
&TasksMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&UptimeMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,

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