X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fthermal.c;h=b6136480c1e5036606f2e9730538e8c068d69e83;hb=074b4980bc75bea6826e6a38dcc6e193a721b2a8;hp=4af63bc0dcca09a57e6b3fcf1e2f3950c6ff91e3;hpb=ce07c14003240fcd63a8aa70c7261d14792fb76e;p=collectd.git diff --git a/src/thermal.c b/src/thermal.c index 4af63bc0..b6136480 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -61,27 +61,17 @@ static void thermal_submit (const char *plugin_instance, enum dev_type dt, 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 *dir, const char *name, + void *user_data) { char filename[256]; char data[1024]; 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; @@ -123,13 +113,17 @@ static int thermal_sysfs_device_read (const char *name) return ok ? 0 : -1; } -static int thermal_procfs_device_read (const char *name) +static int thermal_procfs_device_read (const char *dir, const char *name, + void *user_data) { const char str_temp[] = "temperature:"; char filename[256]; 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 @@ -221,48 +215,16 @@ 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); + 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)