summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-05-04 09:00:12 +0200
committerAlexander Larsson <alexl@redhat.com>2016-05-04 09:00:12 +0200
commit131961644d1b8da9ee196916e4eee3f2bc195e0c (patch)
treef49fbc05b8ea27539aea09c06179cbc70088d1d7 /common
parent098e3e426de4faa6cdef92dc5e00e95475481224 (diff)
downloadxdg-app-131961644d1b8da9ee196916e4eee3f2bc195e0c.tar.gz
Use the userspace arch as the default, not the kernel arch
Its not super uncommon to e.g. have a 64bit kernel with 32bit userspace. So, we default to the arch xdg-app was built for, rather than what uname reports (the kernel version).
Diffstat (limited to 'common')
-rw-r--r--common/xdg-app-utils.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/common/xdg-app-utils.c b/common/xdg-app-utils.c
index cbf5031..cdd48d0 100644
--- a/common/xdg-app-utils.c
+++ b/common/xdg-app-utils.c
@@ -158,18 +158,8 @@ xdg_app_fail (GError **error, const char *format, ...)
return FALSE;
}
-
-/* This maps the kernel-reported uname to a single string representing
- * the cpu family, in the sense that all members of this family would
- * be able to understand and link to a binary file with such cpu
- * opcodes. That doesn't necessarily mean that all members of the
- * family can run all opcodes, for instance for modern 32bit intel we
- * report "i386", even though they support instructions that the
- * original i386 cpu cannot run. Still, such an executable would
- * at least try to execute a 386, wheras an arm binary would not.
- */
const char *
-xdg_app_get_arch (void)
+xdg_app_get_kernel_arch (void)
{
static struct utsname buf;
static char *arch = NULL;
@@ -216,6 +206,40 @@ xdg_app_get_arch (void)
return arch;
}
+
+/* This maps the kernel-reported uname to a single string representing
+ * the cpu family, in the sense that all members of this family would
+ * be able to understand and link to a binary file with such cpu
+ * opcodes. That doesn't necessarily mean that all members of the
+ * family can run all opcodes, for instance for modern 32bit intel we
+ * report "i386", even though they support instructions that the
+ * original i386 cpu cannot run. Still, such an executable would
+ * at least try to execute a 386, wheras an arm binary would not.
+ */
+const char *
+xdg_app_get_arch (void)
+{
+ /* Avoid using uname on multiarch machines, because uname reports the kernels
+ * arch, and that may be different from userspace. If e.g. the kernel is 64bit and
+ * the userspace is 32bit we want to use 32bit by default. So, we take the current build
+ * arch as the default. */
+#if defined(__i386__)
+ return "i386";
+#elif defined(__x86_64__)
+ return "x86_64";
+#elif defined(__aarch64__)
+ return "aarch64";
+#elif defined(__arm__)
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ return "arm";
+#else
+ return "armeb";
+#endif
+#else
+ return xdg_app_get_kernel_arch ();
+#endif
+}
+
const char *
xdg_app_get_bwrap (void)
{