#include <sys/mman.h>
#include <sys/prctl.h>
+#ifdef HAVE_LINUX_MEMFD_H
+# include <linux/memfd.h>
+#endif
+
#include "util.h"
#include "bus-label.h"
-#include "missing.h"
#include "memfd.h"
#include "utf8.h"
+#include "missing.h"
int memfd_new(const char *name) {
-
_cleanup_free_ char *g = NULL;
int fd;
- if (name) {
- g = utf8_escape_invalid(name);
- if (!g)
- return -ENOMEM;
-
- name = g;
- } else {
+ if (!name) {
char pr[17] = {};
/* If no name is specified we generate one. We include
if (isempty(pr))
name = "sd";
else {
- g = strappend("sd-", pr);
+ _cleanup_free_ char *e = NULL;
+
+ e = utf8_escape_invalid(pr);
+ if (!e)
+ return -ENOMEM;
+
+ g = strappend("sd-", e);
if (!g)
return -ENOMEM;
}
}
- fd = memfd_create(name, MFD_ALLOW_SEALING);
+ fd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
if (fd < 0)
return -errno;
return -errno;
*sz = stat.st_size;
- return r;
+ return 0;
}
int memfd_set_size(int fd, uint64_t sz) {
if (r < 0)
return -errno;
- return r;
+ return 0;
}
int memfd_new_and_map(const char *name, size_t sz, void **p) {