File xosview-1.14-sysinfo.patch of Package xosview
--- Makefile
+++ Makefile 2013-04-29 08:42:51.505939256 +0000
@@ -3,6 +3,7 @@
AWK ?= awk
INSTALL ?= install
PLATFORM ?= linux
+USE_SYSCALLS ?= 0
# Installation paths
@@ -55,6 +56,9 @@ OBJS += linux/MeterMaker.o \
linux/acpitemp.o \
linux/coretemp.o
CPPFLAGS += -Ilinux/
+ifneq ($(USE_SYSCALLS),0)
+CPPFLAGS += -DUSE_SYSCALLS
+endif
endif
ifeq ($(PLATFORM), bsd)
--- linux/cpumeter.cc
+++ linux/cpumeter.cc 2013-04-29 08:35:58.533438954 +0000
@@ -13,6 +13,9 @@
#include <string>
#include <sstream>
#include <ctype.h>
+#if defined(USE_SYSCALLS) && (USE_SYSCALLS > 0)
+# include <sys/utsname.h>
+#endif
static const char STATFILENAME[] = "/proc/stat";
static const char VERSIONFILENAME[] = "/proc/sys/kernel/osrelease";
@@ -337,17 +340,23 @@ const char *CPUMeter::toUpper(const char
}
int CPUMeter::getkernelversion(void){
- std::ifstream f(VERSIONFILENAME);
- if (!f) {
- std::cerr << "Can not get kernel version from " << VERSIONFILENAME << "." << std::endl;
- exit(1);
- }
-
- std::string version;
- int major = 0, minor = 0, micro = 0;
-
- f >> version;
- sscanf(version.c_str(), "%d.%d.%d", &major, &minor, µ);
+ static int major = 0, minor = 0, micro = 0;
+ if (!major) {
+#if defined(USE_SYSCALLS) && (USE_SYSCALLS > 0)
+ struct utsname myosrelease;
+ uname(&myosrelease);
+ sscanf(myosrelease.release, "%d.%d.%d", &major, &minor, µ);
+#else
+ std::ifstream f(VERSIONFILENAME);
+ if (!f) {
+ std::cerr << "Can not get kernel version from " << VERSIONFILENAME << "." << std::endl;
+ exit(1);
+ }
- return ( major*1000000 + minor*1000 + micro);
+ std::string version;
+ f >> version;
+ sscanf(version.c_str(), "%d.%d.%d", &major, &minor, µ);
+#endif
+ }
+ return (major*1000000 + minor*1000 + micro);
}
--- linux/swapmeter.cc
+++ linux/swapmeter.cc 2013-04-29 08:37:12.613439241 +0000
@@ -9,6 +9,9 @@
#include <fstream>
#include <sstream>
#include <stdlib.h>
+#if defined(USE_SYSCALLS) && (USE_SYSCALLS > 0)
+# include <sys/sysinfo.h>
+#endif
static const char MEMFILENAME[] = "/proc/meminfo";
@@ -37,7 +40,25 @@ void SwapMeter::checkevent( void ){
drawfields();
}
+#if defined(USE_SYSCALLS) && (USE_SYSCALLS > 0)
+void SwapMeter::getswapinfo( void ){
+ struct sysinfo sinfo;
+ typeof (sinfo.mem_unit) unit;
+
+ sysinfo(&sinfo);
+ unit = (sinfo.mem_unit ? sinfo.mem_unit : 1);
+ total_ = (double)sinfo.totalswap * unit;
+ fields_[0] = (double)(sinfo.totalswap - sinfo.freeswap) * unit;
+
+ if ( total_ == 0 ){
+ total_ = 1;
+ fields_[0] = 0;
+ }
+ if (total_)
+ setUsed (fields_[0], total_);
+}
+#else
void SwapMeter::getswapinfo( void ){
std::ifstream meminfo( MEMFILENAME );
if ( !meminfo ){
@@ -78,3 +99,4 @@ void SwapMeter::getswapinfo( void ){
if (total_)
setUsed (fields_[0], total_);
}
+#endif