From e95c6a7731455136b68bbf075739506db8d5c447 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 13 Sep 2012 13:22:32 +0200 Subject: [PATCH] pf plugin: Rearrange functions to get rid of prototypes. * Add collectd specific includes. * Make global variables and functions static. * Remove main() function and associated code. --- src/pf.c | 96 +++++++++++++++++++++++++--------------------------------------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/src/pf.c b/src/pf.c index 93fb5002..05b3cb58 100644 --- a/src/pf.c +++ b/src/pf.c @@ -15,40 +15,32 @@ * 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; @@ -85,43 +77,31 @@ pf_read(void) 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 -- 2.11.0