From: eplanet Date: Sun, 20 Mar 2016 10:47:56 +0000 (+0100) Subject: Adding glob check to cpu temperature fixes #55 X-Git-Tag: 2.11~40^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F116%2Fhead;p=i3%2Fi3status Adding glob check to cpu temperature fixes #55 --- diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 71ee4d4..fd2dd90 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -1,6 +1,7 @@ // vim:ts=4:sw=4:expandtab #include #include +#include #include #include #include @@ -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);