summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2016-03-21 12:19:14 -0700
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2016-03-21 12:19:14 -0700
commitdbc59d7376dd1c49b4948d17209910fad01b3560 (patch)
tree3fdc5b5b5574f1593781f9cc75be7b93038c912d
parent132c35f6c9effbda3cf0e2cac80c9945b9d8d638 (diff)
parenta8aa5d608ce8ad1cffddd25cbc98d101a959a80a (diff)
Merge pull request #116 from eplanet/55_path_cputemp
Adding glob check to cpu temperature fixes #55
-rw-r--r--src/print_cpu_temperature.c16
1 files changed, 14 insertions, 2 deletions
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 <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);