From: Florian Forster Date: Sat, 17 Jan 2009 10:01:10 +0000 (+0100) Subject: collectd: Don't *abort* on the first read-error with the `-T' option. X-Git-Tag: collectd-4.6.0~103^2 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=4b8debfceafebfe2d2465fefe1b8b501908f843c;p=collectd.git collectd: Don't *abort* on the first read-error with the `-T' option. The `-T' option used to basically quit the daemon right away when the first read function of a plugin failed. This patch changes the behavior, so that: - All read-functions are tried. If one or more fail, the daemon will exit with a non-zero exit status, but all read-functions will be tried. - Don't quit if one read-function failed without calling all the shutdown-functions first. This will clean up the UNIX socket of the unixsock plugin and stuff like that. --- diff --git a/src/collectd.c b/src/collectd.c index 57701c0c..548a8fdd 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -406,6 +406,7 @@ int main (int argc, char **argv) pid_t pid; int daemonize = 1; #endif + int exit_status = 0; /* read options */ while (1) @@ -589,16 +590,20 @@ int main (int argc, char **argv) * run the actual loops */ do_init (); + if (test_readall) { - if (plugin_read_all_once ()) - return (1); + if (plugin_read_all_once () != 0) + exit_status = 1; } else + { + INFO ("Initialization complete, entering read-loop."); do_loop (); + } /* close syslog */ - INFO ("Exiting normally"); + INFO ("Exiting normally."); do_shutdown (); @@ -607,5 +612,5 @@ int main (int argc, char **argv) pidfile_remove (); #endif /* COLLECT_DAEMON */ - return (0); + return (exit_status); } /* int main */ diff --git a/src/plugin.c b/src/plugin.c index 510f92b1..bf707eca 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -682,14 +682,19 @@ void plugin_read_all (void) pthread_mutex_unlock (&read_lock); } /* void plugin_read_all */ +/* Read function called when the `-T' command line argument is given. */ int plugin_read_all_once (void) { llentry_t *le; read_func_t *rf; int status; + int return_status = 0; if (list_read == NULL) + { + NOTICE ("No read-functions are registered."); return (0); + } for (le = llist_head (list_read); le != NULL; @@ -701,12 +706,12 @@ int plugin_read_all_once (void) { NOTICE ("read-function of plugin `%s' failed.", le->key); - return status; + return_status = -1; } } - return (0); -} /* void plugin_read_all_once */ + return (return_status); +} /* int plugin_read_all_once */ int plugin_write (const char *plugin, /* {{{ */ const data_set_t *ds, const value_list_t *vl)