X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fplugin.c;h=46a1c617129e957a79a28d6cfb7aec9440e5106a;hb=70a5b80271643b3c0384e03a77fcfb35c11f726a;hp=be28671a7cb7b5efae25d14db22b5fd8c2713e3b;hpb=8fdec2467f3d4566185a9c9d757376aa3d30413b;p=collectd.git diff --git a/src/plugin.c b/src/plugin.c index be28671a..46a1c617 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; @@ -276,15 +277,28 @@ void plugin_init_all (void) /* * Call `read' on all plugins (if given) */ -void plugin_read_all (void) +void plugin_read_all (const int *loop) { plugin_t *p; - for (p = first_plugin; p != NULL; p = p->next) + for (p = first_plugin; (*loop == 0) && (p != NULL); p = p->next) if (p->read != NULL) (*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. */ @@ -317,10 +331,26 @@ void plugin_register (char *type, 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''.