Wie kann ich mithilfe der Busybox Ash Shell ein Programm mit geändertem argv[0] ausführen?

Wie kann ich mithilfe der Busybox Ash Shell ein Programm mit geändertem argv[0] ausführen?

In bashwürde ich einfach verwenden exec -a. Wie kann ich das in Busybox machen? Ist das überhaupt möglich oder muss ich mein eigenes C-Programm schreiben, um es exec(3)direkt aufzurufen?

Antwort1

Welche Version von Busybox hast du? Lauthttps://git.busybox.net/busybox/tree/shell/ash.cWenn man sich umschaut, execfindet man in der Zeile 9352 oder so den folgenden Code, der zu unterstützen scheintexec [-a customname] ...

execcmd(int argc UNUSED_PARAM, char **argv)
{
    optionarg = NULL;
    while (nextopt("a:") != '\0')
        /* nextopt() sets optionarg to "-a ARGV0" */;

    argv = argptr;
    if (argv[0]) {
        char *prog;

        iflag = 0;              /* exit on error */
        mflag = 0;
        optschanged();
        /* We should set up signals for "exec CMD"
         * the same way as for "CMD" without "exec".
         * But optschanged->setinteractive->setsignal
         * still thought we are a root shell. Therefore, for example,
         * SIGQUIT is still set to IGN. Fix it:
         */
        shlvl++;
        setsignal(SIGQUIT);
        /*setsignal(SIGTERM); - unnecessary because of iflag=0 */
        /*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
        /*setsignal(SIGTTOU); - unnecessary because of mflag=0 */

        prog = argv[0];
        if (optionarg)
            argv[0] = optionarg;
        shellexec(prog, argv, pathval(), 0);

Antwort2

verwandte Informationen