Commit d088d664f2015ba9d168e61d56c599cee81f2aad
1 parent
04a6dfeb
linux-user: identify running binary in /proc/self/exe
Some applications like to test /proc/self/exe to find out who they are. Fake the result of readlink() for them. Use realpath() to return full path to binary (which the links /proc/self/exe are) Signed-off-by: Riku Voipio <riku.voipio@iki.fi> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6485 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
16 additions
and
3 deletions
linux-user/main.c
@@ -37,6 +37,8 @@ | @@ -37,6 +37,8 @@ | ||
37 | 37 | ||
38 | #define DEBUG_LOGFILE "/tmp/qemu.log" | 38 | #define DEBUG_LOGFILE "/tmp/qemu.log" |
39 | 39 | ||
40 | +char *exec_path; | ||
41 | + | ||
40 | static const char *interp_prefix = CONFIG_QEMU_PREFIX; | 42 | static const char *interp_prefix = CONFIG_QEMU_PREFIX; |
41 | const char *qemu_uname_release = CONFIG_UNAME_RELEASE; | 43 | const char *qemu_uname_release = CONFIG_UNAME_RELEASE; |
42 | 44 | ||
@@ -2341,6 +2343,7 @@ int main(int argc, char **argv, char **envp) | @@ -2341,6 +2343,7 @@ int main(int argc, char **argv, char **envp) | ||
2341 | if (optind >= argc) | 2343 | if (optind >= argc) |
2342 | usage(); | 2344 | usage(); |
2343 | filename = argv[optind]; | 2345 | filename = argv[optind]; |
2346 | + exec_path = argv[optind]; | ||
2344 | 2347 | ||
2345 | /* Zero out regs */ | 2348 | /* Zero out regs */ |
2346 | memset(regs, 0, sizeof(struct target_pt_regs)); | 2349 | memset(regs, 0, sizeof(struct target_pt_regs)); |
linux-user/qemu.h
@@ -120,6 +120,7 @@ typedef struct TaskState { | @@ -120,6 +120,7 @@ typedef struct TaskState { | ||
120 | uint8_t stack[0]; | 120 | uint8_t stack[0]; |
121 | } __attribute__((aligned(16))) TaskState; | 121 | } __attribute__((aligned(16))) TaskState; |
122 | 122 | ||
123 | +extern char *exec_path; | ||
123 | void init_task_state(TaskState *ts); | 124 | void init_task_state(TaskState *ts); |
124 | extern const char *qemu_uname_release; | 125 | extern const char *qemu_uname_release; |
125 | 126 |
linux-user/syscall.c
@@ -4410,13 +4410,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, | @@ -4410,13 +4410,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, | ||
4410 | #endif | 4410 | #endif |
4411 | case TARGET_NR_readlink: | 4411 | case TARGET_NR_readlink: |
4412 | { | 4412 | { |
4413 | - void *p2; | 4413 | + void *p2, *temp; |
4414 | p = lock_user_string(arg1); | 4414 | p = lock_user_string(arg1); |
4415 | p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); | 4415 | p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
4416 | if (!p || !p2) | 4416 | if (!p || !p2) |
4417 | ret = -TARGET_EFAULT; | 4417 | ret = -TARGET_EFAULT; |
4418 | - else | ||
4419 | - ret = get_errno(readlink(path(p), p2, arg3)); | 4418 | + else { |
4419 | + if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) { | ||
4420 | + char real[PATH_MAX]; | ||
4421 | + temp = realpath(exec_path,real); | ||
4422 | + ret = (temp==NULL) ? get_errno(-1) : strlen(real) ; | ||
4423 | + snprintf((char *)p2, arg3, "%s", real); | ||
4424 | + } | ||
4425 | + else | ||
4426 | + ret = get_errno(readlink(path(p), p2, arg3)); | ||
4427 | + break; | ||
4428 | + } | ||
4420 | unlock_user(p2, arg2, ret); | 4429 | unlock_user(p2, arg2, ret); |
4421 | unlock_user(p, arg1, 0); | 4430 | unlock_user(p, arg1, 0); |
4422 | } | 4431 | } |