Changeset 2376


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.

Location:
trunk/src/kash
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/Makefile.kmk

    r2315 r2376  
    191191endif
    192192
     193#
     194# For debugging file handle inheritance on Windows.
     195#
     196if "$(KBUILD_TARGET)" == win && 0
     197PROGRAMS += tstDump
     198tstDump_TEMPLATE = BIN
     199tstDump_SOURCES = tstDump.c
     200endif
     201
    193202# Include the sub-makefile.
    194203include $(PATH_SUB_CURRENT)/tests/Makefile.kmk
  • 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
  • trunk/src/kash/shinstance.c

    r2362 r2376  
    899899#if K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE)
    900900    pid = shfork_do_it(psh);
     901    if (pid == 0)
     902        shthread_set_shell(psh);
    901903
    902904#elif defined(SH_FORKED_MODE)
     
    11411143
    11421144        /* File handles. */
     1145        StrtInfo.dwFlags   |= STARTF_USESTDHANDLES;
    11431146        StrtInfo.lpReserved2 = shfile_exec_win(&psh->fdtab, 1 /* prepare */, &StrtInfo.cbReserved2, hndls);
    11441147        StrtInfo.hStdInput  = (HANDLE)hndls[0];
  • trunk/src/kash/show.c

    r2297 r2376  
    273273# define TRY_GET_PSH_OR_RETURN(psh)  \
    274274        if (!(psh)) { \
    275                 psh = shthread_get_shell(); \
    276                 if (!psh) \
     275                (psh) = shthread_get_shell(); \
     276                if (!(psh)) \
    277277                        return; \
    278278        } else do { } while (0)
Note: See TracChangeset for help on using the changeset viewer.