Ignore:
Timestamp:
Mar 20, 2018, 4:13:12 AM (7 years ago)
Author:
bird
Message:

kmk/win: Pretty sure I made this lpReserved2 mistake before. Duh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/w32/winchildren.c

    r3161 r3162  
    396396     */
    397397    InitializeSRWLock(&g_RWLock);
     398
     399    /*
     400     * This is dead code that was thought to fix a problem observed doing
     401     * `tcc.exe /c "kmk |& tee bld.log"` and leading to a crash in cl.exe
     402     * when spawned with fInheritHandles = FALSE, see hStdErr=NULL in the
     403     * child.  However, it turns out this was probably caused by not clearing
     404     * the CRT file descriptor and handle table in the startup info.
     405     * Leaving the code here in case it comes in handy after all.
     406     */
     407#if 0
     408    {
     409        struct
     410        {
     411            DWORD  uStdHandle;
     412            HANDLE hHandle;
     413        } aHandles[3] = { { STD_INPUT_HANDLE, NULL }, { STD_OUTPUT_HANDLE, NULL }, { STD_ERROR_HANDLE, NULL } };
     414        int i;
     415
     416        for (i = 0; i < 3; i++)
     417            aHandles[i].hHandle = GetStdHandle(aHandles[i].uStdHandle);
     418
     419        for (i = 0; i < 3; i++)
     420            if (   aHandles[i].hHandle == NULL
     421                || aHandles[i].hHandle == INVALID_HANDLE_VALUE)
     422            {
     423                int fd = open("nul", _O_RDWR);
     424                if (fd >= 0)
     425                {
     426                    if (_dup2(fd, i) >= 0)
     427                    {
     428                        assert((HANDLE)_get_osfhandle(i) != aHandles[i].hHandle);
     429                        assert((HANDLE)_get_osfhandle(i) == GetStdHandle(aHandles[i].uStdHandle));
     430                    }
     431                    else
     432                        ONNNS(fatal, NILF, "_dup2(%d('nul'), %d) failed: %u (%s)", fd, i, errno, strerror(errno));
     433                    if (fd != i)
     434                        close(fd);
     435                }
     436                else
     437                    ONNS(fatal, NILF, "open(nul,RW) failed: %u (%s)", i, errno, strerror(errno));
     438            }
     439            else
     440            {
     441                int j;
     442                for (j = i + 1; j < 3; j++)
     443                    if (aHandles[j].hHandle == aHandles[i].hHandle)
     444                    {
     445                        int fd = _dup(j);
     446                        if (fd >= 0)
     447                        {
     448                            if (_dup2(fd, j) >= 0)
     449                            {
     450                                aHandles[j].hHandle = (HANDLE)_get_osfhandle(j);
     451                                assert(aHandles[j].hHandle != aHandles[i].hHandle);
     452                                assert(aHandles[j].hHandle == GetStdHandle(aHandles[j].uStdHandle));
     453                            }
     454                            else
     455                                ONNNS(fatal, NILF, "_dup2(%d, %d) failed: %u (%s)", fd, j, errno, strerror(errno));
     456                            if (fd != j)
     457                                close(fd);
     458                        }
     459                        else
     460                            ONNS(fatal, NILF, "_dup(%d) failed: %u (%s)", j, errno, strerror(errno));
     461                    }
     462            }
     463    }
     464#endif
    398465}
    399466
     
    538605    StartupInfo.cb = sizeof(StartupInfo);
    539606    GetStartupInfoW(&StartupInfo);
     607    StartupInfo.lpReserved2 = 0; /* No CRT file handle + descriptor info possible, sorry. */
     608    StartupInfo.cbReserved2 = 0;
    540609    if (!fHaveHandles)
    541610        StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
     
    544613        fFlags |= CREATE_SUSPENDED;
    545614        StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
    546 
    547         /* Don't pass CRT inheritance info to the child (from our parent actually). */
    548         StartupInfo.cbReserved2 = 0;
    549         StartupInfo.lpReserved2 = 0;
    550615    }
    551616
     
    24042469}
    24052470
     2471#if 0  /* no longer needed */
    24062472/** Serialization with kmkbuiltin_redirect. */
    24072473void MkWinChildExclusiveAcquire(void)
     
    24152481    ReleaseSRWLockExclusive(&g_RWLock);
    24162482}
     2483#endif
    24172484
    24182485/**
Note: See TracChangeset for help on using the changeset viewer.