summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a60a9b)
raw | patch | inline | side by side (parent: 2a60a9b)
author | Lubos Stanek <lubek@users.sourceforge.net> | |
Fri, 17 Nov 2006 20:15:14 +0000 (21:15 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 17 Nov 2006 20:15:14 +0000 (21:15 +0100) |
I am sending the updated version of config_list.
I repaired the error freeing unallocated memory, modified regex for dynamically
allocated error message buffer and replaced '|' with '/'.
I repaired the error freeing unallocated memory, modified regex for dynamically
allocated error message buffer and replaced '|' with '/'.
src/config_list.c | patch | blob | history |
diff --git a/src/config_list.c b/src/config_list.c
index fa9294ad56f39e5867ce89583aa21142361aec2a..eff976d84e0dae9425c8acb902005c76cd09de32 100644 (file)
--- a/src/config_list.c
+++ b/src/config_list.c
/**
* Usage:
*
- * Define plugin's global variable of type configlist_t:
+ * Define plugin's global pointer variable of type configlist_t:
* configlist_t *myconfig_ignore;
- * If you know the state of global ignore (IgnoreSelected),
+ * If you know the state of the global ignore (IgnoreSelected),
* allocate the variable with:
* myconfig_ignore = configlist_create (YourKnownIgnore);
- * If you do not know the state of the global ignore (IgnoreSelected),
+ * If you do not know the state of the global ignore,
* initialize the global variable and set the ignore flag later:
* myconfig_ignore = configlist_init ();
* Append single entries in your cf_register'ed callback function:
* When you hit the IgnoreSelected config option,
* offer it to the list:
* configlist_ignore (myconfig_ignore, instantly_got_value_of_ignore);
- * That ia all for the configlist initialization.
+ * That is all for the configlist initialization.
* Later during read and write (plugin's registered functions) get
* the information whether this entry would be collected or not:
* if (configlist_ignored (myconfig_ignore, thisentry))
#include "utils_debug.h"
#include "config_list.h"
-#define BUFSIZE 512
-
/* private prototypes */
struct configentry_s;
{
int rcompile;
regex_t *regtemp;
- char regerr[BUFSIZE];
+ int errsize;
+ char *regerr = NULL;
configentry_t *new;
/* create buffer */
if ((regtemp = malloc(sizeof(regex_t))) == NULL)
{
syslog (LOG_ERR, "cannot allocate new config entry");
- regfree (regtemp);
return (0);
}
memset (regtemp, '\0', sizeof(regex_t));
/* compile regex */
if ((rcompile = regcomp (regtemp, entry, REG_EXTENDED)) != 0)
{
- if (regerror(rcompile, regtemp, regerr, sizeof(regerr)))
+ /* prepare message buffer */
+ errsize = regerror(rcompile, regtemp, NULL, 0);
+ if (errsize)
+ regerr = smalloc(errsize);
+ /* get error message */
+ if (regerror(rcompile, regtemp, regerr, errsize))
syslog (LOG_ERR, "cannot compile regex %s: %i/%s",
entry, rcompile, regerr);
else
syslog (LOG_ERR, "cannot compile regex %s: %i",
entry, rcompile);
+ if (errsize)
+ sfree (regerr);
regfree (regtemp);
return (0);
}
}
memset (new, '\0', sizeof(configentry_t));
new->rmatch = regtemp;
-#if COLLECTD_DEBUG
- new->smatch = sstrdup(entry);
-#endif
+
/* append new entry */
if (conflist->next == NULL)
{
}
#if HAVE_REGEX_H
- /* regex string is enclosed in "|...|" */
- if (entry[0] == '|' && strlen(entry) > 2 && entry[strlen(entry) - 1] == '|')
+ /* regex string is enclosed in "/.../" */
+ if (entry[0] == '/' && strlen(entry) > 2 && entry[strlen(entry) - 1] == '/')
{
entrytemp = smalloc(strlen(entry) - 2);
sstrncpy(entrytemp, &entry[1], strlen(entry) - 1);