#include <sys/socket.h>
#include <netdb.h>
+#include <pthread.h>
+
#include "plugin.h"
#include "configfile.h"
static int loop = 0;
+static void *do_flush (void *arg)
+{
+ INFO ("Flushing all data.");
+ plugin_flush_all (-1);
+ INFO ("Finished flushing all data.");
+ pthread_exit (NULL);
+ return NULL;
+}
+
static void sigIntHandler (int signal)
{
loop++;
loop++;
}
+static void sigUsr1Handler (int signal)
+{
+ pthread_t thread;
+ pthread_attr_t attr;
+
+ /* flushing the data might take a while,
+ * so it should be done asynchronously */
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+ pthread_create (&thread, &attr, do_flush, NULL);
+}
+
static int init_hostname (void)
{
const char *str;
{
struct sigaction sigIntAction;
struct sigaction sigTermAction;
+ struct sigaction sigUsr1Action;
char *configfile = CONFIGFILE;
int test_config = 0;
const char *basedir;
sigTermAction.sa_handler = sigTermHandler;
sigaction (SIGTERM, &sigTermAction, NULL);
+ memset (&sigUsr1Action, '\0', sizeof (sigUsr1Action));
+ sigUsr1Action.sa_handler = sigUsr1Handler;
+ sigaction (SIGUSR1, &sigUsr1Action, NULL);
+
/*
* run the actual loops
*/
static llist_t *list_init;
static llist_t *list_read;
static llist_t *list_write;
+static llist_t *list_flush;
static llist_t *list_shutdown;
static llist_t *list_log;
static llist_t *list_notification;
return (register_callback (&list_write, name, (void *) callback));
} /* int plugin_register_write */
+int plugin_register_flush (const char *name, int (*callback) (const int))
+{
+ return (register_callback (&list_flush, name, (void *) callback));
+} /* int plugin_register_flush */
+
int plugin_register_shutdown (char *name,
int (*callback) (void))
{
return (plugin_unregister (list_write, name));
}
+int plugin_unregister_flush (const char *name)
+{
+ return (plugin_unregister (list_flush, name));
+}
+
int plugin_unregister_shutdown (const char *name)
{
return (plugin_unregister (list_shutdown, name));
pthread_mutex_unlock (&read_lock);
} /* void plugin_read_all */
+void plugin_flush_all (int timeout)
+{
+ int (*callback) (int);
+ llentry_t *le;
+
+ if (list_flush == NULL)
+ return;
+
+ le = llist_head (list_flush);
+ while (le != NULL)
+ {
+ callback = (int (*) (int)) le->value;
+ le = le->next;
+
+ (*callback) (timeout);
+ }
+} /* void plugin_flush_all */
+
void plugin_shutdown_all (void)
{
int (*callback) (void);
void plugin_init_all (void);
void plugin_read_all (void);
+void plugin_flush_all (int timeout);
void plugin_shutdown_all (void);
/*
int (*callback) (void));
int plugin_register_write (const char *name,
int (*callback) (const data_set_t *ds, const value_list_t *vl));
+int plugin_register_flush (const char *name,
+ int (*callback) (const int));
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
int plugin_unregister_init (const char *name);
int plugin_unregister_read (const char *name);
int plugin_unregister_write (const char *name);
+int plugin_unregister_flush (const char *name);
int plugin_unregister_shutdown (const char *name);
int plugin_unregister_data_set (const char *name);
int plugin_unregister_log (const char *name);