summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c31afff)
raw | patch | inline | side by side (parent: c31afff)
author | Michał Mirosław <mirq-linux@rere.qmqm.pl> | |
Sat, 21 Jun 2008 20:19:41 +0000 (22:19 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 24 Jun 2008 11:28:40 +0000 (13:28 +0200) |
src/common.c: Move walk_directory() from thermal plugin
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/thermal.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 3f6eecc363bde456e6dec8a96e79c14610e86031..39436178b65d736cbce4de17b5a7b741020a446c 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)
+{
+ 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 (!callback(ent->d_name))
+ ++ok;
+ }
+
+ closedir (dh);
+
+ return ok ? 0 : -1;
+}
+
+
diff --git a/src/common.h b/src/common.h
index d142679f6b908b3f562b32e2dd503068c0a2f396..ca34e7817b372be61cd486f031a94ad169c37879 100644 (file)
--- a/src/common.h
+++ b/src/common.h
notification_init (n, NOTIF_FAILURE, NULL, \
(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);
+
#endif /* COMMON_H */
diff --git a/src/thermal.c b/src/thermal.c
index 4af63bc0dcca09a57e6b3fcf1e2f3950c6ff91e3..29ea05f5d18641b261e731295ae70c79996017fc 100644 (file)
--- a/src/thermal.c
+++ b/src/thermal.c
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;
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
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);