summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9a68f99)
raw | patch | inline | side by side (parent: 9a68f99)
author | Florian Forster <octo@collectd.org> | |
Thu, 28 Jul 2016 10:10:07 +0000 (12:10 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 28 Jul 2016 10:10:07 +0000 (12:10 +0200) |
src/match_empty_counter.c | patch | blob | history |
index caa3e7e302c000c342775e64665f5aa46ac3c6b0..bff9448a7e7dc273ad14931f8f2f01021f64e944 100644 (file)
/**
* collectd - src/match_empty_counter.c
- * Copyright (C) 2009 Florian Forster
+ * Copyright (C) 2009-2016 Florian Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "common.h"
#include "filter_chain.h"
-/*
- * private data types
- */
-struct mec_match_s;
-typedef struct mec_match_s mec_match_t;
-struct mec_match_s
-{
- int dummy;
-};
-
/*
* internal helper functions
*/
static int mec_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
{
- mec_match_t *m;
-
- m = calloc (1, sizeof (*m));
- if (m == NULL)
- {
- ERROR ("mec_create: calloc failed.");
- return (-ENOMEM);
- }
-
if (ci->children_num != 0)
{
ERROR ("empty_counter match: This match does not take any additional "
"configuration.");
}
- *user_data = m;
+ *user_data = NULL;
return (0);
} /* }}} int mec_create */
-static int mec_destroy (void **user_data) /* {{{ */
+static int mec_destroy (__attribute__((unused)) void **user_data) /* {{{ */
{
- if (user_data != NULL)
- {
- sfree (*user_data);
- }
-
return (0);
} /* }}} int mec_destroy */
-static int mec_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */
+static int mec_match (__attribute__((unused)) const data_set_t *ds, /* {{{ */
const value_list_t *vl,
- notification_meta_t __attribute__((unused)) **meta, void **user_data)
+ __attribute__((unused)) notification_meta_t **meta,
+ __attribute__((unused)) void **user_data)
{
- int num_counters;
- int num_empty;
+ int num_counters = 0;
+ int num_empty = 0;
size_t i;
- if ((user_data == NULL) || (*user_data == NULL))
- return (-1);
-
-
- num_counters = 0;
- num_empty = 0;
-
for (i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_DERIVE)
num_empty++;
}
- if (num_counters == 0)
- return (FC_MATCH_NO_MATCH);
- else if (num_counters == num_empty)
+ if ((num_counters != 0) && (num_counters == num_empty))
return (FC_MATCH_MATCHES);
- else
- return (FC_MATCH_NO_MATCH);
+
+ return (FC_MATCH_NO_MATCH);
} /* }}} int mec_match */
void module_register (void)
{
- match_proc_t mproc;
-
- memset (&mproc, 0, sizeof (mproc));
- mproc.create = mec_create;
- mproc.destroy = mec_destroy;
- mproc.match = mec_match;
- fc_register_match ("empty_counter", mproc);
+ fc_register_match ("empty_counter", (match_proc_t) {
+ .create = mec_create,
+ .destroy = mec_destroy,
+ .match = mec_match,
+ });
} /* module_register */
/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */