[collectd] [PATCH] plugin_read_all: Check the `loop' variable after each iteration and return early if the daemon is shutting down.

Florian Forster octo at verplant.org
Mon Nov 6 19:37:04 CET 2006


From: Florian Forster <octo at leeloo.lan.home.verplant.org>

Lubos Stanek has reported that the daemon may stop too slow, resulting in it
being killed by impatient init-scripts. With this patch `plugin_read_all'
checks the `loop' variable before entering each plugin's read-function. If the
loop-variable is set to non-zero it will return early, allowing the daemon to
shutdown more instantly.

Signed-off-by: Florian Forster <octo at leeloo.lan.home.verplant.org>
---
 src/collectd.c |    2 +-
 src/plugin.c   |    4 ++--
 src/plugin.h   |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/collectd.c b/src/collectd.c
index 98b9a16..ef2ccc7 100644
--- a/src/collectd.c
+++ b/src/collectd.c
@@ -193,7 +193,7 @@ static int start_client (void)
 		curtime = time (NULL);
 
 		/* Issue all plugins */
-		plugin_read_all ();
+		plugin_read_all (&loop);
 
 		if (gettimeofday (&tv_now, NULL) < 0)
 		{
diff --git a/src/plugin.c b/src/plugin.c
index be28671..697449e 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -276,11 +276,11 @@ 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) ();
 }
diff --git a/src/plugin.h b/src/plugin.h
index e1e2e7c..a77c87f 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -99,7 +99,7 @@ int  plugin_load (const char *type);
 
 int  plugin_load_all (char *dir);
 void plugin_init_all (void);
-void plugin_read_all (void);
+void plugin_read_all (const int *loop);
 
 void plugin_register (char *type,
 		void (*init) (void),
-- 
1.4.3.3




More information about the collectd mailing list