Changeset 3464 for trunk/src


Ignore:
Timestamp:
Sep 15, 2020, 9:44:11 PM (5 years ago)
Author:
bird
Message:

kash: Try signal subshell completion as early as possible in all cases.

File:
1 edited

Legend:

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

    r3461 r3464  
    15071507}
    15081508
     1509/**
     1510 * If we have a subshell status structure, signal and release it.
     1511 */
     1512static void shsubshellstatus_signal_and_release(shinstance *psh, int iExit)
     1513{
     1514    shsubshellstatus *sts = psh->subshellstatus;
     1515    if (sts)
     1516    {
     1517        BOOL rc;
     1518        HANDLE hThread;
     1519
     1520        sts->status = W_EXITCODE(iExit, 0);
     1521        sts->done   = K_TRUE;
     1522        rc = SetEvent((HANDLE)sts->towaiton); assert(rc); K_NOREF(rc);
     1523
     1524        hThread = (HANDLE)sts->hThread;
     1525        sts->hThread = 0;
     1526        rc = CloseHandle(hThread); assert(rc);
     1527
     1528        shsubshellstatus_release(psh, sts);
     1529        psh->subshellstatus = NULL;
     1530    }
     1531}
     1532
     1533
    15091534#endif /* !SH_FORKED_MODE */
    15101535
     
    15931618    shinstance * volatile volpsh = (shinstance *)user;
    15941619    shinstance *psh = (shinstance *)user;
    1595     shsubshellstatus *sts;
    15961620    struct jmploc exitjmp;
    15971621    int iExit;
     
    16251649
    16261650    /* Signal parent. */
    1627     sts = psh->subshellstatus;
    1628     if (sts)
    1629     {
    1630         BOOL rc;
    1631         HANDLE hThread;
    1632 
    1633         sts->status = W_EXITCODE(iExit, 0);
    1634         sts->done   = K_TRUE;
    1635         rc = SetEvent((HANDLE)sts->towaiton); assert(rc); K_NOREF(rc);
    1636 
    1637         hThread = (HANDLE)sts->hThread;
    1638         sts->hThread = 0;
    1639         rc = CloseHandle(hThread); assert(rc);
    1640 
    1641         shsubshellstatus_release(psh, sts);
    1642         psh->subshellstatus = NULL;
    1643     }
     1651    shsubshellstatus_signal_and_release(psh, iExit);
    16441652
    16451653    /* destroy the shell instance and exit the thread. */
     
    18421850}
    18431851
    1844 SH_NORETURN_1 void sh__exit(shinstance *psh, int rc)
    1845 {
    1846     TRACE2((psh, "sh__exit(%d)\n", rc));
     1852SH_NORETURN_1 void sh__exit(shinstance *psh, int iExit)
     1853{
     1854    TRACE2((psh, "sh__exit(%d)\n", iExit));
    18471855
    18481856#if defined(SH_FORKED_MODE)
    1849     _exit(rc);
     1857    _exit(iExit);
    18501858    (void)psh;
    18511859
    18521860#else
    1853     psh->exitstatus = rc;
     1861    psh->exitstatus = iExit;
    18541862
    18551863    /*
     
    18581866    if (psh->thread)
    18591867    {
     1868        shsubshellstatus_signal_and_release(psh, iExit);
    18601869        if (psh->exitjmp)
    1861             longjmp(psh->exitjmp->loc, !rc ? SH_EXIT_ZERO : rc);
     1870            longjmp(psh->exitjmp->loc, !iExit ? SH_EXIT_ZERO : iExit);
    18621871        else
    18631872        {
    18641873            static char const s_msg[] = "fatal error in sh__exit: exitjmp is NULL!\n";
    18651874            shfile_write(&psh->fdtab, 2, s_msg, sizeof(s_msg) - 1);
    1866             _exit(rc);
     1875            _exit(iExit);
    18671876        }
    18681877    }
     
    18821891    }
    18831892
    1884     _exit(rc);
     1893    _exit(iExit);
    18851894#endif
    18861895}
     
    21132122                {
    21142123#ifndef SH_FORKED_MODE
    2115                     /** @todo signal the end of this subshell now, we can do the cleaning up
    2116                      *        after the parent shell has resumed. */
     2124                    shsubshellstatus_signal_and_release(psh, (int)dwExitCode);
    21172125#endif
    21182126                    CloseHandle(ProcInfo.hProcess);
Note: See TracChangeset for help on using the changeset viewer.