linux-user: identify running binary in /proc/self/exe
authorRiku Voipio <riku.voipio@nokia.com>
Fri, 9 Jan 2009 15:46:16 +0000 (17:46 +0200)
committerRiku Voipio <riku.voipio@nokia.com>
Wed, 14 Jan 2009 14:59:46 +0000 (16:59 +0200)
Some applications like to test /proc/self/exe to find
out whoe they are. Fake the result of readlink() for
them.

linux-user/main.c
linux-user/qemu.h
linux-user/syscall.c

index 3019f33..2ffe244 100644 (file)
@@ -34,6 +34,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;
 
@@ -2314,6 +2316,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));
index 9fddd05..4137567 100644 (file)
@@ -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;
 
index adb27de..53167e9 100644 (file)
@@ -4720,8 +4720,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 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)
+                    ret = get_errno(snprintf((char *)p2, arg3, "%s", exec_path));
+                else
+                    ret = get_errno(readlink(path(p), p2, arg3));
+                break;
+            }
             unlock_user(p2, arg2, ret);
             unlock_user(p, arg1, 0);
         }