diff mbox series

[v2,42/43] bsd-user: Add '-0 argv0' option to bsd-user/main.c

Message ID 20210826211201.98877-43-imp@bsdimp.com (mailing list archive)
State New, archived
Headers show
Series bsd-user updates to run hello world | expand

Commit Message

Warner Losh Aug. 26, 2021, 9:12 p.m. UTC
From: Colin Percival <cperciva@tarsnap.com>

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 | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Philippe Mathieu-Daudé Aug. 27, 2021, 4:48 a.m. UTC | #1
On 8/26/21 11:12 PM, imp@bsdimp.com wrote:
> From: Colin Percival <cperciva@tarsnap.com>
> 
> 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 | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index b35bcf4d1e..ae25f4c773 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -268,6 +268,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();
>  
> @@ -390,6 +391,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();
>          }
> @@ -413,6 +416,8 @@ int main(int argc, char **argv)
>          usage();
>      }
>      filename = argv[optind];
> +    if (argv0)

Style:

{

> +        argv[optind] = argv0;

}

>  
>      if (!trace_init_backends()) {
>          exit(1);
>
Warner Losh Aug. 27, 2021, 2:52 p.m. UTC | #2
> On Aug 26, 2021, at 10:48 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> 
> On 8/26/21 11:12 PM, imp@bsdimp.com wrote:
>> From: Colin Percival <cperciva@tarsnap.com>
>> 
>> 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 | 5 +++++
>> 1 file changed, 5 insertions(+)
>> 
>> diff --git a/bsd-user/main.c b/bsd-user/main.c
>> index b35bcf4d1e..ae25f4c773 100644
>> --- a/bsd-user/main.c
>> +++ b/bsd-user/main.c
>> @@ -268,6 +268,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();
>> 
>> @@ -390,6 +391,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();
>>         }
>> @@ -413,6 +416,8 @@ int main(int argc, char **argv)
>>         usage();
>>     }
>>     filename = argv[optind];
>> +    if (argv0)
> 
> Style:
> 
> {
> 
>> +        argv[optind] = argv0;
> 
> }

Done in v3.

Warner

> 
>> 
>>     if (!trace_init_backends()) {
>>         exit(1);
diff mbox series

Patch

diff --git a/bsd-user/main.c b/bsd-user/main.c
index b35bcf4d1e..ae25f4c773 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -268,6 +268,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();
 
@@ -390,6 +391,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();
         }
@@ -413,6 +416,8 @@  int main(int argc, char **argv)
         usage();
     }
     filename = argv[optind];
+    if (argv0)
+        argv[optind] = argv0;
 
     if (!trace_init_backends()) {
         exit(1);