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?

  • Where did you get the busybox binary, or how did you compile it? Does it use hush or ash (what's the output of busybox sh --help)? – Gilles 'SO- stop being evil' Apr 27 '17 at 22:20
  • It uses ash. lalala – ali1234 Apr 28 '17 at 22:29
  • @ali1234 Was your question answered? – phk Sep 20 '17 at 3:55

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;
        /* 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:
        /*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);
  • I have v1.25.1. This function is very different. – ali1234 Apr 27 '17 at 19:09
  • @ali1234 Then I think your busybox doesn't have this capability at all. – Gilles 'SO- stop being evil' Apr 27 '17 at 22:22

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.