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

kash: more fixes + pipe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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));
Note: See TracChangeset for help on using the changeset viewer.