summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ddf1f52)
raw | patch | inline | side by side (parent: ddf1f52)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 22:03:00 +0000 (23:03 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 22:03:00 +0000 (23:03 +0100) |
src/logfile.c | patch | blob | history | |
src/perl.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history | |
src/syslog.c | patch | blob | history |
diff --git a/src/logfile.c b/src/logfile.c
index 382386b75552fa0915d9ade6ded18bc5b9954f3d..26d805a4ce4a9c93481e886aadd2ef787e4d3d40 100644 (file)
--- a/src/logfile.c
+++ b/src/logfile.c
return;
} /* void logfile_print */
-static void logfile_log (int severity, const char *msg)
+static void logfile_log (int severity, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
if (severity > log_level)
return;
{
plugin_register_config ("logfile", logfile_config,
config_keys, config_keys_num);
- plugin_register_log ("logfile", logfile_log);
+ plugin_register_log ("logfile", logfile_log, /* user_data = */ NULL);
plugin_register_notification ("logfile", logfile_notification);
} /* void module_register (void) */
diff --git a/src/perl.c b/src/perl.c
index b600ca1d5e4a740ad85153dae85ebfe981b4ad5d..e6b7c460d9b59a3e711361bb058a9473e6d98477 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
return pplugin_call_all (aTHX_ PLUGIN_WRITE, ds, vl);
} /* static int perl_write (const data_set_t *, const value_list_t *) */
-static void perl_log (int level, const char *msg)
+static void perl_log (int level, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
dTHX;
perl_run (aTHX);
- plugin_register_log ("perl", perl_log);
+ plugin_register_log ("perl", perl_log, /* user_data = */ NULL);
plugin_register_notification ("perl", perl_notify);
plugin_register_init ("perl", perl_init);
diff --git a/src/plugin.c b/src/plugin.c
index 49793dca7a29b65801dc47f4cfd1201190f87c2b..41a816f81e7817187cbf9cd538770262dda6e5fe 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
};
typedef struct flush_func_s flush_func_t;
+struct log_func_s
+{
+ plugin_log_cb callback;
+ user_data_t udata;
+};
+typedef struct log_func_s log_func_t;
+
/*
* Private variables
*/
return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
} /* int plugin_register_data_set */
-int plugin_register_log (char *name,
- void (*callback) (int priority, const char *msg))
+int plugin_register_log (const char *name,
+ plugin_log_cb callback, user_data_t *user_data)
{
- return (register_callback (&list_log, name, (void *) callback));
+ log_func_t *lf;
+
+ lf = (log_func_t *) malloc (sizeof (*lf));
+ if (lf == NULL)
+ {
+ ERROR ("plugin_register_log: malloc failed.");
+ return (-1);
+ }
+ memset (lf, 0, sizeof (*lf));
+
+ lf->callback = callback;
+ if (user_data == NULL)
+ {
+ lf->udata.data = NULL;
+ lf->udata.free_func = NULL;
+ }
+ else
+ {
+ lf->udata = *user_data;
+ }
+
+ return (register_callback (&list_log, name, (void *) lf));
} /* int plugin_register_log */
int plugin_register_notification (const char *name,
int plugin_unregister_log (const char *name)
{
- return (plugin_unregister (list_log, name));
+ llentry_t *e;
+ log_func_t *lf;
+
+ e = llist_search (list_log, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_log, e);
+
+ lf = (log_func_t *) e->value;
+ plugin_user_data_destroy (&lf->udata);
+ free (lf);
+ free (e->key);
+
+ llentry_destroy (e);
+
+ return (0);
}
int plugin_unregister_notification (const char *name)
{
char msg[1024];
va_list ap;
-
- void (*callback) (int, const char *);
llentry_t *le;
if (list_log == NULL)
le = llist_head (list_log);
while (le != NULL)
{
- callback = (void (*) (int, const char *)) le->value;
- (*callback) (level, msg);
+ log_func_t *lf;
+
+ lf = (log_func_t *) le->value;
+
+ lf->callback (level, msg, &lf->udata);
le = le->next;
}
diff --git a/src/plugin.h b/src/plugin.h
index ed9fdab7d3d1b624e45e113be11ba186a2b0234d..b4e5cb37744042143905e000912c31cd3d930988 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
user_data_t *);
typedef int (*plugin_flush_cb) (int timeout, const char *identifier,
user_data_t *);
+typedef void (*plugin_log_cb) (int severity, const char *message,
+ user_data_t *);
/*
* NAME
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
-int plugin_register_log (char *name,
- void (*callback) (int, const char *));
+int plugin_register_log (const char *name,
+ plugin_log_cb callback, user_data_t *user_data);
int plugin_register_notification (const char *name,
int (*callback) (const notification_t *notif));
diff --git a/src/syslog.c b/src/syslog.c
index a21bef18e180a3c63c1bf6966effc77f26a0518b..ace9dc6f090e1a98a8bc3a0d4d08a25b39f6f21b 100644 (file)
--- a/src/syslog.c
+++ b/src/syslog.c
return (0);
} /* int sl_config */
-static void sl_log (int severity, const char *msg)
+static void sl_log (int severity, const char *msg,
+ user_data_t __attribute__((unused)) *user_data)
{
if (severity > log_level)
return;
openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
- plugin_register_log ("syslog", sl_log);
+ plugin_register_log ("syslog", sl_log, /* user_data = */ NULL);
plugin_register_shutdown ("syslog", sl_shutdown);
} /* void module_register(void) */