LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File xosview-1.9.2-procsys.patch of Package xosview (Project X11:Utilities)

--- linux/intmeter.cc
+++ linux/intmeter.cc	2012-02-08 11:59:17.001933755 +0100
@@ -3,7 +3,7 @@
 //
 //  This file may be distributed under terms of the GPL
 //
-
+#define USE_UNAME	1	// Use fast uname API
 #include "intmeter.h"
 #include "xosview.h"
 #include "cpumeter.h"
@@ -11,8 +11,9 @@
 #include <sstream>
 #include <map>
 #include <stdlib.h>
-
-
+#ifdef USE_UNAME
+# include <sys/utsname.h>
+#endif
 static const char *INTFILE     = "/proc/interrupts";
 static const char *VERSIONFILE = "/proc/version";
 
@@ -55,6 +56,7 @@ void IntMeter::checkResources( void ){
 }
 
 float IntMeter::getLinuxVersion(void) {
+#ifndef USE_UNAME
     std::ifstream vfile(VERSIONFILE);
     if (!vfile) {
       std::cerr << "Can not open file : " << VERSIONFILE << std::endl;
@@ -65,7 +67,12 @@ float IntMeter::getLinuxVersion(void) {
     float rval;
     vfile >> dump >> dump; // Drop the first two words
     vfile >> rval; // Drops everything but #.# (float regex)
-
+#else
+    struct utsname myosrelease;
+    char *myendptr;
+    uname(&myosrelease);
+    float rval = strtof(myosrelease.release, &myendptr);
+#endif
     return rval;
 }
 
--- linux/netmeter.cc
+++ linux/netmeter.cc	2012-02-01 09:11:43.109934021 +0000
@@ -22,6 +22,7 @@
 // its display.
 //-----------------------------------------------------------------------
 
+#define USE_UNAME	1	// Use fast uname API
 
 #include "netmeter.h"
 #include "xosview.h"
@@ -32,6 +33,9 @@
 #include <stdlib.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#ifdef USE_UNAME
+# include <sys/utsname.h>
+#endif
 #if defined(GNULIBC) || defined(__GLIBC__)
 #include <net/if.h>
 #else
@@ -59,6 +63,7 @@ NetMeter::~NetMeter( void ){
 
 void NetMeter::checkOSVersion(void)
     {
+#ifndef USE_UNAME
     std::ifstream ifs("/proc/sys/kernel/osrelease");
     if (!ifs)
         {
@@ -66,14 +71,22 @@ void NetMeter::checkOSVersion(void)
           << std::endl;
         exit(1);
         }
-
+#else
+    struct utsname myosrelease;
+    char *myendptr;
+#endif
     int major, minor;
     _bytesInDev = 0;
+#ifndef USE_UNAME
     ifs >> major;
     ifs.ignore(1);
     ifs >> minor;
     ifs.ignore(1);
-
+#else
+    uname(&myosrelease);
+    major=strtol(myosrelease.release, &myendptr, 10);
+    minor=strtol(myendptr+1, (char **)NULL, 10);
+#endif
     if (major > 2 || (major == 2 && minor >= 1))
         {
 	// check presence of iacct and oacct chains