Changeset 3442


Ignore:
Timestamp:
Sep 10, 2020, 2:06:29 PM (5 years ago)
Author:
bird
Message:

kash: Turns out the redirlist needs to be copied too.

Location:
trunk/src/kash
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/redir.c

    r3438 r3442  
    9090STATIC void openredirect(shinstance *, union node *, char[10], int);
    9191STATIC int openhere(shinstance *, union node *);
     92
     93
     94#ifndef SH_FORKED_MODE
     95void
     96subshellinitredir(shinstance *psh, shinstance *inherit)
     97{
     98    /* We can have a redirlist here if we're handling backtick while expanding
     99       arguments, just copy it even if the subshell probably doesn't need it. */
     100    struct redirtab *src = inherit->redirlist;
     101    if (src)
     102    {
     103        struct redirtab **dstp = &psh->redirlist;
     104        do
     105        {
     106            struct redirtab *dst = ckmalloc(psh, sizeof(dst));
     107            memcpy(dst->renamed, src->renamed, sizeof(dst->renamed));
     108            *dstp = dst;
     109            dstp = &dst->next;
     110            src = src->next;
     111        } while (src);
     112        *dstp = NULL;
     113
     114        psh->fd0_redirected = inherit->fd0_redirected;
     115    }
     116}
     117#endif /* !SH_FORKED_MODE */
    92118
    93119
  • trunk/src/kash/redir.h

    r3436 r3442  
    4040
    4141union node;
     42#ifndef SH_FORKED_MODE
     43void subshellinitredir(shinstance *, shinstance *);
     44#endif
    4245void redirect(struct shinstance *, union node *, int);
    4346void popredir(struct shinstance *);
  • trunk/src/kash/shinstance.c

    r3441 r3442  
    733733    /* The rest are internal to the parser, as I see them, and can be ignored. */
    734734
    735     /* redir.c - we shouldn't sub-shell with redirlist as non-NULL, I think.  */
    736     assert(inherit->redirlist == NULL);
    737     assert(inherit->fd0_redirected == 0); /* (follows from redirlist == NULL) */
     735    /* redir.c */
     736    subshellinitredir(psh, inherit);
    738737
    739738    /* show.c */
Note: See TracChangeset for help on using the changeset viewer.