busybox ash 쉘을 사용하여 수정된 argv[0]으로 프로그램을 어떻게 실행할 수 있나요?

busybox ash 쉘을 사용하여 수정된 argv[0]으로 프로그램을 어떻게 실행할 수 있나요?

나는 bash단순히 exec -a. 비지박스에서 이 작업을 어떻게 수행할 수 있나요? 가능합니까, 아니면 exec(3)직접 호출하려면 자체 C 프로그램을 작성해야 합니까?

답변1

어떤 버전의 busybox를 사용하고 있나요? 에 따르면https://git.busybox.net/busybox/tree/shell/ash.c자세히 살펴보면 exec라인 9352 부근에서 지원하는 것으로 보이는 다음 코드를 만날 수 있습니다.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

exec -aBusybox 1.27부터 지원됩니다., 다음에 대한 답변도 참조하세요.대상 애플리케이션의 0번째 인수를 설정하는 POSIX 방법이 있습니까?다른 방법으로 달성하는 방법에 대해 알아보세요.

관련 정보