X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpf.c;h=976b32f8e15fad75a7a4787f8db15e48928411e7;hb=6ff08df6ba1de1ebd95f569d96f62f7e6e5d68e0;hp=b4d2a45863a54a12d3d128683bce6b4c5b157897;hpb=59fc91adb22eeaff143f629cd5e7727732708f6e;p=collectd.git diff --git a/src/pf.c b/src/pf.c index b4d2a458..976b32f8 100644 --- a/src/pf.c +++ b/src/pf.c @@ -15,39 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef TEST -#include "collectd.h" -#include "common.h" -#include "plugin.h" -#include "configfile.h" -#else -#include -typedef u_int64_t counter_t; -#endif - -#define PF_SOCKET "/dev/pf" - -struct pfdata { - int pd_dev; -}; - -static struct pfdata pd; +#include "pfcommon.h" static int pf_init(void); static int pf_read(void); @@ -80,16 +48,14 @@ pf_init(void) { struct pf_status status; - memset(&pd, '\0', sizeof(pd)); - - if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) { + if ((dev = open(PF_SOCKET, O_RDWR)) == -1) { return (-1); } - if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) { + if (ioctl(dev, DIOCGETSTATUS, &status) == -1) { return (-1); } - close(pd.pd_dev); + close(dev); if (!status.running) return (-1); @@ -106,14 +72,14 @@ pf_read(void) char *lnames[] = LCNT_NAMES; char *names[] = { "searches", "inserts", "removals" }; - if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) { + if ((dev = open(PF_SOCKET, O_RDWR)) == -1) { return (-1); } - if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) { + if (ioctl(dev, DIOCGETSTATUS, &status) == -1) { return (-1); } - close(pd.pd_dev); + close(dev); for (i = 0; i < PFRES_MAX; i++) submit_counter("pf_counters", cnames[i], status.counters[i]); for (i = 0; i < LCNT_MAX; i++) @@ -141,4 +107,3 @@ void module_register(void) { plugin_register_read("pf", pf_read); } #endif -