Ignore:
Timestamp:
Jan 13, 2010, 2:45:49 AM (16 years ago)
Author:
bird
Message:

kash: Fixed some file handle inheritance issues on windows. piping to the native sort.exe works now.

File:
1 edited

Legend:

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

    r2312 r2376  
    548548                        if (hFile != INVALID_HANDLE_VALUE)
    549549                        {
    550                             int fd2 = shfile_insert(pfdtab, (intptr_t)hFile, aStdHandles[i].fFlags, 0, i, "shtab_init");
     550                            DWORD       dwType  = GetFileType(hFile);
     551                            unsigned    fFlags  = aStdHandles[i].fFlags;
     552                            unsigned    fFlags2;
     553                            int         fd2;
     554                            if (dwType == FILE_TYPE_CHAR)
     555                                fFlags2 = SHFILE_FLAGS_TTY;
     556                            else if (dwType == FILE_TYPE_PIPE)
     557                                fFlags2 = SHFILE_FLAGS_PIPE;
     558                            else
     559                                fFlags2 = SHFILE_FLAGS_FILE;
     560                            fd2 = shfile_insert(pfdtab, (intptr_t)hFile, fFlags, fFlags2, i, "shtab_init");
    551561                            assert(fd2 == i); (void)fd2;
    552562                            if (fd2 != i)
     
    588598
    589599    shmtx_enter(&pfdtab->mtx, &tmp);
    590     TRACE2((NULL, "shfile_fork_win:\n"));
     600    TRACE2((NULL, "shfile_fork_win: set=%d\n", set));
    591601
    592602    i = pfdtab->size;
     
    598608            if (set)
    599609                TRACE2((NULL, "  #%d: native=%#x oflags=%#x shflags=%#x\n",
    600                         i, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags, hFile));
     610                        i, hFile, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags));
    601611            if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag))
    602612            {
     
    612622        {
    613623            if (    pfdtab->size > i
    614                 &&  pfdtab->tab[i].fd == 0)
     624                &&  pfdtab->tab[i].fd == i)
    615625                hndls[i] = pfdtab->tab[i].native;
    616626            else
    617627                hndls[i] = (intptr_t)INVALID_HANDLE_VALUE;
     628            TRACE2((NULL, "shfile_fork_win: i=%d size=%d fd=%d native=%d hndls[%d]=%p\n",
     629                    i, pfdtab->size, pfdtab->tab[i].fd, pfdtab->tab[i].native, i, hndls[i]));
    618630        }
    619631    }
     
    644656
    645657    shmtx_enter(&pfdtab->mtx, &tmp);
    646     TRACE2((NULL, "shfile_fork_win:\n"));
     658    TRACE2((NULL, "shfile_exec_win: prepare=%p\n", prepare));
    647659
    648660    count  = pfdtab->size < (0x10000-4) / (1 + sizeof(HANDLE))
    649661           ? pfdtab->size
    650662           : (0x10000-4) / (1 + sizeof(HANDLE));
    651     while (count > 3 && pfdtab->tab[count].fd == -1)
     663    while (count > 3 && pfdtab->tab[count - 1].fd == -1)
    652664        count--;
    653665
     
    669681                HANDLE hFile = (HANDLE)pfdtab->tab[i].native;
    670682                TRACE2((NULL, "  #%d: native=%#x oflags=%#x shflags=%#x\n",
    671                         i, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags, hFile));
     683                        i, hFile, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags));
    672684
    673685                if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
     
    697709        for (i = 0; i < 3; i++)
    698710        {
    699             if (    count > i
    700                 &&  pfdtab->tab[i].fd == 0)
     711            if (    i < count
     712                &&  pfdtab->tab[i].fd == i)
    701713                hndls[i] = pfdtab->tab[i].native;
    702714            else
    703715                hndls[i] = (intptr_t)INVALID_HANDLE_VALUE;
     716            TRACE2((NULL, "shfile_exec_win: i=%d count=%d fd=%d native=%d hndls[%d]=\n",
     717                    i, count, pfdtab->tab[i].fd, pfdtab->tab[i].native, i, hndls[i]));
    704718        }
    705719
Note: See TracChangeset for help on using the changeset viewer.