summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3facef0)
raw | patch | inline | side by side (parent: 3facef0)
author | Doug MacEachern <dougm@hyperic.com> | |
Fri, 2 Jan 2009 21:52:35 +0000 (13:52 -0800) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 17 Jan 2009 09:46:56 +0000 (10:46 +0100) |
The -T switch:
- implies -f
- does not start any read threads
- invokes callback() foreach list_read and will exit 1 on failure, 0
otherwise
Makes for a nicer dryrun than -f + ^C, also makes it possible to wrap
with a test harness such as Test.pm
Signed-off-by: Doug MacEachern <dougm@hyperic.com>
Signed-off-by: Florian Forster <octo@leeloo.lan.home.verplant.org>
- implies -f
- does not start any read threads
- invokes callback() foreach list_read and will exit 1 on failure, 0
otherwise
Makes for a nicer dryrun than -f + ^C, also makes it possible to wrap
with a test harness such as Test.pm
Signed-off-by: Doug MacEachern <dougm@hyperic.com>
Signed-off-by: Florian Forster <octo@leeloo.lan.home.verplant.org>
src/collectd.c | patch | blob | history | |
src/collectd.pod | 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 9526ec915cbe4733c384c48792aa23a005662b8b..57701c0cb6ee456d78aba397fdbf05f284d7fb44 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
" -C <file> Configuration file.\n"
" Default: "CONFIGFILE"\n"
" -t Test config and exit.\n"
+ " -T Test plugin read and exit.\n"
" -P <file> PID-file.\n"
" Default: "PIDFILE"\n"
#if COLLECT_DAEMON
struct sigaction sig_pipe_action;
char *configfile = CONFIGFILE;
int test_config = 0;
+ int test_readall = 0;
const char *basedir;
#if COLLECT_DAEMON
struct sigaction sig_chld_action;
{
int c;
- c = getopt (argc, argv, "htC:"
+ c = getopt (argc, argv, "htTC:"
#if COLLECT_DAEMON
"fP:"
#endif
case 't':
test_config = 1;
break;
+ case 'T':
+ test_readall = 1;
+ global_option_set ("ReadThreads", "-1");
+#if COLLECT_DAEMON
+ daemonize = 0;
+#endif /* COLLECT_DAEMON */
+ break;
#if COLLECT_DAEMON
case 'P':
global_option_set ("PIDFile", optarg);
* run the actual loops
*/
do_init ();
- do_loop ();
+ if (test_readall)
+ {
+ if (plugin_read_all_once ())
+ return (1);
+ }
+ else
+ do_loop ();
/* close syslog */
INFO ("Exiting normally");
diff --git a/src/collectd.pod b/src/collectd.pod
index c10ae7802027c8c2dd96162b445cb16cb4b707d2..e36dcdf3eb0c9ebe031970da77cf86d777a36059 100644 (file)
--- a/src/collectd.pod
+++ b/src/collectd.pod
Test the configuration only. The program immediately exits after parsing the
config file. A return code not equal to zero indicates an error.
+=item B<-T>
+
+Test the plugin read callbacks only. The program immediately exits after invoking
+the read callbacks once. A return code not equal to zero indicates an error.
+
=item B<-P> I<E<lt>pid-fileE<gt>>
Specify an alternative pid file. This overwrites any settings in the config
diff --git a/src/plugin.c b/src/plugin.c
index 4ad7366cd0c5d9ff8244fb64866211f6d9ef27bd..510f92b103f4b25e13c177ff209b497145141137 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
{
int i;
+ if (read_threads == NULL)
+ return;
+
pthread_mutex_lock (&read_lock);
read_loop = 0;
DEBUG ("plugin: stop_threads: Signalling `read_cond'");
int num;
rt = global_option_get ("ReadThreads");
num = atoi (rt);
- start_threads ((num > 0) ? num : 5);
+ if (num != -1)
+ start_threads ((num > 0) ? num : 5);
}
} /* void plugin_init_all */
pthread_mutex_unlock (&read_lock);
} /* void plugin_read_all */
+int plugin_read_all_once (void)
+{
+ llentry_t *le;
+ read_func_t *rf;
+ int status;
+
+ if (list_read == NULL)
+ return (0);
+
+ for (le = llist_head (list_read);
+ le != NULL;
+ le = le->next)
+ {
+ rf = (read_func_t *) le->value;
+ status = rf->callback ();
+ if (status != 0)
+ {
+ NOTICE ("read-function of plugin `%s' failed.",
+ le->key);
+ return status;
+ }
+ }
+
+ return (0);
+} /* void plugin_read_all_once */
+
int plugin_write (const char *plugin, /* {{{ */
const data_set_t *ds, const value_list_t *vl)
{
diff --git a/src/plugin.h b/src/plugin.h
index a6f89a0ec37697ef11c61ffdc03312494aa06e22..4f4a360299b7214ac6821620ab55cc906bb0f441 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
void plugin_init_all (void);
void plugin_read_all (void);
+int plugin_read_all_once (void);
void plugin_shutdown_all (void);
/*