Skip to content

Commit

Permalink
bsd-user: Add '-0 argv0' option to bsd-user/main.c
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cperciva authored and bsdimp committed Sep 10, 2021
1 parent 63cca10 commit b801264
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bsd-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down

0 comments on commit b801264

Please sign in to comment.