From 0f9b2438c927d2787bf43b693809af3719e15646 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 3 Jan 2024 12:38:21 +0100 Subject: [PATCH] libmount: add mnt_context_within_helper() wrapper Signed-off-by: Karel Zak --- libmount/src/context.c | 9 ++++++++- libmount/src/context_umount.c | 2 +- libmount/src/mountP.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libmount/src/context.c b/libmount/src/context.c index 6db71f4e47..93fc3dbdcb 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -2737,7 +2737,6 @@ int mnt_context_get_excode( return rc; } - /** * mnt_context_init_helper * @cxt: mount context @@ -2773,6 +2772,14 @@ int mnt_context_init_helper(struct libmnt_context *cxt, int action, return rc; } +/* + * libmount used in /sbin/[u]mount. helper + */ +int mnt_context_within_helper(struct libmnt_context *cxt) +{ + return cxt && (cxt->flags & MNT_FL_HELPER); +} + /** * mnt_context_helper_setopt: * @cxt: context diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 26394d51ef..79b62378d8 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -270,7 +270,7 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg */ if (mnt_context_is_restricted(cxt) || *tgt != '/' - || (cxt->flags & MNT_FL_HELPER) + || mnt_context_within_helper(cxt) || mnt_context_is_force(cxt) || mnt_context_is_lazy(cxt) || mnt_context_is_nocanonicalize(cxt) diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 59921cf740..2385e191db 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -620,6 +620,8 @@ extern struct libmnt_context *mnt_copy_context(struct libmnt_context *o); extern int mnt_context_utab_writable(struct libmnt_context *cxt); extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt); +extern int mnt_context_within_helper(struct libmnt_context *cxt); + extern int mnt_context_get_mountinfo(struct libmnt_context *cxt, struct libmnt_table **tb); extern int mnt_context_get_mountinfo_for_target(struct libmnt_context *cxt, struct libmnt_table **mountinfo, const char *tgt); -- 2.47.2