[collectd] [PATCH] Added support for an optional plugin shutdown
function.
Sebastian Harl
sh<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org
Mon Dec 4 11:30:29 CET 2006
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<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org>
---
src/collectd.c | 2 ++
src/plugin.c | 30 ++++++++++++++++++++++++++++++
src/plugin.h | 4 ++++
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/src/collectd.c b/src/collectd.c
index 64da576..a1e15bf 100644
--- a/src/collectd.c
+++ b/src/collectd.c
@@ -444,6 +444,8 @@ #if HAVE_LIBRRD
#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 697449e..46a1c61 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -34,6 +34,7 @@ typedef struct plugin
void (*init) (void);
void (*read) (void);
void (*write) (char *host, char *inst, char *val);
+ void (*shutdown) (void);
struct plugin *next;
} plugin_t;
@@ -286,6 +287,19 @@ void plugin_read_all (const int *loop)
}
/*
+ * 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.
*/
void plugin_register (char *type,
@@ -317,11 +331,27 @@ #endif
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 a77c87f..45e9b49 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -101,11 +101,15 @@ int plugin_load_all (char *dir);
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
--
1.4.3.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20061204/d144ceea/attachment.pgp
More information about the collectd
mailing list