summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ad2537)
raw | patch | inline | side by side (parent: 9ad2537)
author | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 11:22:32 +0000 (13:22 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 11:22:32 +0000 (13:22 +0200) |
* Add collectd specific includes.
* Make global variables and functions static.
* Remove main() function and associated code.
* Make global variables and functions static.
* Remove main() function and associated code.
src/pf.c | patch | blob | history |
diff --git a/src/pf.c b/src/pf.c
index 93fb500204424ccdcb788ca9831e17cead7cc97b..05b3cb588616db468f63fb90cbbe6a135200634c 100644 (file)
--- a/src/pf.c
+++ b/src/pf.c
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "pfcommon.h"
+#include "collectd.h"
+#include "plugin.h"
-static int pf_init(void);
-static int pf_read(void);
-static void submit_counter(const char *, const char *, counter_t, int);
+static char *pf_device = "/dev/pf";
-char *pf_device = "/dev/pf";
-
-int
-pf_init(void)
+static void submit_counter (char const *type, char const *inst,
+ counter_t val, _Bool usegauge)
{
- struct pf_status status;
- int pfdev = -1;
-
- if ((pfdev = open(pf_device, O_RDONLY)) == -1) {
- ERROR("unable to open %s", pf_device);
- return (-1);
- }
-
- if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) {
- ERROR("DIOCGETSTATUS: %i", pfdev);
- close(pfdev);
- return (-1);
- }
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
- close(pfdev);
- if (!status.running)
- return (-1);
+ if (usegauge)
+ values[0].gauge = val;
+ else
+ values[0].counter = val;
- return (0);
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "pf", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof(vl.type));
+ sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance));
+ plugin_dispatch_values(&vl);
}
-int
-pf_read(void)
+static int pf_read (void)
{
struct pf_status status;
int pfdev = -1;
return (0);
}
-void
-submit_counter(const char *type, const char *inst, counter_t val, int usegauge)
+static int pf_init (void)
{
-#ifndef TEST
- value_t values[1];
- value_list_t vl = VALUE_LIST_INIT;
+ struct pf_status status;
+ int pfdev = -1;
- if (usegauge)
- values[0].gauge = val;
- else
- values[0].counter = val;
+ if ((pfdev = open(pf_device, O_RDONLY)) == -1) {
+ ERROR("unable to open %s", pf_device);
+ return (-1);
+ }
- vl.values = values;
- vl.values_len = 1;
- sstrncpy (vl.host, hostname_g, sizeof (vl.host));
- sstrncpy (vl.plugin, "pf", sizeof (vl.plugin));
- sstrncpy (vl.type, type, sizeof(vl.type));
- sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance));
- plugin_dispatch_values(&vl);
-#else
- printf("%s.%s: %lld\n", type, inst, val);
-#endif
-}
+ if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) {
+ ERROR("DIOCGETSTATUS: %i", pfdev);
+ close(pfdev);
+ return (-1);
+ }
+
+ close(pfdev);
+ if (!status.running)
+ return (-1);
-#ifdef TEST
-int
-main(int argc, char *argv[])
-{
- if (pf_init())
- err(1, "pf_init");
- if (pf_read())
- err(1, "pf_read");
return (0);
}
-#else
-void module_register(void) {
+
+void module_register (void)
+{
plugin_register_init("pf", pf_init);
plugin_register_read("pf", pf_read);
}
-#endif