diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c
index 27eb987c94fec0c534a5e82417a36e904cbefee3..de42d0fa399035e0f2e3930866d2be670557fc72 100644 (file)
--- a/src/utils_ignorelist.c
+++ b/src/utils_ignorelist.c
/**
* collectd - src/utils_ignorelist.c
* Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ * Copyright (C) 2008 Florian Forster <octo at verplant.org>
*
* This program is free software; you can redistribute it and/
* or modify it under the terms of the GNU General Public Li-
*
* Authors:
* Lubos Stanek <lubek at users.sourceforge.net>
+ * Florian Forster <octo at verplant.org>
**/
/**
* ignorelist handles plugin's list of configured collectable
* return;
**/
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "common.h"
-#include "utils_debug.h"
+#include "plugin.h"
#include "utils_ignorelist.h"
/*
/* create buffer */
if ((regtemp = malloc(sizeof(regex_t))) == NULL)
{
- syslog (LOG_ERR, "cannot allocate new config entry");
+ ERROR ("cannot allocate new config entry");
return (1);
}
memset (regtemp, '\0', sizeof(regex_t));
{
fprintf (stderr, "Cannot compile regex %s: %i/%s",
entry, rcompile, regerr);
- syslog (LOG_ERR, "Cannot compile regex %s: %i/%s",
+ ERROR ("Cannot compile regex %s: %i/%s",
entry, rcompile, regerr);
}
else
{
fprintf (stderr, "Cannot compile regex %s: %i",
entry, rcompile);
- syslog (LOG_ERR, "Cannot compile regex %s: %i",
+ ERROR ("Cannot compile regex %s: %i",
entry, rcompile);
}
regfree (regtemp);
return (1);
}
- DBG("regex compiled: %s - %i", entry, rcompile);
+ DEBUG("regex compiled: %s - %i", entry, rcompile);
/* create new entry */
if ((new = malloc(sizeof(ignorelist_item_t))) == NULL)
{
- syslog (LOG_ERR, "cannot allocate new config entry");
+ ERROR ("cannot allocate new config entry");
regfree (regtemp);
return (1);
}
/* create new entry */
if ((new = malloc(sizeof(ignorelist_item_t))) == NULL )
{
- syslog (LOG_ERR, "cannot allocate new entry");
+ ERROR ("cannot allocate new entry");
return (1);
}
memset (new, '\0', sizeof(ignorelist_item_t));
/* smalloc exits if it failes */
il = (ignorelist_t *) smalloc (sizeof (ignorelist_t));
- DBG("Ignorelist created 0x%p, default is %s",
- (void *) il,
- invert ? "collect" : "ignore");
-
memset (il, '\0', sizeof (ignorelist_t));
/*
ignorelist_item_t *this;
ignorelist_item_t *next;
- DBG ("(il = 0x%p)", (void *) il);
-
if (il == NULL)
return;
{
if (il == NULL)
{
- DBG("ignore call with ignorelist_t == NULL");
+ DEBUG("ignore call with ignorelist_t == NULL");
return;
}
{
int ret;
size_t entry_len;
- char *entry_copy;
if (il == NULL)
{
- DBG ("add called with ignorelist_t == NULL");
+ DEBUG ("add called with ignorelist_t == NULL");
return (1);
}
/* append nothing */
if (entry_len == 0)
{
- DBG("not appending: empty entry");
+ DEBUG("not appending: empty entry");
return (1);
}
/* regex string is enclosed in "/.../" */
if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
{
+ char *entry_copy;
+ size_t entry_copy_size;
+
/* We need to copy `entry' since it's const */
- entry_copy = smalloc (entry_len);
- memset (entry_copy, '\0', entry_len);
- strncpy (entry_copy, entry + 1, entry_len - 2);
+ entry_copy_size = entry_len - 1;
+ entry_copy = smalloc (entry_copy_size);
+ sstrncpy (entry_copy, entry + 1, entry_copy_size);
- DBG("I'm about to add regex entry: %s", entry_copy);
+ DEBUG("I'm about to add regex entry: %s", entry_copy);
ret = ignorelist_append_regex(il, entry_copy);
sfree (entry_copy);
}
else
#endif
{
- DBG("to add entry: %s", entry);
+ DEBUG("to add entry: %s", entry);
ret = ignorelist_append_string(il, entry);
}
{
ignorelist_item_t *traverse;
- assert (il != NULL);
-
/* if no entries, collect all */
- if (il->head == NULL)
+ if ((il == NULL) || (il->head == NULL))
return (0);
if ((entry == NULL) || (strlen (entry) == 0))