summaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authoraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-30 20:09:01 +0000
committeraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-30 20:09:01 +0000
commitc0adcb44086db43e4509983cf231accae39b174c (patch)
treea299f658523698fc9e6ad3007e19003a5e60abd8 /linux-user
parent0f9246a0c10e473cf859a645174f60276910d3db (diff)
downloadqemu-c0adcb44086db43e4509983cf231accae39b174c.tar.gz
qemu-c0adcb44086db43e4509983cf231accae39b174c.tar.bz2
qemu-c0adcb44086db43e4509983cf231accae39b174c.zip
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
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/main.c3
-rw-r--r--linux-user/qemu.h1
-rw-r--r--linux-user/syscall.c15
3 files changed, 16 insertions, 3 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 2841120430..95efe398c7 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -37,6 +37,8 @@
#define DEBUG_LOGFILE "/tmp/qemu.log"
+char *exec_path;
+
static const char *interp_prefix = CONFIG_QEMU_PREFIX;
const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
@@ -2341,6 +2343,7 @@ int main(int argc, char **argv, char **envp)
if (optind >= argc)
usage();
filename = argv[optind];
+ exec_path = argv[optind];
/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 9fddd0519c..41375677fe 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -120,6 +120,7 @@ typedef struct TaskState {
uint8_t stack[0];
} __attribute__((aligned(16))) TaskState;
+extern char *exec_path;
void init_task_state(TaskState *ts);
extern const char *qemu_uname_release;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3e21bb311c..8d52099cb9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4410,13 +4410,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#endif
case TARGET_NR_readlink:
{
- void *p2;
+ void *p2, *temp;
p = lock_user_string(arg1);
p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!p || !p2)
ret = -TARGET_EFAULT;
- else
- ret = get_errno(readlink(path(p), p2, arg3));
+ else {
+ if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) {
+ char real[PATH_MAX];
+ temp = realpath(exec_path,real);
+ ret = (temp==NULL) ? get_errno(-1) : strlen(real) ;
+ snprintf((char *)p2, arg3, "%s", real);
+ }
+ else
+ ret = get_errno(readlink(path(p), p2, arg3));
+ break;
+ }
unlock_user(p2, arg2, ret);
unlock_user(p, arg1, 0);
}