X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fthermal.c;h=93781328be182879748a7d23965f152ba37720a3;hb=6ddbe0026dea748db40ccc494b4f5048817b346a;hp=15bbcb91cd9799963c781b44f3bf859ba15dbfd1;hpb=9214ecbf1989684ba85a1f9a6fc684af37f861ae;p=collectd.git diff --git a/src/thermal.c b/src/thermal.c index 15bbcb91..93781328 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -42,32 +42,23 @@ enum dev_type { COOLING_DEV }; -static void thermal_submit (const char *plugin_instance, enum dev_type dt, double value) +static void thermal_submit (const char *plugin_instance, enum dev_type dt, + gauge_t value) { - value_list_t vl = dt == TEMP ? vl_temp_template : vl_state_template; + value_list_t vl = (dt == TEMP) ? vl_temp_template : vl_state_template; value_t vt; vt.gauge = value; vl.values = &vt; vl.time = time (NULL); - sstrncpy (vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); + sstrncpy (vl.plugin, "thermal", sizeof(vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, + sizeof(vl.plugin_instance)); + sstrncpy (vl.type, (dt == TEMP) ? "temperature" : "gauge", + sizeof (vl.type)); - plugin_dispatch_values (dt == TEMP ? "temperature" : "gauge", &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; + plugin_dispatch_values (&vl); } static int thermal_sysfs_device_read (const char *name) @@ -77,6 +68,9 @@ static int thermal_sysfs_device_read (const char *name) int len; int ok = 0; + 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))) return -1; @@ -125,6 +119,9 @@ static int thermal_procfs_device_read (const char *name) char data[1024]; int len; + if (device_list && ignorelist_match (device_list, name)) + return -1; + /** * rechot ~ # cat /proc/acpi/thermal_zone/THRM/temperature * temperature: 55 C @@ -216,40 +213,6 @@ static int thermal_config (const char *key, const char *value) return 0; } -static int walk_directory (const char *dir, int (*callback)(const char *dev)) -{ - struct dirent *ent; - DIR *dh; - int ok = 0; - - if ((dh = opendir (dir)) == NULL) - { - char errbuf[1024]; - ERROR ("Cannot open '%s': %s", dir, - sstrerror (errno, errbuf, sizeof (errbuf))); - return -1; - } - - while ((ent = readdir (dh)) != NULL) - { - if (ent->d_name[0] == '.') - continue; - - if (device_list) { - DEBUG ("thermal plugin: Checking ignorelist for '%s'", ent->d_name); - if (ignorelist_match (device_list, ent->d_name)) - continue; - } - - if (!callback(ent->d_name)) - ++ok; - } - - closedir (dh); - - return ok ? 0 : -1; -} - static int thermal_sysfs_read (void) { return walk_directory (dirname_sysfs, thermal_sysfs_device_read);