pf plugin: Remove the init() callback.
authorFlorian Forster <octo@collectd.org>
Thu, 13 Sep 2012 12:01:40 +0000 (14:01 +0200)
committerFlorian Forster <octo@collectd.org>
Thu, 13 Sep 2012 12:01:40 +0000 (14:01 +0200)
Instead check for a running PF in the read() callback.

src/pf.c

index 05b3cb5..4b5154d 100644 (file)
--- a/src/pf.c
+++ b/src/pf.c
@@ -63,6 +63,9 @@ static int pf_read (void)
 
        close(pfdev);
 
+       if (!status.running)
+               return (-1);
+
        for (i = 0; i < PFRES_MAX; i++)
                submit_counter("pf_counters", cnames[i], status.counters[i], 0);
        for (i = 0; i < LCNT_MAX; i++)
@@ -77,31 +80,7 @@ static int pf_read (void)
        return (0);
 }
 
-static int pf_init (void)
-{
-       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);
-       }
-
-       close(pfdev);
-       if (!status.running)
-               return (-1);
-
-       return (0);
-}
-
 void module_register (void)
 {
-       plugin_register_init("pf", pf_init);
        plugin_register_read("pf", pf_read);
 }