]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_cpu_temperature.c
Merge pull request #142 from tommie/incremental_multibatt
[i3/i3status] / src / print_cpu_temperature.c
index f60a5f6c128552e466ae9f1d1109db873262861b..fd2dd90c796f8e17890e1787ff4d66c85d80c476 100644 (file)
@@ -1,6 +1,7 @@
 // vim:ts=4:sw=4:expandtab
 #include <stdlib.h>
 #include <limits.h>
+#include <glob.h>
 #include <stdio.h>
 #include <string.h>
 #include <yajl/yajl_gen.h>
@@ -57,8 +58,19 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
 
     if (path == NULL)
         asprintf(&thermal_zone, THERMAL_ZONE, zone);
-    else
-        asprintf(&thermal_zone, path, zone);
+    else {
+        static glob_t globbuf;
+        if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
+            die("glob() failed\n");
+        if (globbuf.gl_pathc == 0) {
+            /* No glob matches, the specified path does not contain a wildcard. */
+            asprintf(&thermal_zone, path, zone);
+        } else {
+            /* glob matched, we take the first match and ignore the others */
+            asprintf(&thermal_zone, "%s", globbuf.gl_pathv[0]);
+        }
+        globfree(&globbuf);
+    }
 
     INSTANCE(thermal_zone);
 
@@ -261,9 +273,9 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
     OUTPUT_FULL_TEXT(buffer);
     return;
 error:
-#endif
     free(thermal_zone);
+#endif
 
-    OUTPUT_FULL_TEXT("cant read temp");
+    OUTPUT_FULL_TEXT("can't read temp");
     (void)fputs("i3status: Cannot read temperature. Verify that you have a thermal zone in /sys/class/thermal or disable the cpu_temperature module in your i3status config.\n", stderr);
 }