Skip to content

Commit b801264

Browse files
cpercivabsdimp
authored andcommitted
bsd-user: Add '-0 argv0' option to bsd-user/main.c
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 <[email protected]> Signed-off-by: Warner Losh <[email protected]> Reviewed-by: Richard Henderson <[email protected]>
1 parent 63cca10 commit b801264

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bsd-user/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ int main(int argc, char **argv)
243243
char **target_environ, **wrk;
244244
envlist_t *envlist = NULL;
245245
bsd_type = HOST_DEFAULT_BSD_TYPE;
246+
char *argv0 = NULL;
246247

247248
adjust_ssize();
248249

@@ -367,6 +368,8 @@ int main(int argc, char **argv)
367368
do_strace = 1;
368369
} else if (!strcmp(r, "trace")) {
369370
trace_opt_parse(optarg);
371+
} else if (!strcmp(r, "0")) {
372+
argv0 = argv[optind++];
370373
} else {
371374
usage();
372375
}
@@ -390,6 +393,9 @@ int main(int argc, char **argv)
390393
usage();
391394
}
392395
filename = argv[optind];
396+
if (argv0) {
397+
argv[optind] = argv0;
398+
}
393399

394400
if (!trace_init_backends()) {
395401
exit(1);

0 commit comments

Comments
 (0)