From a72b6681d981967f2aa1463a2d2f738c5f556b4a Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Tue, 30 Jul 2024 14:16:20 +0200 Subject: [PATCH] util/misc: use memfd helpers over direct ioctls Use the memfd helpers rather than directly invoking ioctls. This consolidates error handling in the helper. Signed-off-by: David Rheinsberg --- src/util/misc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/misc.c b/src/util/misc.c index 8fba5e51..ddd8f229 100644 --- a/src/util/misc.c +++ b/src/util/misc.c @@ -60,6 +60,7 @@ int misc_memfd(const char *name, unsigned int uflags, unsigned int useals) { _c_cleanup_(c_closep) int fd = -1; unsigned int flags = uflags; unsigned int seals = useals; + unsigned int kseals; struct stat st; int r; @@ -126,11 +127,11 @@ int misc_memfd(const char *name, unsigned int uflags, unsigned int useals) { * into the kernel again. */ if (seals) { - r = fcntl(fd, MISC_F_GET_SEALS); - if (r < 0) - return error_origin(-errno); + r = misc_memfd_get_seals(fd, &kseals); + if (r) + return error_fold(r); - if (seals & ~r) { + if (seals & ~kseals) { r = misc_memfd_add_seals(fd, seals); if (r) return error_fold(r);