#endif /* HAVE_IOKIT_IOKITLIB_H */
#if KERNEL_LINUX
-static int battery_read_acpi (const char *name)
+static int battery_read_acpi (const char *dir, const char *name,
+ void *user_data)
{
double current = INVALID_VALUE;
double voltage = INVALID_VALUE;
battery_submit ("0", "voltage", voltage);
}
- walk_directory (battery_acpi_dir, battery_read_acpi);
+ walk_directory (battery_acpi_dir, battery_read_acpi,
+ /* user_data = */ NULL);
#endif /* KERNEL_LINUX */
return (0);
} /* int notification_init */
-int walk_directory (const char *dir, dirwalk_callback_f callback)
+int walk_directory (const char *dir, dirwalk_callback_f callback,
+ void *user_data)
{
struct dirent *ent;
DIR *dh;
- int ok = 0;
+ int success;
+ int failure;
+
+ success = 0;
+ failure = 0;
if ((dh = opendir (dir)) == NULL)
{
char errbuf[1024];
- ERROR ("Cannot open '%s': %s", dir,
+ ERROR ("walk_directory: Cannot open '%s': %s", dir,
sstrerror (errno, errbuf, sizeof (errbuf)));
return -1;
}
while ((ent = readdir (dh)) != NULL)
{
+ int status;
+
if (ent->d_name[0] == '.')
continue;
- if (!callback(ent->d_name))
- ++ok;
+ status = (*callback) (dir, ent->d_name, user_data);
+ if (status != 0)
+ failure++;
+ else
+ success++;
}
closedir (dh);
- return ok ? 0 : -1;
+ if ((success == 0) && (failure > 0))
+ return (-1);
+ return (0);
}
int read_file_contents (const char *filename, char *buf, int bufsize)
(vl)->host, (vl)->plugin, (vl)->plugin_instance, \
(ds)->type, (vl)->type_instance)
-typedef int (*dirwalk_callback_f)(const char *filename);
-int walk_directory (const char *dir, dirwalk_callback_f callback);
+typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename,
+ void *user_data);
+int walk_directory (const char *dir, dirwalk_callback_f callback,
+ void *user_data);
int read_file_contents (const char *filename, char *buf, int bufsize);
#endif /* COMMON_H */
plugin_dispatch_values (&vl);
}
-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];
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];
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)