busybox ash shellを使用して、変更されたargv[0]を持つプログラムを実行するにはどうすればよいですか?

busybox ash shellを使用して、変更されたargv[0]を持つプログラムを実行するにはどうすればよいですか?

では、bash単に を使用しますexec -a。busybox でこれを行うにはどうすればよいですか? これは可能ですか、それとも直接呼び出すために独自の C プログラムを作成する必要がありますかexec(3)?

答え1

ビジーボックスのどのバージョンをお持ちですか?https://git.busybox.net/busybox/tree/shell/ash.cexec9352行目あたりに次のようなコードが見つかるかもしれない。exec [-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);

答え2

関連情報