Unreachable code in evalsubshell()?

Denys Vlasenko <[email protected]> Tue, 27 Jan 2026 05:26:13 +0100
Newsgroups org.kernel.vger.dash
Message-ID <CAK1hOcNHGv-7tkmD=XKw_oTy0s4NvZY0n1Mq4m_5_NX9miU2_Q@mail.gmail.com>
        switch (n->type) {
...
        case NBACKGND:
                evalfn = evalsubshell;  //THIS IS THE ONLY USE OF evalsubshell
                goto checkexit;
...
checkexit:
                checkexit = EV_TESTED;
                goto calleval;
...
calleval:
                status = evalfn(n, flags);

THe above means that in evalsubshell(n,...),
n->type is always NBACKGND.

STATIC int
evalsubshell(union node *n, int flags)
{
        struct job *jp;
        int backgnd = (n->type == NBACKGND);  // ALWAYS TRUE
        int status;

        errlinno = lineno = n->nredir.linno;
        if (funcline)
                lineno -= funcline - 1;

        expredir(n->nredir.redirect);
        INTOFF;
        if (!backgnd && flags & EV_EXIT && !have_traps()) {
//*** UNREACHABLE code branch *** !backgnd is FALSE
//*** (if we remove this, the nofork: label is also unused)
                forkreset(NULL);
                goto nofork;
        }
        jp = makejob(1);
        if (forkshell(jp, n->nredir.n, backgnd) == 0) {
//*** unreadable code: the backgnd is 1 in the line above, which in
this case means FORK_BG
//*** maybe make it explicit?
                flags |= EV_EXIT;
                if (backgnd)
                        flags &=~ EV_TESTED;
nofork: