summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 62435b7)
raw | patch | inline | side by side (parent: 62435b7)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 4 Dec 2006 10:30:29 +0000 (11:30 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 4 Dec 2006 10:34:05 +0000 (11:34 +0100) |
A plugin may register a shutdown function using plugin_register_shutdown ().
This function is called when collectd terminates either during normal
termination or after SIGINT or SIGTERM have been received.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
This function is called when collectd terminates either during normal
termination or after SIGINT or SIGTERM have been received.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
src/collectd.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/collectd.c b/src/collectd.c
index 64da57650a2627774e3cf3e78913b0f20810c6ee..a1e15bf1e7ca52b674632b1308012c91297d2c00 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
#endif
start_client ();
+ plugin_shutdown_all ();
+
#if COLLECT_DEBUG
if (logfile != NULL)
DBG_STOPFILE("debug file closed.");
diff --git a/src/plugin.c b/src/plugin.c
index 697449e209e81a8791e50bd8cfeb8f93711307e4..46a1c617129e957a79a28d6cfb7aec9440e5106a 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
void (*init) (void);
void (*read) (void);
void (*write) (char *host, char *inst, char *val);
+ void (*shutdown) (void);
struct plugin *next;
} plugin_t;
(*p->read) ();
}
+/*
+ * Call `shutdown' on all plugins (if given)
+ */
+void plugin_shutdown_all (void)
+{
+ plugin_t *p;
+
+ for (p = first_plugin; NULL != p; p = p->next)
+ if (NULL != p->shutdown)
+ (*p->shutdown) ();
+ return;
+}
+
/*
* Add plugin to the linked list of registered plugins.
*/
p->read = read;
p->write = write;
+ p->shutdown = NULL;
+
p->next = first_plugin;
first_plugin = p;
}
+/*
+ * Register the shutdown function (optional).
+ */
+int plugin_register_shutdown (char *type, void (*shutdown) (void))
+{
+ plugin_t *p = plugin_search (type);
+
+ if (NULL == p)
+ return -1;
+
+ p->shutdown = shutdown;
+ return 0;
+}
+
/*
* Send received data back to the plugin/module which will append DS
* definitions and pass it on to ``rrd_update_file''.
diff --git a/src/plugin.h b/src/plugin.h
index a77c87fb9a39be0ac298be5746a86cdf9f30fbb6..45e9b494fc60634b568ee6a7f0d9bc4bc263656f 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
void plugin_init_all (void);
void plugin_read_all (const int *loop);
+void plugin_shutdown_all (void);
+
void plugin_register (char *type,
void (*init) (void),
void (*read) (void),
void (*write) (char *, char *, char *));
+int plugin_register_shutdown (char *, void (*) (void));
+
/*
* NAME
* plugin_write