VirtualBox

Changeset 2294 in kBuild


Ignore:
Timestamp:
Feb 28, 2009 8:33:26 AM (16 years ago)
Author:
bird
Message:

kash: more fixes + pipe.

Location:
trunk/src/kash
Files:
5 edited

Legend:

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

    r2292 r2294  
    134134                return 2;
    135135        shthread_set_shell(psh);
    136         return shell_main(psh, argc, argv);
     136        return shell_main(psh, argc, psh->argptr);
    137137}
    138138
  • trunk/src/kash/shfile.c

    r2293 r2294  
    381381        if (getcwd(buf, sizeof(buf)))
    382382        {
    383             pfdtab->cwd = strdup(buf);
     383            pfdtab->cwd = sh_strdup(NULL, buf);
    384384            if (!inherit)
    385385            {
     
    466466
    467467    shmtx_enter(&pfdtab->mtx, &tmp);
     468    TRACE2((NULL, "shfile_fork_win:\n"));
    468469
    469470    i = pfdtab->size;
     
    473474        {
    474475            HANDLE hFile = (HANDLE)pfdtab->tab[i].native;
    475             DWORD  fFlag = set || !pfdtab->tab[i].cloexec ? HANDLE_FLAG_INHERIT : 0;
     476            DWORD  fFlag = (set || !pfdtab->tab[i].cloexec)
     477                         ? HANDLE_FLAG_INHERIT : 0;
     478            if (set)
     479                TRACE2((NULL, "  #%d: native=%#x flags=%#x cloexec=%d fFlag=%#x\n",
     480                        i, pfdtab->tab[i].flags, hFile, pfdtab->tab[i].cloexec, fFlag));
     481
    476482            if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag))
    477483            {
     
    613619int shfile_pipe(shfdtab *pfdtab, int fds[2])
    614620{
    615 #ifdef SH_PURE_STUB_MODE
    616     return -1;
     621    int rc;
     622    int s;
     623#ifdef SHFILE_IN_USE
     624# if K_OS == K_OS_WINDOWS
     625    HANDLE hRead  = INVALID_HANDLE_VALUE;
     626    HANDLE hWrite = INVALID_HANDLE_VALUE;
     627    SECURITY_ATTRIBUTES SecurityAttributes;
     628
     629    SecurityAttributes.nLength = sizeof(SecurityAttributes);
     630    SecurityAttributes.lpSecurityDescriptor = NULL;
     631    SecurityAttributes.bInheritHandle = TRUE;
     632
     633    if (!CreatePipe(&hRead, &hWrite, &SecurityAttributes, 4096))
     634    {
     635        fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, -1, "shfile_pipe");
     636        if (fds[0] != -1)
     637        {
     638            fds[1] = shfile_insert(pfdtab, (intptr_t)hWrite, O_WRONLY, -1, "shfile_pipe");
     639            if (fds[1] != -1)
     640                rc = 0;
     641        }
     642
     643# else
     644    int native_fds[2];
     645    if (!pipe(native_fds))
     646    {
     647        fds[1] = -1;
     648        fds[0] = shfile_insert(pfdtab, native_fds[0], O_RDONLY, -1, "shfile_pipe");
     649        if (fds[0] != -1)
     650        {
     651            fds[1] = shfile_insert(pfdtab, native_fds[1], O_WRONLY, -1, "shfile_pipe");
     652            if (fds[1] != -1)
     653                rc = 0;
     654        }
     655# endif
     656        s = errno;
     657        if (fds[1] == -1)
     658        {
     659            if (fds[0] != -1)
     660            {
     661                shmtxtmp tmp;
     662                shmtx_enter(&pfdtab->mtx, &tmp);
     663                rc = fds[0];
     664                pfdtab->tab[rc].fd = -1;
     665                pfdtab->tab[rc].flags = 0;
     666                pfdtab->tab[rc].native = -1;
     667                shmtx_leave(&pfdtab->mtx, &tmp);
     668            }
     669
     670# if K_OS == K_OS_WINDOWS
     671            CloseHandle(hRead);
     672            CloseHandle(hWrite);
     673# else
     674            close(native_fds[0]);
     675            close(native_fds[1]);
     676# endif
     677            fds[0] = fds[1] = -1;
     678            errno = s;
     679            rc = -1;
     680        }
     681    }
     682
     683#elif defined(SH_PURE_STUB_MODE)
     684    rc = -1;
     685    errno = ENOSYS;
    617686
    618687#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
    619688# ifdef _MSC_VER
    620     return _pipe(fds, PIPE_BUF, O_BINARY);
    621 # else
    622     return pipe(fds);
    623 # endif
    624 
    625 #else
    626 #endif
     689    rc = _pipe(fds, PIPE_BUF, O_BINARY);
     690# else
     691    rc = pipe(fds);
     692# endif
     693#endif
     694
     695    TRACE2((NULL, "shfile_pipe() -> %d{%d,%d} [%d]\n", rc, fds[0], fds[1], errno));
     696    return rc;
    627697}
    628698
  • trunk/src/kash/shforkA-win.asm

    r2293 r2294  
    107107        mov     [rax - 10h], r10
    108108        mov     [rax - 18h], r11
     109int3
    109110        cmp     rax, r10
    110111        jb      .below
  • trunk/src/kash/shinstance.c

    r2293 r2294  
    181181
    182182/**
    183  * Clones an environment vector.
     183 * Clones a string vector like enviorn or argv.
    184184 *
    185185 * @returns 0 on success, -1 and errno on failure.
     186 * @param   psh     The shell to associate the allocations with.
    186187 * @param   dstp    Where to store the clone.
    187188 * @param   src     The vector to be cloned.
    188189 */
    189 static int sh_env_clone(char ***dstp, char **src)
     190static int sh_clone_string_vector(shinstance *psh, char ***dstp, char **src)
    190191{
    191192   char **dst;
     
    198199
    199200   /* alloc clone array. */
    200    *dstp = dst = sh_malloc(NULL, sizeof(*dst) * items + 1);
     201   *dstp = dst = sh_malloc(psh, sizeof(*dst) * items + 1);
    201202   if (!dst)
    202203       return -1;
     
    206207   while (items-- > 0)
    207208   {
    208        dst[items] = sh_strdup(NULL, src[items]);
     209       dst[items] = sh_strdup(psh, src[items]);
    209210       if (!dst[items])
    210211       {
    211212           /* allocation error, clean up. */
    212213           while (dst[++items])
    213                sh_free(NULL, dst[items]);
    214            sh_free(NULL, dst);
     214               sh_free(psh, dst[items]);
     215           sh_free(psh, dst);
    215216           errno = ENOMEM;
    216217           return -1;
     
    246247
    247248        /* Call the basic initializers. */
    248         if (    !sh_env_clone(&psh->shenviron, envp)
     249        if (    !sh_clone_string_vector(psh, &psh->shenviron, envp)
     250            &&  !sh_clone_string_vector(psh, &psh->argptr, argv)
    249251            &&  !shfile_init(&psh->fdtab, inherit ? &inherit->fdtab : NULL))
    250252        {
     
    916918#elif K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE)
    917919    pid = shfork_do_it(psh);
     920# ifdef DEBUG
     921    if (!pid)
     922        opentrace(psh);
     923# endif
    918924
    919925#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
     
    928934
    929935#endif
     936
     937    /* child: update the pid */
     938    if (!pid)
     939# ifdef _MSC_VER
     940        psh->pid = _getpid();
     941# else
     942        psh->pid = getpid();
     943# endif
    930944
    931945    TRACE2((psh, "sh_fork -> %d [%d]\n", pid, errno));
  • trunk/src/kash/var.c

    r2290 r2294  
    255255                vp->next = *vpp;
    256256                *vpp = vp;
    257                 vp->text = strdup(ip->text);
     257                vp->text = sh_strdup(psh, ip->text);
    258258                vp->flags = ip->flags;
    259259                vp->func = ip->func;
     
    265265                psh->vps1.next = *vpp;
    266266                *vpp = &psh->vps1;
    267                 psh->vps1.text = strdup(sh_geteuid(psh) ? "PS1=$ " : "PS1=# ");
     267                psh->vps1.text = sh_strdup(psh, sh_geteuid(psh) ? "PS1=$ " : "PS1=# ");
    268268                psh->vps1.flags = VSTRFIXED|VTEXTFIXED;
    269269        }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette