]> git.proxmox.com Git - mirror_qemu.git/commitdiff
bsd-user: Add '-0 argv0' option to bsd-user/main.c
authorColin Percival <cperciva@tarsnap.com>
Sat, 7 Aug 2021 20:34:21 +0000 (14:34 -0600)
committerWarner Losh <imp@bsdimp.com>
Fri, 10 Sep 2021 20:13:06 +0000 (14:13 -0600)
Previously it was impossible to emulate a program with a file name
different from its argv[0].  With this change, you can run
    qemu -0 fakename realname args
which runs the program "realname" with an argv of "fakename args".

Signed-off-by: Colin Percival <cperciva@tarsnap.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
bsd-user/main.c

index 659dd2b512dc1af1e9e2846e78cd6ea62f0f42ea..6df4f4f01136ff36e93a01e3e69857f4b8b0b6fb 100644 (file)
@@ -243,6 +243,7 @@ int main(int argc, char **argv)
     char **target_environ, **wrk;
     envlist_t *envlist = NULL;
     bsd_type = HOST_DEFAULT_BSD_TYPE;
+    char *argv0 = NULL;
 
     adjust_ssize();
 
@@ -367,6 +368,8 @@ int main(int argc, char **argv)
             do_strace = 1;
         } else if (!strcmp(r, "trace")) {
             trace_opt_parse(optarg);
+        } else if (!strcmp(r, "0")) {
+            argv0 = argv[optind++];
         } else {
             usage();
         }
@@ -390,6 +393,9 @@ int main(int argc, char **argv)
         usage();
     }
     filename = argv[optind];
+    if (argv0) {
+        argv[optind] = argv0;
+    }
 
     if (!trace_init_backends()) {
         exit(1);