aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2023-10-05 13:19:14 +0200
committerThomas Weißschuh <thomas@t-8ch.de>2023-10-05 13:19:14 +0200
commit2d5e138e8c28e89fea8e3e960ca863787bb6fe91 (patch)
treef7179e65e87ad3ad36b6200d88ad8a82c56436fb /libmount/src
parent8eb925b14a34d65e5e33861ea4aa1f565fb3d7ca (diff)
downloadutil-linux-2d5e138e8c28e89fea8e3e960ca863787bb6fe91.tar.gz
libmount: add helper to log mount messages as emitted by kernel
The kernel helpfully provides feedback about failed operations via the filesystem descriptor. Read that information and expose it via libmounts debug facilities. Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/hook_mount.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/libmount/src/hook_mount.c b/libmount/src/hook_mount.c
index 4b2a534f74..2e0b5f0fac 100644
--- a/libmount/src/hook_mount.c
+++ b/libmount/src/hook_mount.c
@@ -64,6 +64,31 @@ static void close_sysapi_fds(struct libmnt_sysapi *api)
api->fd_tree = api->fd_fs = -1;
}
+static void debug_fs_fd_messages(int fd)
+{
+ uint8_t buf[BUFSIZ];
+ int rc;
+
+ while ((rc = read(fd, buf, sizeof(buf))) != -1) {
+ if (rc > 0 && buf[rc - 1] == '\n')
+ buf[rc - 1] = '\0';
+ DBG(CXT, ul_debug("message from kernel: %*s", rc, buf));
+ }
+}
+
+static void set_syscall_status_cxt_log(struct libmnt_context *cxt,
+ const char *name, int x)
+{
+ struct libmnt_sysapi *api;
+
+ set_syscall_status(cxt, name, x);
+
+ if (!x) {
+ api = get_sysapi(cxt);
+ debug_fs_fd_messages(api->fd_fs);
+ }
+}
+
/*
* This hookset uses 'struct libmnt_sysapi' (mountP.h) as hookset data.
*/