2

In bash I would simply use exec -a. How can I do this in busybox? Is it even possible, or will I have to write my own C program to call exec(3) directly?

ali1234
  • 1,044
  • 2
  • 11
  • 20

2 Answers2

1

What version of busybox do you have? According to https://git.busybox.net/busybox/tree/shell/ash.c if one delves around for exec one may encounter around line 9352 or so the following code which appears to support 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);
thrig
  • 34,333
  • 3
  • 63
  • 84
1

exec -a is supported since Busybox 1.27, see also the answers to Is there a POSIX way of setting zeroth argument of a target application? for how to do achieve it some other way.

phk
  • 5,893
  • 7
  • 41
  • 70