X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fthermal.c;h=b9d07bf5ce22fcacd55f5dcac729e4ad665b12d5;hb=96c474f576c721c6d993025b99c55de375552259;hp=2ea6a24fb916719937376556f0bc8d3f6d3d7f41;hpb=b72d521340383b6418fa6a75faca3bc45f06b14a;p=collectd.git diff --git a/src/thermal.c b/src/thermal.c index 2ea6a24f..b9d07bf5 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -71,8 +71,9 @@ static int thermal_sysfs_device_read (const char __attribute__((unused)) *dir, if (device_list && ignorelist_match (device_list, name)) return -1; - len = snprintf (filename, sizeof (filename), "%s/%s/temp", dirname_sysfs, name); - if ((len < 0) || ((unsigned int)len >= sizeof (filename))) + len = snprintf (filename, sizeof (filename), + "%s/%s/temp", dirname_sysfs, name); + if ((len < 0) || ((size_t) len >= sizeof (filename))) return -1; len = read_file_contents (filename, data, sizeof(data)); @@ -90,8 +91,9 @@ static int thermal_sysfs_device_read (const char __attribute__((unused)) *dir, } } - len = snprintf (filename, sizeof (filename), "%s/%s/cur_state", dirname_sysfs, name); - if ((len < 0) || ((unsigned int)len >= sizeof (filename))) + len = snprintf (filename, sizeof (filename), + "%s/%s/cur_state", dirname_sysfs, name); + if ((len < 0) || ((size_t) len >= sizeof (filename))) return -1; len = read_file_contents (filename, data, sizeof(data)); @@ -128,12 +130,15 @@ static int thermal_procfs_device_read (const char __attribute__((unused)) *dir, * temperature: 55 C */ - len = snprintf (filename, sizeof (filename), "%s/%s/temperature", dirname_procfs, name); - if ((len < 0) || ((unsigned int)len >= sizeof (filename))) + len = snprintf (filename, sizeof (filename), + "%s/%s/temperature", dirname_procfs, name); + if ((len < 0) || ((size_t) len >= sizeof (filename))) return -1; len = read_file_contents (filename, data, sizeof(data)); - if (len > sizeof(str_temp) && data[--len] == '\n' && !strncmp(data, str_temp, sizeof(str_temp)-1)) { + if ((len > 0) && ((size_t) len > sizeof(str_temp)) + && (data[--len] == '\n') + && (! strncmp(data, str_temp, sizeof(str_temp)-1))) { char *endptr = NULL; double temp; double celsius, add; @@ -193,17 +198,13 @@ static int thermal_config (const char *key, const char *value) else if (strcasecmp (key, "IgnoreSelected") == 0) { ignorelist_set_invert (device_list, 1); - if ((strcasecmp (value, "True") == 0) - || (strcasecmp (value, "Yes") == 0) - || (strcasecmp (value, "On") == 0)) + if (IS_TRUE (value)) ignorelist_set_invert (device_list, 0); } else if (strcasecmp (key, "ForceUseProcfs") == 0) { force_procfs = 0; - if ((strcasecmp (value, "True") == 0) - || (strcasecmp (value, "Yes") == 0) - || (strcasecmp (value, "On") == 0)) + if (IS_TRUE (value)) force_procfs = 1; } else @@ -217,13 +218,13 @@ static int thermal_config (const char *key, const char *value) static int thermal_sysfs_read (void) { return walk_directory (dirname_sysfs, thermal_sysfs_device_read, - /* user_data = */ NULL); + /* user_data = */ NULL, /* include hidden */ 0); } static int thermal_procfs_read (void) { return walk_directory (dirname_procfs, thermal_procfs_device_read, - /* user_data = */ NULL); + /* user_data = */ NULL, /* include hidden */ 0); } static int thermal_init (void)