aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cuse_lowlevel.c
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 /lib/cuse_lowlevel.c
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 'lib/cuse_lowlevel.c')
-rw-r--r--lib/cuse_lowlevel.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/cuse_lowlevel.c b/lib/cuse_lowlevel.c
index 019b20f..9917b64 100644
--- a/lib/cuse_lowlevel.c
+++ b/lib/cuse_lowlevel.c
@@ -122,14 +122,14 @@ static struct cuse_data *cuse_prep_data(const struct cuse_info *ci,
NULL);
if (dev_info_len > CUSE_INIT_INFO_MAX) {
- fprintf(stderr, "cuse: dev_info (%zu) too large, limit=%u\n",
+ fuse_log(FUSE_LOG_ERR, "cuse: dev_info (%zu) too large, limit=%u\n",
dev_info_len, CUSE_INIT_INFO_MAX);
return NULL;
}
cd = calloc(1, sizeof(*cd) + dev_info_len);
if (!cd) {
- fprintf(stderr, "cuse: failed to allocate cuse_data\n");
+ fuse_log(FUSE_LOG_ERR, "cuse: failed to allocate cuse_data\n");
return NULL;
}
@@ -203,8 +203,8 @@ void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
(void) nodeid;
if (se->debug) {
- fprintf(stderr, "CUSE_INIT: %u.%u\n", arg->major, arg->minor);
- fprintf(stderr, "flags=0x%08x\n", arg->flags);
+ fuse_log(FUSE_LOG_DEBUG, "CUSE_INIT: %u.%u\n", arg->major, arg->minor);
+ fuse_log(FUSE_LOG_DEBUG, "flags=0x%08x\n", arg->flags);
}
se->conn.proto_major = arg->major;
se->conn.proto_minor = arg->minor;
@@ -212,14 +212,14 @@ void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
se->conn.want = 0;
if (arg->major < 7) {
- fprintf(stderr, "cuse: unsupported protocol version: %u.%u\n",
+ fuse_log(FUSE_LOG_ERR, "cuse: unsupported protocol version: %u.%u\n",
arg->major, arg->minor);
fuse_reply_err(req, EPROTO);
return;
}
if (bufsize < FUSE_MIN_READ_BUFFER) {
- fprintf(stderr, "cuse: warning: buffer size too small: %zu\n",
+ fuse_log(FUSE_LOG_ERR, "cuse: warning: buffer size too small: %zu\n",
bufsize);
bufsize = FUSE_MIN_READ_BUFFER;
}
@@ -242,14 +242,14 @@ void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
outarg.dev_minor = cd->dev_minor;
if (se->debug) {
- fprintf(stderr, " CUSE_INIT: %u.%u\n",
+ fuse_log(FUSE_LOG_DEBUG, " CUSE_INIT: %u.%u\n",
outarg.major, outarg.minor);
- fprintf(stderr, " flags=0x%08x\n", outarg.flags);
- fprintf(stderr, " max_read=0x%08x\n", outarg.max_read);
- fprintf(stderr, " max_write=0x%08x\n", outarg.max_write);
- fprintf(stderr, " dev_major=%u\n", outarg.dev_major);
- fprintf(stderr, " dev_minor=%u\n", outarg.dev_minor);
- fprintf(stderr, " dev_info: %.*s\n", cd->dev_info_len,
+ fuse_log(FUSE_LOG_DEBUG, " flags=0x%08x\n", outarg.flags);
+ fuse_log(FUSE_LOG_DEBUG, " max_read=0x%08x\n", outarg.max_read);
+ fuse_log(FUSE_LOG_DEBUG, " max_write=0x%08x\n", outarg.max_write);
+ fuse_log(FUSE_LOG_DEBUG, " dev_major=%u\n", outarg.dev_major);
+ fuse_log(FUSE_LOG_DEBUG, " dev_minor=%u\n", outarg.dev_minor);
+ fuse_log(FUSE_LOG_DEBUG, " dev_info: %.*s\n", cd->dev_info_len,
cd->dev_info);
}
@@ -303,9 +303,9 @@ struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[],
fd = open(devname, O_RDWR);
if (fd == -1) {
if (errno == ENODEV || errno == ENOENT)
- fprintf(stderr, "cuse: device not found, try 'modprobe cuse' first\n");
+ fuse_log(FUSE_LOG_ERR, "cuse: device not found, try 'modprobe cuse' first\n");
else
- fprintf(stderr, "cuse: failed to open %s: %s\n",
+ fuse_log(FUSE_LOG_ERR, "cuse: failed to open %s: %s\n",
devname, strerror(errno));
goto err_se;
}