summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-18 23:35:19 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-18 23:37:27 +0100
commit6afc95b73605833e6e966af1c466b5c08feb953f (patch)
tree28829a42e4ae84dd504988f5f9c8e4f998219565 /src/shared
parent0bc8e31b358a872ec2631874bd2109ba4e009ccf (diff)
nspawn: add new --personality= switch to make it easier to run 32bit containers on a 64bit host
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c30
-rw-r--r--src/shared/util.h2
2 files changed, 32 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 72b1e2f3c..99658f097 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -58,6 +58,7 @@
#include <limits.h>
#include <langinfo.h>
#include <locale.h>
+#include <sys/personality.h>
#include <libgen.h>
#undef basename
@@ -6192,3 +6193,32 @@ int fd_warn_permissions(const char *path, int fd) {
return 0;
}
+
+unsigned long parse_personality(const char *p) {
+
+ /* Parse a personality specifier. We introduce our own
+ * identifiers that indicate specific ABIs, rather than just
+ * hints regarding the register size, since we want to keep
+ * things open for multiple locally supported ABIs for the
+ * same register size. We try to reuse the ABI identifiers
+ * used by libseccomp. */
+
+#if defined(__x86_64__)
+
+ if (streq(p, "x86"))
+ return PER_LINUX32;
+
+ if (streq(p, "x86-64"))
+ return PER_LINUX;
+
+#elif defined(__i386__)
+
+ if (streq(p, "x86"))
+ return PER_LINUX;
+#endif
+
+ /* personality(7) documents that 0xffffffffUL is used for
+ * querying the current personality, hence let's use that here
+ * as error indicator. */
+ return 0xffffffffUL;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index a41348e32..e379c30e6 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -870,3 +870,5 @@ int mkostemp_safe(char *pattern, int flags);
int open_tmpfile(const char *path, int flags);
int fd_warn_permissions(const char *path, int fd);
+
+unsigned long parse_personality(const char *p);