summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c7d512b)
raw | patch | inline | side by side (parent: c7d512b)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 23 Aug 2008 12:35:24 +0000 (14:35 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 23 Aug 2008 12:35:24 +0000 (14:35 +0200) |
`walk_directory' in turn passes the directory name and the user data
back to the callback functions.
back to the callback functions.
src/battery.c | patch | blob | history | |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/thermal.c | patch | blob | history |
diff --git a/src/battery.c b/src/battery.c
index 9f1bee654e014812f254070a458f2be5a60508d3..416f3397d0e6c01da373ca17dfc8d48fac8ab03a 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
#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 */
diff --git a/src/common.c b/src/common.c
index fd7c19938e7119f1a9f8347059b9c4d85d86d04c..61a759b10b2c3dad4d85716ffe5ef1dd55979625 100644 (file)
--- a/src/common.c
+++ b/src/common.c
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)
diff --git a/src/common.h b/src/common.h
index 119cee6dcc2952cb640df0af01d4a63bed5420e2..f463b77e0c3b6f95707a4092d8f5310979ce3b5e 100644 (file)
--- a/src/common.h
+++ b/src/common.h
(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 */
diff --git a/src/thermal.c b/src/thermal.c
index 93781328be182879748a7d23965f152ba37720a3..b6136480c1e5036606f2e9730538e8c068d69e83 100644 (file)
--- a/src/thermal.c
+++ b/src/thermal.c
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)