summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 98da2aa)
raw | patch | inline | side by side (parent: 98da2aa)
author | Florian Forster <sifnfors@faui02d.informatik.uni-erlangen.de> | |
Wed, 31 Jan 2007 11:17:37 +0000 (12:17 +0100) | ||
committer | Florian Forster <sifnfors@faui02d.informatik.uni-erlangen.de> | |
Wed, 31 Jan 2007 11:17:37 +0000 (12:17 +0100) |
The usual quadratic increase of delay-intervals is being used to disable the
function for up to 24 hours.
function for up to 24 hours.
src/plugin.c | patch | blob | history | |
src/unixsock.c | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index df2eb6b50df270f85f363f8a54f9b47bcad03b1f..2daeea9fd67e42e8ef36c5b6eee4e185542ed8e1 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#include "utils_llist.h"
#include "utils_debug.h"
+/*
+ * Private structures
+ */
+struct read_func_s
+{
+ int wait_time;
+ int wait_left;
+ int (*callback) (void);
+};
+typedef struct read_func_s read_func_t;
+
/*
* Private variables
*/
return (-1);
llist_remove (list, e);
+ llentry_destroy (e);
return (0);
} /* int plugin_unregister */
int plugin_register_read (const char *name,
int (*callback) (void))
{
- return (register_callback (&list_read, name, (void *) callback));
+ read_func_t *rf;
+
+ rf = (read_func_t *) malloc (sizeof (read_func_t));
+ if (rf == NULL)
+ {
+ syslog (LOG_ERR, "plugin_register_read: malloc failed: %s",
+ strerror (errno));
+ return (-1);
+ }
+
+ memset (rf, '\0', sizeof (read_func_t));
+ rf->wait_time = atoi (COLLECTD_STEP);
+ rf->wait_left = 0;
+ rf->callback = callback;
+
+ return (register_callback (&list_read, name, (void *) rf));
} /* int plugin_register_read */
int plugin_register_write (const char *name,
int plugin_unregister_read (const char *name)
{
return (plugin_unregister (list_read, name));
+ llentry_t *e;
+
+ e = llist_search (list_read, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_read, e);
+ free (e->value);
+ llentry_destroy (e);
+
+ return (0);
}
int plugin_unregister_write (const char *name)
void plugin_read_all (const int *loop)
{
- int (*callback) (void);
- llentry_t *le;
+ llentry_t *le;
+ read_func_t *rf;
+ int status;
+ int step;
if (list_read == NULL)
return;
+ step = atoi (COLLECTD_STEP);
+
le = llist_head (list_read);
while ((*loop == 0) && (le != NULL))
{
- callback = le->value;
- (*callback) ();
+ rf = (read_func_t *) le->value;
+
+ if (rf->wait_left > 0)
+ rf->wait_left -= step;
+ if (rf->wait_left > 0)
+ {
+ le = le->next;
+ continue;
+ }
+
+ status = rf->callback ();
+ if (status != 0)
+ {
+ rf->wait_left = rf->wait_time;
+ rf->wait_time = rf->wait_time * 2;
+ if (rf->wait_time > 86400)
+ rf->wait_time = 86400;
+
+ syslog (LOG_NOTICE, "read-function of plugin `%s' "
+ "failed. Will syspend it for %i "
+ "seconds.", le->key, rf->wait_left);
+ }
+ else
+ {
+ rf->wait_left = 0;
+ rf->wait_time = step;
+ }
le = le->next;
- }
+ } /* while ((*loop == 0) && (le != NULL)) */
} /* void plugin_read_all */
void plugin_shutdown_all (void)
diff --git a/src/unixsock.c b/src/unixsock.c
index b2663f14056bf4d913111aaa3d029a98aac4420c..de1fa4fdcacd07b00eba1b872d384ba86a94cbab 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
pthread_join (listen_thread, &ret);
}
+ plugin_unregister_init ("unixsock");
+ plugin_unregister_write ("unixsock");
+ plugin_unregister_shutdown ("unixsock");
+
return (0);
} /* int us_shutdown */