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?

3
  • 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)? Apr 27, 2017 at 22:20
  • It uses ash. lalala
    – ali1234
    Apr 28, 2017 at 22:29
  • @ali1234 Was your question answered?
    – phk
    Sep 20, 2017 at 3:55

2 Answers 2

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);
2
  • I have v1.25.1. This function is very different.
    – ali1234
    Apr 27, 2017 at 19:09
  • @ali1234 Then I think your busybox doesn't have this capability at all. Apr 27, 2017 at 22:22
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .