summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linux-user/binfmt.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/linux-user/binfmt.c b/linux-user/binfmt.c
index 458f136fb..26bb38814 100644
--- a/linux-user/binfmt.c
+++ b/linux-user/binfmt.c
@@ -4,10 +4,7 @@
#include <libgen.h>
#include <string.h>
#include <stdlib.h>
-
-#ifdef __x86_64__
-#define ARCH_NAME "x86_64"
-#endif
+#include <limits.h>
int main(int argc, char **argv, char **envp)
{
@@ -31,18 +28,20 @@ int main(int argc, char **argv, char **envp)
binfmt[0] = '\0';
/* Now argv[0] is the real qemu binary name */
-#ifdef ARCH_NAME
{
- char *hostbin;
- char *guestarch;
int r;
+ char buf[PATH_MAX];
+ char *hostbin;
+ char *path;
- guestarch = strrchr(argv[0], '-') ;
- if (!guestarch) {
- goto skip;
+ /* Follow symbolic link if any. */
+ path = realpath(argv[1], buf);
+ if (path == NULL) {
+ /* Error occured, falling back to original argument */
+ path = argv[1];
}
- guestarch++;
- r = asprintf(&hostbin, "/emul/" ARCH_NAME "-for-%s/%s", guestarch, argv[1]);
+
+ r = asprintf(&hostbin, "/emul/%s", path);
if ((r > 0) && !access(hostbin, X_OK)) {
/*
* We found a host binary replacement for the non-host binary. Let's
@@ -51,8 +50,6 @@ int main(int argc, char **argv, char **envp)
return execve(hostbin, &argv[2], envp);
}
}
-skip:
-#endif
new_argv = (char **)malloc((argc + 2) * sizeof(*new_argv));
if (argc > 3) {