summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Isorce <j.isorce@samsung.com>2016-05-10 13:18:06 +0100
committerwanchao-xu <wanchao.xu@samsung.com>2024-01-10 17:16:38 +0800
commit2feb467573ee11fe485e5cc05fda62da43919bd8 (patch)
tree86cc4531506dcde5fe9015819f6b0387131d2f9d
parent9bf1785bf74d34541714d19f81263011e3567783 (diff)
downloadqemu-arm-static-2feb467573ee11fe485e5cc05fda62da43919bd8.tar.gz
qemu-arm-static-2feb467573ee11fe485e5cc05fda62da43919bd8.tar.bz2
qemu-arm-static-2feb467573ee11fe485e5cc05fda62da43919bd8.zip
binfmt: translate symbolic links correctly with realpath
Change-Id: Ic0eeac9de40a8e1082c83b442829ac28f68bff04 Signed-off-by: Julien Isorce <j.isorce@samsung.com> Signed-off-by: Yury Usishchev <y.usishchev@samsung.com>
-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) {