File xosview-1.16-coretemp2.patch of Package xosview

---
 linux/coretemp.cc |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 2 deletions(-)

--- linux/coretemp.cc
+++ linux/coretemp.cc	2015-02-03 13:52:45.786934745 +0100
@@ -1,5 +1,6 @@
 //
 //  Copyright (c) 2008-2014 by Tomi Tapper <tomi.o.tapper@jyu.fi>
+//  Copyright (c) 2015 by Werner Fink <werner@suse.de>
 //
 //  Read CPU temperature readings from /sys and display actual temperature.
 //  If actual >= high, actual temp changes color to indicate alarm.
@@ -32,7 +33,6 @@ static const char SYS_VIATEMP[] = "/sys/
 
 CoreTemp::CoreTemp( XOSView *parent, const char *label, const char *caption, int pkg, int cpu )
   : FieldMeter( parent, 3, label, caption, 1, 1, 1 ), _pkg(pkg), _cpu(cpu) {
-  metric_ = true;
   _high = 0;
 }
 
@@ -55,6 +55,7 @@ void CoreTemp::checkResources( void ) {
   if ( _cpus.empty() ) {  // should not happen at this point
     std::cerr << "BUG: Could not determine sysfs file(s) for coretemp." << std::endl;
     parent_->done(1);
+    return;
   }
 
   // Get TjMax and use it for total, if available.
@@ -111,6 +112,44 @@ void CoreTemp::findSysFiles( void ) {
   DIR *dir;
   struct dirent *dent;
 
+  if ((dir = opendir(SYS_HWMON))) {
+    while ( (dent = readdir(dir)) ) {
+      char *core, *path;
+      if ( !strncmp(dent->d_name, ".", 1) ||
+           !strncmp(dent->d_name, "..", 2) )
+        continue;
+      snprintf(name, PATH_SIZE, "%s/%s/device", SYS_HWMON, dent->d_name);
+      core = realpath(name, NULL);
+      if (!core)
+	break;
+      path = strrchr(core, '/');
+      if (path)
+	path++;
+      if (strncmp(path, "coretemp.", 9) == 0) {
+	path = strrchr(name, '/');
+	*path = '\0';
+	snprintf(path, PATH_SIZE - strlen(name), "/temp*_label");
+  	glob(name, 0, NULL, &gbuf);
+  	for (i = 0; i < gbuf.gl_pathc; i++) {
+    	  file.open(gbuf.gl_pathv[i]);
+	  if (file.good()) {
+    	    file >> dummy >> cpu;
+	    file.close();
+      	    strcpy(strrchr(gbuf.gl_pathv[i], '_'), "_input");
+	    if (_cpu < 0 || cpu == _cpu) {
+	      _cpus.push_back(gbuf.gl_pathv[i]);
+	    }
+	  }
+	}
+	globfree(&gbuf);
+      }
+      free(core);
+    }
+    closedir(dir);
+    if ( !_cpus.empty() )
+      return;
+  }
+
   // Intel and VIA CPUs.
   snprintf(name, PATH_SIZE, "%s.%d/temp*_label", SYS_CORETEMP, _pkg);
   glob(name, 0, NULL, &gbuf);
@@ -122,8 +161,9 @@ void CoreTemp::findSysFiles( void ) {
     file.close();
     if ( strncmp(dummy.c_str(), "Core", 4) == 0 ) {
       strcpy(strrchr(gbuf.gl_pathv[i], '_'), "_input");
-      if (_cpu < 0 || cpu == _cpu)
+      if (_cpu < 0 || cpu == _cpu) {
         _cpus.push_back(gbuf.gl_pathv[i]);
+      }
     }
   }
   globfree(&gbuf);
@@ -261,6 +301,42 @@ unsigned int CoreTemp::countCores( unsig
   std::string dummy;
   std::ifstream file;
 
+  if ((dir = opendir(SYS_HWMON))) {
+    while ( (dent = readdir(dir)) ) {
+      char *core, *path;
+      if ( !strncmp(dent->d_name, ".", 1) ||
+           !strncmp(dent->d_name, "..", 2) )
+        continue;
+      snprintf(s, PATH_SIZE, "%s/%s/device", SYS_HWMON, dent->d_name);
+      core = realpath(s, NULL);
+      if (!core)
+	break;
+      path = strrchr(core, '/');
+      if (path)
+	path++;
+      if (strncmp(path, "coretemp.", 9) == 0) {
+	path = strrchr(s, '/');
+	*path = '\0';
+	snprintf(path, PATH_SIZE - strlen(s), "/temp*_label");
+  	glob(s, 0, NULL, &gbuf);
+  	for (i = 0; i < gbuf.gl_pathc; i++) {
+    	  file.open(gbuf.gl_pathv[i]);
+	  if (file.good()) {
+    	    file >> dummy;
+	    file.close();
+    	    if (strncmp(dummy.c_str(), "Core", 4) == 0)
+	      count++;
+	  }
+	}
+	globfree(&gbuf);
+      }
+      free(core);
+    }
+    closedir(dir);
+    if (count > 0)
+      return count;
+  }
+
   // Intel or VIA CPU.
   snprintf(s, PATH_SIZE, "%s.%d/temp*_label", SYS_CORETEMP, pkg);
   glob(s, 0, NULL, &gbuf);
openSUSE Build Service is sponsored by