diff --git a/src/thermal.c b/src/thermal.c
index 29ea05f5d18641b261e731295ae70c79996017fc..fe54aee443790617b30c22915414bcd4c5123b5c 100644 (file)
--- a/src/thermal.c
+++ b/src/thermal.c
vt.gauge = value;
vl.values = &vt;
- vl.time = time (NULL);
sstrncpy (vl.plugin, "thermal", sizeof(vl.plugin));
sstrncpy (vl.plugin_instance, plugin_instance,
sizeof(vl.plugin_instance));
plugin_dispatch_values (&vl);
}
-static int read_file_contents (const char *filename, char *buf, int bufsize)
-{
- FILE *fh;
- int n;
-
- if ((fh = fopen (filename, "r")) == NULL)
- return -1;
-
- n = fread(buf, 1, bufsize, fh);
- fclose(fh);
-
- return n;
-}
-
-static int thermal_sysfs_device_read (const char *name)
+static int thermal_sysfs_device_read (const char __attribute__((unused)) *dir,
+ const char *name, void __attribute__((unused)) *user_data)
{
char filename[256];
char data[1024];
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));
}
}
- 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));
return ok ? 0 : -1;
}
-static int thermal_procfs_device_read (const char *name)
+static int thermal_procfs_device_read (const char __attribute__((unused)) *dir,
+ const char *name, void __attribute__((unused)) *user_data)
{
const char str_temp[] = "temperature:";
char filename[256];
* 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;
static int thermal_sysfs_read (void)
{
- return walk_directory (dirname_sysfs, thermal_sysfs_device_read);
+ return walk_directory (dirname_sysfs, thermal_sysfs_device_read,
+ /* user_data = */ NULL);
}
static int thermal_procfs_read (void)
{
- return walk_directory (dirname_procfs, thermal_procfs_device_read);
+ return walk_directory (dirname_procfs, thermal_procfs_device_read,
+ /* user_data = */ NULL);
}
static int thermal_init (void)