Как я могу запустить программу с измененным argv [0], используя оболочку пепла busybox?

Вы также можете использовать аргумент -w для curl :

> curl -fs -w "%{response_code},%{redirect_url}\n" -o /dev/null http://google.com
302,http://www.google.de/?gfe_rd=cr&ei=...
2
27.04.2017, 21:12
2 ответа

Какая у вас версия 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);
1
27.01.2020, 22:10

Теги

Похожие вопросы