qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] linux-user: manage binfmt-misc preserve-arg[0] flag


From: Laurent Vivier
Subject: Re: [PATCH] linux-user: manage binfmt-misc preserve-arg[0] flag
Date: Mon, 22 Feb 2021 18:09:02 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

Le 22/02/2021 à 15:45, Michael Tokarev a écrit :
> 22.02.2021 13:50, Laurent Vivier wrote:
>> Add --preserve-argv0 in qemu-binfmt-conf.sh to configure the preserve-argv0
>> flag.
>>
>> This patch allows to use new flag in AT_FLAGS to detect if
>> preserve-argv0 is configured for this interpreter:
>> argv[0] (the full pathname provided by binfmt-misc) is removed and
>> replaced by argv[1] (the original argv[0] provided by binfmt-misc when
>> 'P'/preserve-arg[0] is set)
> 
> A few days ago I sent an RFC patch which fixes this issue without kernel
> patch, by registering special binary name in binfmt (note: that patch had
> argv[1] & argv[2] swapped by mistake).
> 
> Here it is: 
> https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04639.html
>
In this case, we don't want to modify QEMU to manage special case based on the 
binary name but
instead use a wrapper:

- add a proper parameter to manage the argv0 case
  [like this one 
https://patchew.org/QEMU/20191024153847.31815-1-laurent@vivier.eu/
   but I think now it would be better to use a new flag rather than using -0 ""]

- write a wrapper and name it "/usr/libexec/qemu-binfmt/foo-binfmt-P"

- the wrapper will call qemu-foo with the new parameter:

something like (with the example patch above):

#include <stdio.h>
#include <unistd.h>
#include <string.h>

static const char *baseargv[] = {
        "-0",
        "",
};

int main(int argc, char **argv, char **envp) {
        char *newargv[argc + sizeof(baseargv) / sizeof(char *) + 1];
        int current = 0;

        newargv[current] = argv[0];
        current++;

        memcpy(&newargv[current], baseargv, sizeof(baseargv));
        current += sizeof(baseargv) / sizeof(char *);

        memcpy(&newargv[current], &argv[1], sizeof(*argv) * (argc - 1));
        current += argc - 1;

        newargv[current] = NULL;

        return execve("/qemu-foo", newargv, envp);
}

Thanks,
Laurent



reply via email to

[Prev in Thread] Current Thread [Next in Thread]