Skip to content

Commit

Permalink
Merge branch 'libmount/errormsg' of https://github.com/t-8ch/util-linux
Browse files Browse the repository at this point in the history
* 'libmount/errormsg' of https://github.com/t-8ch/util-linux:
  libmount: report all kernel messages for fd-based mount API
  libmount: add helper to log mount messages as emitted by kernel
  libmount: change syscall status macros to be functions
  • Loading branch information
karelzak committed Oct 9, 2023
2 parents 36cce3d + 2f0e92b commit f3fd641
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
27 changes: 27 additions & 0 deletions libmount/src/hook_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ 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);
}
}

#define set_syscall_status set_syscall_status_cxt_log

/*
* This hookset uses 'struct libmnt_sysapi' (mountP.h) as hookset data.
*/
Expand Down
34 changes: 18 additions & 16 deletions libmount/src/mountP.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,24 @@ struct libmnt_context
/* Flags usable with MS_BIND|MS_REMOUNT */
#define MNT_BIND_SETTABLE (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY|MS_NOSYMFOLLOW)

#define set_syscall_status(_cxt, _name, _x) __extension__ ({ \
if (!(_x)) { \
DBG(CXT, ul_debug("syscall '%s' [%m]", _name)); \
(_cxt)->syscall_status = -errno; \
(_cxt)->syscall_name = (_name); \
} else { \
DBG(CXT, ul_debug("syscall '%s' [success]", _name)); \
(_cxt)->syscall_status = 0; \
} \
})

#define reset_syscall_status(_cxt) __extension__ ({ \
DBG(CXT, ul_debug("reset syscall status")); \
(_cxt)->syscall_status = 0; \
(_cxt)->syscall_name = NULL; \
})
static inline void set_syscall_status(struct libmnt_context *cxt, const char *name, int x)
{
if (!x) {
DBG(CXT, ul_debug("syscall '%s' [%m]", name));
cxt->syscall_status = -errno;
cxt->syscall_name = name;
} else {
DBG(CXT, ul_debug("syscall '%s' [success]", name));
cxt->syscall_status = 0;
}
}

static inline void reset_syscall_status(struct libmnt_context *cxt)
{
DBG(CXT, ul_debug("reset syscall status"));
cxt->syscall_status = 0;
cxt->syscall_name = NULL;
}

/* optmap.c */
extern const struct libmnt_optmap *mnt_optmap_get_entry(
Expand Down

0 comments on commit f3fd641

Please sign in to comment.