aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@gmail.com>2019-09-04 15:59:18 +0100
committerNikolaus Rath <Nikolaus@rath.org>2019-09-04 15:59:18 +0100
commit317181e8ea1b3406919b946ca5524f8b9f34817d (patch)
tree0d0e0a2eb0d3d309dbabbdcdd6cb62131507b592 /include
parentf39c71dcf99292c188bb6f0a117d7e118f92bfb1 (diff)
downloadlibfuse-317181e8ea1b3406919b946ca5524f8b9f34817d.tar.gz
Introduce callback for logging
Introduce an API for custom log handler functions. This allows libfuse applications to send messages to syslog(3) or other logging systems. See include/fuse_log.h for details. Convert libfuse from fprintf(stderr, ...) to log_fuse(level, ...). Most messages are error messages with FUSE_LOG_ERR log level. There are also some debug messages which now use the FUSE_LOG_DEBUG log level. Note that lib/mount_util.c is used by both libfuse and fusermount3. Since fusermount3 does not link against libfuse, we cannot call fuse_log() from lib/mount_util.c. This file will continue to use fprintf(stderr, ...) until someone figures out how to split it up. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/fuse_common.h1
-rw-r--r--include/fuse_log.h74
-rw-r--r--include/meson.build2
3 files changed, 76 insertions, 1 deletions
diff --git a/include/fuse_common.h b/include/fuse_common.h
index 0809441..2d686b2 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -15,6 +15,7 @@
#define FUSE_COMMON_H_
#include "fuse_opt.h"
+#include "fuse_log.h"
#include <stdint.h>
#include <sys/types.h>
diff --git a/include/fuse_log.h b/include/fuse_log.h
new file mode 100644
index 0000000..df43697
--- /dev/null
+++ b/include/fuse_log.h
@@ -0,0 +1,74 @@
+/*
+ FUSE: Filesystem in Userspace
+ Copyright (C) 2019 Red Hat, Inc.
+
+ This program can be distributed under the terms of the GNU LGPLv2.
+ See the file COPYING.LIB.
+*/
+
+#ifndef FUSE_LOG_H_
+#define FUSE_LOG_H_
+
+/** @file
+ *
+ * This file defines the logging interface of FUSE
+ */
+
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Log severity level
+ *
+ * These levels correspond to syslog(2) log levels since they are widely used.
+ */
+enum fuse_log_level {
+ FUSE_LOG_EMERG,
+ FUSE_LOG_ALERT,
+ FUSE_LOG_CRIT,
+ FUSE_LOG_ERR,
+ FUSE_LOG_WARNING,
+ FUSE_LOG_NOTICE,
+ FUSE_LOG_INFO,
+ FUSE_LOG_DEBUG
+};
+
+/**
+ * Log message handler function.
+ *
+ * This function must be thread-safe. It may be called from any libfuse
+ * function, including fuse_parse_cmdline() and other functions invoked before
+ * a FUSE filesystem is created.
+ *
+ * Install a custom log message handler function using fuse_set_log_func().
+ *
+ * @param level log severity level
+ * @param fmt sprintf-style format string including newline
+ * @param ap format string arguments
+ */
+typedef void (*fuse_log_func_t)(enum fuse_log_level level,
+ const char *fmt, va_list ap);
+
+/**
+ * Install a custom log handler function.
+ *
+ * Log messages are emitted by libfuse functions to report errors and debug
+ * information. Messages are printed to stderr by default but this can be
+ * overridden by installing a custom log message handler function.
+ *
+ * The log message handler function is global and affects all FUSE filesystems
+ * created within this process.
+ *
+ * @param func a custom log message handler function or NULL to revert to
+ * the default
+ */
+void fuse_set_log_func(fuse_log_func_t func);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FUSE_LOG_H_ */
diff --git a/include/meson.build b/include/meson.build
index 55cb6f7..bf67197 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -1,4 +1,4 @@
libfuse_headers = [ 'fuse.h', 'fuse_common.h', 'fuse_lowlevel.h',
- 'fuse_opt.h', 'cuse_lowlevel.h' ]
+ 'fuse_opt.h', 'cuse_lowlevel.h', 'fuse_log.h' ]
install_headers(libfuse_headers, subdir: 'fuse3')