summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bdcefed)
raw | patch | inline | side by side (parent: bdcefed)
author | Florian Forster <octo@collectd.org> | |
Wed, 5 Apr 2017 09:54:10 +0000 (11:54 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 5 Apr 2017 09:54:10 +0000 (11:54 +0200) |
The collectd daemon isn't using the "ignorelist" functionality itself --
it was only linked in to provide it to loaded plugins. Since the code is
under the GPL, this interfers with our intend of having an MIT licensed
daemon.
This patch changes the build system to link plugins with the ignorelist
directly instead of expecting the symbols to be in the daemon.
it was only linked in to provide it to loaded plugins. Since the code is
under the GPL, this interfers with our intend of having an MIT licensed
daemon.
This patch changes the build system to link plugins with the ignorelist
directly instead of expecting the symbols to be in the daemon.
Makefile.am | patch | blob | history | |
src/daemon/utils_ignorelist.c | [deleted file] | patch | blob | history |
src/daemon/utils_ignorelist.h | [deleted file] | patch | blob | history |
src/utils_ignorelist.c | [new file with mode: 0644] | patch | blob |
src/utils_ignorelist.h | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile.am b/Makefile.am
index c03347235e6a72437b73acae88a8f9e28af2bd8c..23e6a24f604ae0c6575a56e9d92a93bf6ac965a8 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
libformat_graphite.la \
libformat_json.la \
libheap.la \
+ libignorelist.la \
liblatency.la \
liblookup.la \
libmetadata.la \
src/daemon/utils_cache.h \
src/daemon/utils_complain.c \
src/daemon/utils_complain.h \
- src/daemon/utils_ignorelist.c \
- src/daemon/utils_ignorelist.h \
src/daemon/utils_llist.c \
src/daemon/utils_llist.h \
src/daemon/utils_random.c \
src/daemon/utils_heap.c \
src/daemon/utils_heap.h
+libignorelist_la_SOURCES = \
+ src/utils_ignorelist.c \
+ src/utils_ignorelist.h
+
libmetadata_la_SOURCES = \
src/daemon/meta_data.c \
src/daemon/meta_data.h
src/daemon/utils_cache_mock.c \
src/daemon/utils_complain.c \
src/daemon/utils_complain.h \
- src/daemon/utils_ignorelist.c \
- src/daemon/utils_ignorelist.h \
src/daemon/utils_time.c \
src/daemon/utils_time.h
libplugin_mock_la_CPPFLAGS = $(AM_CPPFLAGS) -DMOCK_TIME
-libplugin_mock_la_LIBADD = libcommon.la $(COMMON_LIBS)
+libplugin_mock_la_LIBADD = libcommon.la libignorelist.la $(COMMON_LIBS)
libformat_graphite_la_SOURCES = \
src/utils_format_graphite.c \
pkglib_LTLIBRARIES += cgroups.la
cgroups_la_SOURCES = src/cgroups.c
cgroups_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-cgroups_la_LIBADD = libmount.la
+cgroups_la_LIBADD = libignorelist.la libmount.la
endif
if BUILD_PLUGIN_CHRONY
pkglib_LTLIBRARIES += df.la
df_la_SOURCES = src/df.c
df_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-df_la_LIBADD = libmount.la
+df_la_LIBADD = libignorelist.la libmount.la
endif
if BUILD_PLUGIN_DISK
disk_la_CFLAGS = $(AM_CFLAGS)
disk_la_CPPFLAGS = $(AM_CPPFLAGS)
disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-disk_la_LIBADD =
+disk_la_LIBADD = libignorelist.la
if BUILD_WITH_LIBKSTAT
disk_la_LIBADD += -lkstat
endif
interface_la_SOURCES = src/interface.c
interface_la_CFLAGS = $(AM_CFLAGS)
interface_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-interface_la_LIBADD =
+interface_la_LIBADD = libignorelist.la
if BUILD_WITH_LIBSTATGRAB
interface_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
interface_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
ipmi_la_SOURCES = src/ipmi.c
ipmi_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_OPENIPMI_CFLAGS)
ipmi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-ipmi_la_LIBADD = $(BUILD_WITH_OPENIPMI_LIBS)
+ipmi_la_LIBADD = libignorelist.la $(BUILD_WITH_OPENIPMI_LIBS)
endif
if BUILD_PLUGIN_IPVS
pkglib_LTLIBRARIES += irq.la
irq_la_SOURCES = src/irq.c
irq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+irq_la_LIBADD = libignorelist.la
endif
if BUILD_PLUGIN_JAVA
src/madwifi.c \
src/madwifi.h
madwifi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+madwifi_la_LIBADD = libignorelist.la
endif
if BUILD_PLUGIN_MATCH_EMPTY_COUNTER
pkglib_LTLIBRARIES += md.la
md_la_SOURCES = src/md.c
md_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+md_la_LIBADD = libignorelist.la
endif
if BUILD_PLUGIN_MEMCACHEC
mic_la_SOURCES = src/mic.c
mic_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LDFLAGS)
-mic_la_LIBADD = $(BUILD_WITH_MIC_LIBS)
+mic_la_LIBADD = libignorelist.la $(BUILD_WITH_MIC_LIBS)
endif
if BUILD_PLUGIN_MODBUS
netapp_la_SOURCES = src/netapp.c
netapp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBNETAPP_CPPFLAGS)
netapp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBNETAPP_LDFLAGS)
-netapp_la_LIBADD = $(LIBNETAPP_LIBS)
+netapp_la_LIBADD = libignorelist.la $(LIBNETAPP_LIBS)
endif
if BUILD_PLUGIN_NETLINK
pkglib_LTLIBRARIES += onewire.la
onewire_la_SOURCES = src/onewire.c
onewire_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
-onewire_la_LIBADD = $(BUILD_WITH_LIBOWCAPI_LIBS)
onewire_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBOWCAPI_LDFLAGS)
+onewire_la_LIBADD = libignorelist.la $(BUILD_WITH_LIBOWCAPI_LIBS)
endif
if BUILD_PLUGIN_OPENLDAP
pkglib_LTLIBRARIES += protocols.la
protocols_la_SOURCES = src/protocols.c
protocols_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+protocols_la_LIBADD = libignorelist.la
endif
if BUILD_PLUGIN_REDIS
sensors_la_SOURCES = src/sensors.c
sensors_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBSENSORS_CPPFLAGS)
sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSENSORS_LDFLAGS)
-sensors_la_LIBADD = $(BUILD_WITH_LIBSENSORS_LIBS)
+sensors_la_LIBADD = libignorelist.la $(BUILD_WITH_LIBSENSORS_LIBS)
endif
if BUILD_PLUGIN_SERIAL
smart_la_SOURCES = src/smart.c
smart_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS) $(BUILD_WITH_LIBUDEV_CPPFLAGS)
smart_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBATASMART_LDFLAGS) $(BUILD_WITH_LIBUDEV_LDFLAGS)
-smart_la_LIBADD = $(BUILD_WITH_LIBATASMART_LIBS) $(BUILD_WITH_LIBUDEV_LIBS)
+smart_la_LIBADD = libignorelist.la $(BUILD_WITH_LIBATASMART_LIBS) $(BUILD_WITH_LIBUDEV_LIBS)
endif
endif
pkglib_LTLIBRARIES += thermal.la
thermal_la_SOURCES = src/thermal.c
thermal_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+thermal_la_LIBADD = libignorelist.la
endif
if BUILD_PLUGIN_THRESHOLD
virt_la_SOURCES = src/virt.c
virt_la_CFLAGS = $(AM_CFLAGS) \
$(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
-virt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
virt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+virt_la_LIBADD = libignorelist.la $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
# TODO: enable once we support only modern libvirts which depends on libnl-3
# the libvirt on wheezy is linked in libnl v1, and there is a small leak here,
diff --git a/src/daemon/utils_ignorelist.c b/src/daemon/utils_ignorelist.c
+++ /dev/null
@@ -1,309 +0,0 @@
-/**
- * collectd - src/utils_ignorelist.c
- * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- * Copyright (C) 2008 Florian Forster <octo at collectd.org>
- *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; either
- * version 2 of the Licence, or any later version.
- *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors:
- * Lubos Stanek <lubek at users.sourceforge.net>
- * Florian Forster <octo at collectd.org>
- **/
-/**
- * ignorelist handles plugin's list of configured collectable
- * entries with global ignore action
- **/
-/**
- * Usage:
- *
- * Define plugin's global pointer variable of type ignorelist_t:
- * ignorelist_t *myconfig_ignore;
- * If you know the state of the global ignore (IgnoreSelected),
- * allocate the variable with:
- * myconfig_ignore = ignorelist_create (YourKnownIgnore);
- * If you do not know the state of the global ignore,
- * initialize the global variable and set the ignore flag later:
- * myconfig_ignore = ignorelist_init ();
- * Append single entries in your cf_register'ed callback function:
- * ignorelist_add (myconfig_ignore, newentry);
- * When you hit the IgnoreSelected config option,
- * offer it to the list:
- * ignorelist_ignore (myconfig_ignore, instantly_got_value_of_ignore);
- * That is all for the ignorelist initialization.
- * Later during read and write (plugin's registered functions) get
- * the information whether this entry would be collected or not:
- * if (ignorelist_match (myconfig_ignore, thisentry))
- * return;
- **/
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "common.h"
-#include "plugin.h"
-#include "utils_ignorelist.h"
-
-/*
- * private prototypes
- */
-struct ignorelist_item_s {
-#if HAVE_REGEX_H
- regex_t *rmatch; /* regular expression entry identification */
-#endif
- char *smatch; /* string entry identification */
- struct ignorelist_item_s *next;
-};
-typedef struct ignorelist_item_s ignorelist_item_t;
-
-struct ignorelist_s {
- int ignore; /* ignore entries */
- ignorelist_item_t *head; /* pointer to the first entry */
-};
-
-/* *** *** *** ********************************************* *** *** *** */
-/* *** *** *** *** *** *** private functions *** *** *** *** *** *** */
-/* *** *** *** ********************************************* *** *** *** */
-
-static inline void ignorelist_append(ignorelist_t *il,
- ignorelist_item_t *item) {
- assert((il != NULL) && (item != NULL));
-
- item->next = il->head;
- il->head = item;
-}
-
-#if HAVE_REGEX_H
-static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) {
- regex_t *re;
- ignorelist_item_t *entry;
- int status;
-
- re = calloc(1, sizeof(*re));
- if (re == NULL) {
- ERROR("ignorelist_append_regex: calloc failed.");
- return (ENOMEM);
- }
-
- status = regcomp(re, re_str, REG_EXTENDED);
- if (status != 0) {
- char errbuf[1024];
- (void)regerror(status, re, errbuf, sizeof(errbuf));
- ERROR("utils_ignorelist: regcomp failed: %s", errbuf);
- ERROR("ignorelist_append_regex: Compiling regular expression \"%s\" "
- "failed: %s",
- re_str, errbuf);
- sfree(re);
- return (status);
- }
-
- entry = calloc(1, sizeof(*entry));
- if (entry == NULL) {
- ERROR("ignorelist_append_regex: calloc failed.");
- regfree(re);
- sfree(re);
- return (ENOMEM);
- }
- entry->rmatch = re;
-
- ignorelist_append(il, entry);
- return (0);
-} /* int ignorelist_append_regex */
-#endif
-
-static int ignorelist_append_string(ignorelist_t *il, const char *entry) {
- ignorelist_item_t *new;
-
- /* create new entry */
- if ((new = calloc(1, sizeof(*new))) == NULL) {
- ERROR("cannot allocate new entry");
- return (1);
- }
- new->smatch = sstrdup(entry);
-
- /* append new entry */
- ignorelist_append(il, new);
-
- return (0);
-} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
-
-#if HAVE_REGEX_H
-/*
- * check list for entry regex match
- * return 1 if found
- */
-static int ignorelist_match_regex(ignorelist_item_t *item, const char *entry) {
- assert((item != NULL) && (item->rmatch != NULL) && (entry != NULL) &&
- (strlen(entry) > 0));
-
- /* match regex */
- if (regexec(item->rmatch, entry, 0, NULL, 0) == 0)
- return (1);
-
- return (0);
-} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
-#endif
-
-/*
- * check list for entry string match
- * return 1 if found
- */
-static int ignorelist_match_string(ignorelist_item_t *item, const char *entry) {
- assert((item != NULL) && (item->smatch != NULL) && (entry != NULL) &&
- (strlen(entry) > 0));
-
- if (strcmp(entry, item->smatch) == 0)
- return (1);
-
- return (0);
-} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
-
-/* *** *** *** ******************************************** *** *** *** */
-/* *** *** *** *** *** *** public functions *** *** *** *** *** *** */
-/* *** *** *** ******************************************** *** *** *** */
-
-/*
- * create the ignorelist_t with known ignore state
- * return pointer to ignorelist_t
- */
-ignorelist_t *ignorelist_create(int invert) {
- ignorelist_t *il;
-
- il = calloc(1, sizeof(*il));
- if (il == NULL)
- return NULL;
-
- /*
- * ->ignore == 0 => collect
- * ->ignore == 1 => ignore
- */
- il->ignore = invert ? 0 : 1;
-
- return (il);
-} /* ignorelist_t *ignorelist_create (int ignore) */
-
-/*
- * free memory used by ignorelist_t
- */
-void ignorelist_free(ignorelist_t *il) {
- ignorelist_item_t *this;
- ignorelist_item_t *next;
-
- if (il == NULL)
- return;
-
- for (this = il->head; this != NULL; this = next) {
- next = this->next;
-#if HAVE_REGEX_H
- if (this->rmatch != NULL) {
- regfree(this->rmatch);
- sfree(this->rmatch);
- this->rmatch = NULL;
- }
-#endif
- if (this->smatch != NULL) {
- sfree(this->smatch);
- this->smatch = NULL;
- }
- sfree(this);
- }
-
- sfree(il);
-} /* void ignorelist_destroy (ignorelist_t *il) */
-
-/*
- * set ignore state of the ignorelist_t
- */
-void ignorelist_set_invert(ignorelist_t *il, int invert) {
- if (il == NULL) {
- DEBUG("ignore call with ignorelist_t == NULL");
- return;
- }
-
- il->ignore = invert ? 0 : 1;
-} /* void ignorelist_set_invert (ignorelist_t *il, int ignore) */
-
-/*
- * append entry into ignorelist_t
- * return 0 for success
- */
-int ignorelist_add(ignorelist_t *il, const char *entry) {
- size_t len;
-
- if (il == NULL) {
- DEBUG("add called with ignorelist_t == NULL");
- return (1);
- }
-
- len = strlen(entry);
-
- /* append nothing */
- if (len == 0) {
- DEBUG("not appending: empty entry");
- return (1);
- }
-
-#if HAVE_REGEX_H
- /* regex string is enclosed in "/.../" */
- if ((len > 2) && (entry[0] == '/') && entry[len - 1] == '/') {
- char *copy;
- int status;
-
- /* skip leading slash */
- copy = strdup(entry + 1);
- if (copy == NULL)
- return ENOMEM;
-
- /* trim trailing slash */
- copy[strlen(copy) - 1] = 0;
-
- status = ignorelist_append_regex(il, copy);
- sfree(copy);
- return status;
- }
-#endif
-
- return ignorelist_append_string(il, entry);
-} /* int ignorelist_add (ignorelist_t *il, const char *entry) */
-
-/*
- * check list for entry
- * return 1 for ignored entry
- */
-int ignorelist_match(ignorelist_t *il, const char *entry) {
- /* if no entries, collect all */
- if ((il == NULL) || (il->head == NULL))
- return (0);
-
- if ((entry == NULL) || (strlen(entry) == 0))
- return (0);
-
- /* traverse list and check entries */
- for (ignorelist_item_t *traverse = il->head; traverse != NULL;
- traverse = traverse->next) {
-#if HAVE_REGEX_H
- if (traverse->rmatch != NULL) {
- if (ignorelist_match_regex(traverse, entry))
- return (il->ignore);
- } else
-#endif
- {
- if (ignorelist_match_string(traverse, entry))
- return (il->ignore);
- }
- } /* for traverse */
-
- return (1 - il->ignore);
-} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
diff --git a/src/daemon/utils_ignorelist.h b/src/daemon/utils_ignorelist.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * collectd - src/utils_ignorelist.h
- * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; either
- * version 2 of the Licence, or any later version.
- *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors:
- * Lubos Stanek <lubek at users.sourceforge.net>
- **/
-/**
- * ignorelist handles plugin's list of configured collectable
- * entries with global ignore action
- **/
-
-#ifndef UTILS_IGNORELIST_H
-#define UTILS_IGNORELIST_H 1
-
-#include "collectd.h"
-
-#if HAVE_REGEX_H
-#include <regex.h>
-#endif
-
-/* public prototypes */
-
-struct ignorelist_s;
-typedef struct ignorelist_s ignorelist_t;
-
-/*
- * create the ignorelist_t with known ignore state
- * return pointer to ignorelist_t
- */
-ignorelist_t *ignorelist_create(int invert);
-
-/*
- * free memory used by ignorelist_t
- */
-void ignorelist_free(ignorelist_t *il);
-
-/*
- * set ignore state of the ignorelist_t
- */
-void ignorelist_set_invert(ignorelist_t *il, int invert);
-
-/*
- * append entry to ignorelist_t
- * returns zero on success, non-zero upon failure.
- */
-int ignorelist_add(ignorelist_t *il, const char *entry);
-
-/*
- * check list for entry
- * return 1 for ignored entry
- */
-int ignorelist_match(ignorelist_t *il, const char *entry);
-
-#endif /* UTILS_IGNORELIST_H */
diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c
--- /dev/null
+++ b/src/utils_ignorelist.c
@@ -0,0 +1,309 @@
+/**
+ * collectd - src/utils_ignorelist.c
+ * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ * Copyright (C) 2008 Florian Forster <octo at collectd.org>
+ *
+ * This program is free software; you can redistribute it and/
+ * or modify it under the terms of the GNU General Public Li-
+ * cence as published by the Free Software Foundation; either
+ * version 2 of the Licence, or any later version.
+ *
+ * This program is distributed in the hope that it will be use-
+ * ful, but WITHOUT ANY WARRANTY; without even the implied war-
+ * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Lubos Stanek <lubek at users.sourceforge.net>
+ * Florian Forster <octo at collectd.org>
+ **/
+/**
+ * ignorelist handles plugin's list of configured collectable
+ * entries with global ignore action
+ **/
+/**
+ * Usage:
+ *
+ * Define plugin's global pointer variable of type ignorelist_t:
+ * ignorelist_t *myconfig_ignore;
+ * If you know the state of the global ignore (IgnoreSelected),
+ * allocate the variable with:
+ * myconfig_ignore = ignorelist_create (YourKnownIgnore);
+ * If you do not know the state of the global ignore,
+ * initialize the global variable and set the ignore flag later:
+ * myconfig_ignore = ignorelist_init ();
+ * Append single entries in your cf_register'ed callback function:
+ * ignorelist_add (myconfig_ignore, newentry);
+ * When you hit the IgnoreSelected config option,
+ * offer it to the list:
+ * ignorelist_ignore (myconfig_ignore, instantly_got_value_of_ignore);
+ * That is all for the ignorelist initialization.
+ * Later during read and write (plugin's registered functions) get
+ * the information whether this entry would be collected or not:
+ * if (ignorelist_match (myconfig_ignore, thisentry))
+ * return;
+ **/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "common.h"
+#include "plugin.h"
+#include "utils_ignorelist.h"
+
+/*
+ * private prototypes
+ */
+struct ignorelist_item_s {
+#if HAVE_REGEX_H
+ regex_t *rmatch; /* regular expression entry identification */
+#endif
+ char *smatch; /* string entry identification */
+ struct ignorelist_item_s *next;
+};
+typedef struct ignorelist_item_s ignorelist_item_t;
+
+struct ignorelist_s {
+ int ignore; /* ignore entries */
+ ignorelist_item_t *head; /* pointer to the first entry */
+};
+
+/* *** *** *** ********************************************* *** *** *** */
+/* *** *** *** *** *** *** private functions *** *** *** *** *** *** */
+/* *** *** *** ********************************************* *** *** *** */
+
+static inline void ignorelist_append(ignorelist_t *il,
+ ignorelist_item_t *item) {
+ assert((il != NULL) && (item != NULL));
+
+ item->next = il->head;
+ il->head = item;
+}
+
+#if HAVE_REGEX_H
+static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) {
+ regex_t *re;
+ ignorelist_item_t *entry;
+ int status;
+
+ re = calloc(1, sizeof(*re));
+ if (re == NULL) {
+ ERROR("ignorelist_append_regex: calloc failed.");
+ return (ENOMEM);
+ }
+
+ status = regcomp(re, re_str, REG_EXTENDED);
+ if (status != 0) {
+ char errbuf[1024];
+ (void)regerror(status, re, errbuf, sizeof(errbuf));
+ ERROR("utils_ignorelist: regcomp failed: %s", errbuf);
+ ERROR("ignorelist_append_regex: Compiling regular expression \"%s\" "
+ "failed: %s",
+ re_str, errbuf);
+ sfree(re);
+ return (status);
+ }
+
+ entry = calloc(1, sizeof(*entry));
+ if (entry == NULL) {
+ ERROR("ignorelist_append_regex: calloc failed.");
+ regfree(re);
+ sfree(re);
+ return (ENOMEM);
+ }
+ entry->rmatch = re;
+
+ ignorelist_append(il, entry);
+ return (0);
+} /* int ignorelist_append_regex */
+#endif
+
+static int ignorelist_append_string(ignorelist_t *il, const char *entry) {
+ ignorelist_item_t *new;
+
+ /* create new entry */
+ if ((new = calloc(1, sizeof(*new))) == NULL) {
+ ERROR("cannot allocate new entry");
+ return (1);
+ }
+ new->smatch = sstrdup(entry);
+
+ /* append new entry */
+ ignorelist_append(il, new);
+
+ return (0);
+} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
+
+#if HAVE_REGEX_H
+/*
+ * check list for entry regex match
+ * return 1 if found
+ */
+static int ignorelist_match_regex(ignorelist_item_t *item, const char *entry) {
+ assert((item != NULL) && (item->rmatch != NULL) && (entry != NULL) &&
+ (strlen(entry) > 0));
+
+ /* match regex */
+ if (regexec(item->rmatch, entry, 0, NULL, 0) == 0)
+ return (1);
+
+ return (0);
+} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
+#endif
+
+/*
+ * check list for entry string match
+ * return 1 if found
+ */
+static int ignorelist_match_string(ignorelist_item_t *item, const char *entry) {
+ assert((item != NULL) && (item->smatch != NULL) && (entry != NULL) &&
+ (strlen(entry) > 0));
+
+ if (strcmp(entry, item->smatch) == 0)
+ return (1);
+
+ return (0);
+} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
+
+/* *** *** *** ******************************************** *** *** *** */
+/* *** *** *** *** *** *** public functions *** *** *** *** *** *** */
+/* *** *** *** ******************************************** *** *** *** */
+
+/*
+ * create the ignorelist_t with known ignore state
+ * return pointer to ignorelist_t
+ */
+ignorelist_t *ignorelist_create(int invert) {
+ ignorelist_t *il;
+
+ il = calloc(1, sizeof(*il));
+ if (il == NULL)
+ return NULL;
+
+ /*
+ * ->ignore == 0 => collect
+ * ->ignore == 1 => ignore
+ */
+ il->ignore = invert ? 0 : 1;
+
+ return (il);
+} /* ignorelist_t *ignorelist_create (int ignore) */
+
+/*
+ * free memory used by ignorelist_t
+ */
+void ignorelist_free(ignorelist_t *il) {
+ ignorelist_item_t *this;
+ ignorelist_item_t *next;
+
+ if (il == NULL)
+ return;
+
+ for (this = il->head; this != NULL; this = next) {
+ next = this->next;
+#if HAVE_REGEX_H
+ if (this->rmatch != NULL) {
+ regfree(this->rmatch);
+ sfree(this->rmatch);
+ this->rmatch = NULL;
+ }
+#endif
+ if (this->smatch != NULL) {
+ sfree(this->smatch);
+ this->smatch = NULL;
+ }
+ sfree(this);
+ }
+
+ sfree(il);
+} /* void ignorelist_destroy (ignorelist_t *il) */
+
+/*
+ * set ignore state of the ignorelist_t
+ */
+void ignorelist_set_invert(ignorelist_t *il, int invert) {
+ if (il == NULL) {
+ DEBUG("ignore call with ignorelist_t == NULL");
+ return;
+ }
+
+ il->ignore = invert ? 0 : 1;
+} /* void ignorelist_set_invert (ignorelist_t *il, int ignore) */
+
+/*
+ * append entry into ignorelist_t
+ * return 0 for success
+ */
+int ignorelist_add(ignorelist_t *il, const char *entry) {
+ size_t len;
+
+ if (il == NULL) {
+ DEBUG("add called with ignorelist_t == NULL");
+ return (1);
+ }
+
+ len = strlen(entry);
+
+ /* append nothing */
+ if (len == 0) {
+ DEBUG("not appending: empty entry");
+ return (1);
+ }
+
+#if HAVE_REGEX_H
+ /* regex string is enclosed in "/.../" */
+ if ((len > 2) && (entry[0] == '/') && entry[len - 1] == '/') {
+ char *copy;
+ int status;
+
+ /* skip leading slash */
+ copy = strdup(entry + 1);
+ if (copy == NULL)
+ return ENOMEM;
+
+ /* trim trailing slash */
+ copy[strlen(copy) - 1] = 0;
+
+ status = ignorelist_append_regex(il, copy);
+ sfree(copy);
+ return status;
+ }
+#endif
+
+ return ignorelist_append_string(il, entry);
+} /* int ignorelist_add (ignorelist_t *il, const char *entry) */
+
+/*
+ * check list for entry
+ * return 1 for ignored entry
+ */
+int ignorelist_match(ignorelist_t *il, const char *entry) {
+ /* if no entries, collect all */
+ if ((il == NULL) || (il->head == NULL))
+ return (0);
+
+ if ((entry == NULL) || (strlen(entry) == 0))
+ return (0);
+
+ /* traverse list and check entries */
+ for (ignorelist_item_t *traverse = il->head; traverse != NULL;
+ traverse = traverse->next) {
+#if HAVE_REGEX_H
+ if (traverse->rmatch != NULL) {
+ if (ignorelist_match_regex(traverse, entry))
+ return (il->ignore);
+ } else
+#endif
+ {
+ if (ignorelist_match_string(traverse, entry))
+ return (il->ignore);
+ }
+ } /* for traverse */
+
+ return (1 - il->ignore);
+} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
diff --git a/src/utils_ignorelist.h b/src/utils_ignorelist.h
--- /dev/null
+++ b/src/utils_ignorelist.h
@@ -0,0 +1,69 @@
+/**
+ * collectd - src/utils_ignorelist.h
+ * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/
+ * or modify it under the terms of the GNU General Public Li-
+ * cence as published by the Free Software Foundation; either
+ * version 2 of the Licence, or any later version.
+ *
+ * This program is distributed in the hope that it will be use-
+ * ful, but WITHOUT ANY WARRANTY; without even the implied war-
+ * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Lubos Stanek <lubek at users.sourceforge.net>
+ **/
+/**
+ * ignorelist handles plugin's list of configured collectable
+ * entries with global ignore action
+ **/
+
+#ifndef UTILS_IGNORELIST_H
+#define UTILS_IGNORELIST_H 1
+
+#include "collectd.h"
+
+#if HAVE_REGEX_H
+#include <regex.h>
+#endif
+
+/* public prototypes */
+
+struct ignorelist_s;
+typedef struct ignorelist_s ignorelist_t;
+
+/*
+ * create the ignorelist_t with known ignore state
+ * return pointer to ignorelist_t
+ */
+ignorelist_t *ignorelist_create(int invert);
+
+/*
+ * free memory used by ignorelist_t
+ */
+void ignorelist_free(ignorelist_t *il);
+
+/*
+ * set ignore state of the ignorelist_t
+ */
+void ignorelist_set_invert(ignorelist_t *il, int invert);
+
+/*
+ * append entry to ignorelist_t
+ * returns zero on success, non-zero upon failure.
+ */
+int ignorelist_add(ignorelist_t *il, const char *entry);
+
+/*
+ * check list for entry
+ * return 1 for ignored entry
+ */
+int ignorelist_match(ignorelist_t *il, const char *entry);
+
+#endif /* UTILS_IGNORELIST_H */