diff options
author | Thomas Weißschuh <thomas@t-8ch.de> | 2023-03-14 03:42:05 +0000 |
---|---|---|
committer | Thomas Weißschuh <thomas@t-8ch.de> | 2023-03-15 01:18:59 +0000 |
commit | ad62530ebb397982a73266a07ac6f182e47922de (patch) | |
tree | 879739ab2946d212074439a4ed4986b17c4e6f68 /src/basic/memfd-util.c | |
parent | 8cb0a001d8193721af98a448d5b3615ac5e263f1 (diff) | |
download | systemd-ad62530ebb397982a73266a07ac6f182e47922de.tar.gz |
memfd-util: add wrapper for memfd_create
The wrapper removes the flags MFD_EXEC and MFD_NOEXEC_SEAL when running
on kernels not understanding those flags.
Diffstat (limited to 'src/basic/memfd-util.c')
-rw-r--r-- | src/basic/memfd-util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index 96024bc485..99df236e7d 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -20,6 +20,22 @@ #include "string-util.h" #include "utf8.h" +int memfd_create_wrapper(const char *name, unsigned mode) { + unsigned mode_compat; + int mfd; + + mfd = RET_NERRNO(memfd_create(name, mode)); + if (mfd != -EINVAL) + return mfd; + + mode_compat = mode & ~(MFD_EXEC | MFD_NOEXEC_SEAL); + + if (mode == mode_compat) + return mfd; + + return RET_NERRNO(memfd_create(name, mode_compat)); +} + int memfd_new(const char *name) { _cleanup_free_ char *g = NULL; |