]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: move memfd_create() definition
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 18 Oct 2017 11:36:36 +0000 (13:36 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 21 Oct 2017 14:30:03 +0000 (16:30 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/utils.h

index 88ed2b7a632e9bc83053e047442ff14fb20a9f41..3b1e422a3f8ff5b572d585a47ab619c55db08288 100644 (file)
 #include <../include/openpty.h>
 #endif
 
-#ifdef HAVE_LINUX_MEMFD_H
-#include <linux/memfd.h>
-#endif
-
 #include "af_unix.h"
 #include "caps.h"       /* for lxc_caps_last_cap() */
 #include "cgroup.h"
@@ -181,59 +177,6 @@ static int sethostname(const char * name, size_t len)
 #define MS_LAZYTIME (1<<25)
 #endif
 
-/* memfd_create() */
-#ifndef MFD_CLOEXEC
-#define MFD_CLOEXEC 0x0001U
-#endif
-
-#ifndef MFD_ALLOW_SEALING
-#define MFD_ALLOW_SEALING 0x0002U
-#endif
-
-#ifndef HAVE_MEMFD_CREATE
-static int memfd_create(const char *name, unsigned int flags) {
-       #ifndef __NR_memfd_create
-               #if defined __i386__
-                       #define __NR_memfd_create 356
-               #elif defined __x86_64__
-                       #define __NR_memfd_create 319
-               #elif defined __arm__
-                       #define __NR_memfd_create 385
-               #elif defined __aarch64__
-                       #define __NR_memfd_create 279
-               #elif defined __s390__
-                       #define __NR_memfd_create 350
-               #elif defined __powerpc__
-                       #define __NR_memfd_create 360
-               #elif defined __sparc__
-                       #define __NR_memfd_create 348
-               #elif defined __blackfin__
-                       #define __NR_memfd_create 390
-               #elif defined __ia64__
-                       #define __NR_memfd_create 1340
-               #elif defined _MIPS_SIM
-                       #if _MIPS_SIM == _MIPS_SIM_ABI32
-                               #define __NR_memfd_create 4354
-                       #endif
-                       #if _MIPS_SIM == _MIPS_SIM_NABI32
-                               #define __NR_memfd_create 6318
-                       #endif
-                       #if _MIPS_SIM == _MIPS_SIM_ABI64
-                               #define __NR_memfd_create 5314
-                       #endif
-               #endif
-       #endif
-       #ifdef __NR_memfd_create
-       return syscall(__NR_memfd_create, name, flags);
-       #else
-       errno = ENOSYS;
-       return -1;
-       #endif
-}
-#else
-extern int memfd_create(const char *name, unsigned int flags);
-#endif
-
 char *lxchook_names[NUM_LXC_HOOKS] = {"pre-start", "pre-mount", "mount",
                                      "autodev",   "start",     "stop",
                                      "post-stop", "clone",     "destroy",
index 41c43827a7e887b206b355de5440bbb6cdbcbfdd..2005aa61e54142132dddc2442f6665689e507dba 100644 (file)
 #include <sys/types.h>
 #include <sys/vfs.h>
 
+#ifdef HAVE_LINUX_MEMFD_H
+#include <linux/memfd.h>
+#endif
+
 #include "initutils.h"
 
 /* Define __S_ISTYPE if missing from the C library. */
@@ -184,6 +188,59 @@ static inline int signalfd(int fd, const sigset_t *mask, int flags)
 #define LOOP_CTL_GET_FREE 0x4C82
 #endif
 
+/* memfd_create() */
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+
+#ifndef MFD_ALLOW_SEALING
+#define MFD_ALLOW_SEALING 0x0002U
+#endif
+
+#ifndef HAVE_MEMFD_CREATE
+static inline int memfd_create(const char *name, unsigned int flags) {
+       #ifndef __NR_memfd_create
+               #if defined __i386__
+                       #define __NR_memfd_create 356
+               #elif defined __x86_64__
+                       #define __NR_memfd_create 319
+               #elif defined __arm__
+                       #define __NR_memfd_create 385
+               #elif defined __aarch64__
+                       #define __NR_memfd_create 279
+               #elif defined __s390__
+                       #define __NR_memfd_create 350
+               #elif defined __powerpc__
+                       #define __NR_memfd_create 360
+               #elif defined __sparc__
+                       #define __NR_memfd_create 348
+               #elif defined __blackfin__
+                       #define __NR_memfd_create 390
+               #elif defined __ia64__
+                       #define __NR_memfd_create 1340
+               #elif defined _MIPS_SIM
+                       #if _MIPS_SIM == _MIPS_SIM_ABI32
+                               #define __NR_memfd_create 4354
+                       #endif
+                       #if _MIPS_SIM == _MIPS_SIM_NABI32
+                               #define __NR_memfd_create 6318
+                       #endif
+                       #if _MIPS_SIM == _MIPS_SIM_ABI64
+                               #define __NR_memfd_create 5314
+                       #endif
+               #endif
+       #endif
+       #ifdef __NR_memfd_create
+       return syscall(__NR_memfd_create, name, flags);
+       #else
+       errno = ENOSYS;
+       return -1;
+       #endif
+}
+#else
+extern int memfd_create(const char *name, unsigned int flags);
+#endif
+
 /* Struct to carry child pid from lxc_popen() to lxc_pclose().
  * Not an opaque struct to allow direct access to the underlying FILE *
  * (i.e., struct lxc_popen_FILE *file; fgets(buf, sizeof(buf), file->f))