summaryrefslogtreecommitdiffstats
path: root/ctdb/include/ctdb.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-06-04 20:27:03 +0930
committerRusty Russell <rusty@rustcorp.com.au>2010-06-04 20:27:03 +0930
commit379fd4e606978d84f1b9c42817a739feb5aa7198 (patch)
tree5d164e2bd251a6ab18f387084ec7ffd5561808da /ctdb/include/ctdb.h
parentcc8435852c5b0cef4637919f3993f304d9f8703e (diff)
downloadsamba-379fd4e606978d84f1b9c42817a739feb5aa7198.tar.gz
samba-379fd4e606978d84f1b9c42817a739feb5aa7198.tar.xz
samba-379fd4e606978d84f1b9c42817a739feb5aa7198.zip
libctdb: add logging infrastructure
This is based on Ronnie's work, merged with mine. That means errors are all my fault. Differences from Ronnie's: 1) use syslog's LOG_ levels directly. 2) typesafe arg to log function, and use it (eg stderr) in helper function. 3) store fn in ctdb context, and expose ctdb_log_level directly thru API. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 86259aa395555aaf7b2fae7326caa2ea62961092)
Diffstat (limited to 'ctdb/include/ctdb.h')
-rw-r--r--ctdb/include/ctdb.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index 5ad8736a7e..1d0a08611c 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -23,8 +23,15 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
+#include <stdarg.h>
+#include <stdio.h>
#include <tdb.h>
+/* The type of the first arg should match the arg given to ctdb_connect() */
+typedef void (*ctdb_log_fn_t)(void *log_priv,
+ int severity, const char *format, va_list ap);
+
+
/* All *_send() functions are guaranteed to be non-blocking and fully
* asynchronous. The non-_send variants are synchronous.
*/
@@ -34,7 +41,8 @@
* Returns a ctdb context if successful or NULL.
*
*/
-struct ctdb_connection *ctdb_connect(const char *addr);
+struct ctdb_connection *ctdb_connect(const char *addr,
+ ctdb_log_fn_t log_fn, void *log_priv);
int ctdb_get_fd(struct ctdb_connection *ctdb);
@@ -212,12 +220,26 @@ int ctdb_getrecmaster(struct ctdb_connection *ctdb,
int ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req);
+/*
+ * functions for logging errors
+ */
+extern int ctdb_log_level; /* LOG_WARNING and above by default. */
+void ctdb_log_file(FILE *, int severity, const char *format, va_list ap);
+
+
/* These ugly macro wrappers make the callbacks typesafe. */
#include <ctdb_typesafe_cb.h>
#define ctdb_sendcb(cb, cbdata) \
typesafe_cb_preargs(void, (cb), (cbdata), \
struct ctdb_connection *, struct ctdb_request *)
+#define ctdb_connect(addr, log, logpriv) \
+ ctdb_connect((addr), \
+ typesafe_cb_postargs(void, (log), (logpriv), \
+ int, const char *, va_list), \
+ (logpriv))
+
+
#define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags), \
ctdb_sendcb((cb), (cbdata)), (cbdata))