VirtualBox

Changeset 2652 in kBuild for trunk


Ignore:
Timestamp:
Sep 9, 2012 5:21:48 PM (12 years ago)
Author:
bird
Message:

kash: Fixes for hash-bang-scripts on windows. Related debug tracing fix. Another CWD slash fix. Fixed a couple of assertions.

Location:
trunk/src/kash
Files:
6 edited

Legend:

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

    r2641 r2652  
    4242## @todo bring over PC_SLASHES?
    4343kash_DEFS.win = \
    44         BSD PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS YY_NO_UNISTD_H SH_DEAL_WITH_CRLF
     44        BSD YY_NO_UNISTD_H \
     45        SH_DEAL_WITH_CRLF PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS EXEC_HASH_BANG_SCRIPT
    4546kash_DEFS.os2 = \
    46         HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME \
    47         EXEC_HASH_BANG_SCRIPT PC_OS2_LIBPATHS PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS
     47        HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME PC_OS2_LIBPATHS \
     48        SH_DEAL_WITH_CRLF PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS EXEC_HASH_BANG_SCRIPT
    4849kash_DEFS.darwin = \
    4950        HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
  • trunk/src/kash/exec.c

    r2649 r2652  
    265265        char **ap;
    266266        char *newargs[NEWARGS];
    267         int i;
     267        intptr_t i;
    268268        char **ap2;
    269269        char **new;
    270270
     271        /* Split the string into arguments. */
    271272        n = psh->parsenleft - 2;
    272273        inp = psh->parsenextc + 2;
     
    290291        }
    291292
    292         /* Special optimizations / builtins. */
     293        /* /usr/bin/env emulation, very common with kash/kmk_ash. */
    293294        i = ap - newargs;
    294         if (i > 1 && equal(newargs[0], "/usr/bin/env"))  {
    295                 /* /usr/bin/env <self> -> easy. */
    296                 if (i == 2 && is_shell_exe_name(newargs[1])) {
    297                     TRACE((psh, "hash bang /usr/bin/env self\n"));
    298                     return;
    299                 }
    300                 /** @todo implement simple /usr/bin/env that locates an exec in the PATH. */
    301 
    302         } else if (i == 1) { /* if no args, maybe shell and no exec is needed. */
     295        if (i > 1 && equal(newargs[0], "/usr/bin/env")) {
     296                if (   !strchr(newargs[1], '=')
     297                    && newargs[1][0] != '-') {
     298                    /* shellexec below searches the PATH for us, so just
     299                       drop /usr/bin/env. */
     300                    TRACE((psh, "hash bang /usr/bin/env utility, dropping /usr/bin/env\n"));
     301                    ap--;
     302                    i--;
     303                    for (n = 0; n < i; n++)
     304                            newargs[n] = newargs[n + 1];
     305                } /* else: complicated invocation */
     306        }
     307
     308        /* If the interpreter is the shell or a similar shell, there is
     309           no need to exec. */
     310        if (i == 1) {
    303311                p = strrchr(newargs[0], '/');
    304312                if (!p)
     
    310318        }
    311319
    312         /* Combine the argument lists and exec. */
     320        /* Combine the two argument lists and exec. */
    313321        i = (char *)ap - (char *)newargs;               /* size in bytes */
    314322        if (i == 0)
  • trunk/src/kash/generated/init.c

    r2415 r2652  
    268268              for (i = 0; psh->optlist[i].name; i++)
    269269                      psh->optlist[i].val = 0;
     270# if DEBUG == 2
     271              debug(psh) = 1;
     272# endif
    270273              optschanged(psh);
    271 
    272274      }
    273275
  • trunk/src/kash/options.c

    r2290 r2652  
    261261        for (i = 0; psh->optlist[i].name; i++)
    262262                psh->optlist[i].val = 0;
     263# if DEBUG == 2
     264        debug(psh) = 1;
     265# endif
    263266        optschanged(psh);
    264 
    265267}
    266268#endif
  • trunk/src/kash/shfile.c

    r2650 r2652  
    164164static void shfile_native_close(intptr_t native, unsigned flags)
    165165{
    166 #if K_OS == K_OS_WINDOWS
     166# if K_OS == K_OS_WINDOWS
    167167    BOOL fRc = CloseHandle((HANDLE)native);
    168168    assert(fRc); (void)fRc;
    169 #else
     169# else
    170170    int s = errno;
    171171    close(native);
    172172    errno = s;
    173 #endif
     173# endif
    174174    (void)flags;
    175175}
     
    289289}
    290290
    291 #if K_OS != K_OS_WINDOWS
     291# if K_OS != K_OS_WINDOWS
    292292/**
    293293 * Makes a copy of the native file, closes the original, and inserts the copy
     
    318318    return fd;
    319319}
    320 #endif /* !K_OS_WINDOWS */
     320# endif /* !K_OS_WINDOWS */
    321321
    322322/**
     
    385385    }
    386386    if (    *path == '/'
    387 #if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     387# if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    388388        ||  *path == '\\'
    389389        ||  (   *path
     
    391391             && (   (*path >= 'A' && *path <= 'Z')
    392392                 || (*path >= 'a' && *path <= 'z')))
    393 #endif
     393# endif
    394394        )
    395395    {
     
    419419    }
    420420
    421 #if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     421# if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    422422    if (!strcmp(buf, "/dev/null"))
    423423        strcpy(buf, "NUL");
    424 #endif
     424# endif
    425425    return 0;
    426426}
     
    528528
    529529/**
     530 * Converts DOS slashes to UNIX slashes if necessary.
     531 *
     532 * @param   pszPath             The path to fix.
     533 */
     534static void shfile_fix_slashes(char *pszPath)
     535{
     536#if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     537    while ((pszPath = strchr(pszPath, '\\')))
     538        *pszPath++ = '/';
     539#else
     540    (void)pszPath;
     541#endif
     542}
     543
     544/**
    530545 * Initializes the global variables in this file.
    531546 */
     
    574589        if (getcwd(buf, sizeof(buf)))
    575590        {
    576 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
    577             char *pszSlash = strchr(buf, '\\');
    578             while (pszSlash)
    579             {
    580                 *pszSlash = '/';
    581                 pszSlash = strchr(pszSlash + 1, '\\');
    582             }
    583 # endif
     591            shfile_fix_slashes(buf);
    584592
    585593            pfdtab->cwd = sh_strdup(NULL, buf);
     
    13901398        rc = -1;
    13911399
    1392 #else
     1400# ifdef DEBUG
    13931401    if (fd != shthread_get_shell()->tracefd)
    1394     {
     1402        TRACE2((NULL, "shfile_write(%d,,%d) -> %d [%d]\n", fd, len, rc, errno));
     1403# endif
     1404
     1405#else
     1406    if (fd != shthread_get_shell()->tracefd)
     1407    {
     1408        int iSavedErrno = errno;
    13951409        struct stat s;
    13961410        int x;
     
    13981412        TRACE2((NULL, "shfile_write(%d) - %lu bytes (%d) - pos %lu - before; %o\n",
    13991413                fd, (long)s.st_size, x, (long)lseek(fd, 0, SEEK_CUR), s.st_mode ));
    1400         errno = 0;
     1414        errno = iSavedErrno;
    14011415    }
    14021416
    14031417    rc = write(fd, buf, len);
    1404 #endif
    1405 
    1406 #ifdef DEBUG
    1407     if (fd != shthread_get_shell()->tracefd)
    1408     {
    1409         struct stat s;
    1410         int x;
    1411         TRACE2((NULL, "shfile_write(%d,,%d) -> %d [%d]\n", fd, len, rc, errno));
    1412         x=fstat(fd, &s);
    1413         TRACE2((NULL, "shfile_write(%d) - %lu bytes (%d) - pos %lu - after\n", fd, (long)s.st_size, x, (long)lseek(fd, 0, SEEK_CUR) ));
    1414     }
    14151418#endif
    14161419    return rc;
     
    16011604        char *abspath_copy = sh_strdup(psh, abspath);
    16021605        char *free_me = abspath_copy;
    1603         rc = chdir(path);
     1606        rc = chdir(abspath);
    16041607        if (!rc)
    16051608        {
     
    16071610            shmtx_enter(&pfdtab->mtx, &tmp);
    16081611
     1612            shfile_fix_slashes(abspath_copy);
    16091613            free_me = pfdtab->cwd;
    16101614            pfdtab->cwd = abspath_copy;
  • trunk/src/kash/shinstance.c

    r2648 r2652  
    598598#ifdef _MSC_VER
    599599        if (signal(signo, g_sig_state[signo].sa.sa_handler) == SIG_ERR)
     600        {
     601            TRACE2((psh, "sh_sigaction: SIG_ERR, errno=%d signo=%d\n", errno, signo));
     602            if (   signo != SIGHUP   /* whatever */
     603                && signo != SIGQUIT
     604                && signo != SIGPIPE
     605                && signo != SIGTTIN
     606                && signo != SIGTSTP
     607                && signo != SIGTTOU
     608                && signo != SIGCONT)
     609                assert(0);
     610        }
    600611#else
    601612        if (sigaction(signo, &g_sig_state[signo].sa, NULL))
    602 #endif
    603613            assert(0);
     614#endif
    604615
    605616        shmtx_leave(&g_sh_mtx, &tmp);
     
    11811192            errno = EINVAL;
    11821193        }
     1194        else
     1195        {
     1196            DWORD dwErr = GetLastError();
     1197            switch (dwErr)
     1198            {
     1199                case ERROR_FILE_NOT_FOUND:          errno = ENOENT; break;
     1200                case ERROR_PATH_NOT_FOUND:          errno = ENOENT; break;
     1201                case ERROR_BAD_EXE_FORMAT:          errno = ENOEXEC; break;
     1202                case ERROR_INVALID_EXE_SIGNATURE:   errno = ENOEXEC; break;
     1203                default:
     1204                    errno = EINVAL;
     1205                    break;
     1206            }
     1207            TRACE2((psh, "sh_execve: dwErr=%d -> errno=%d\n", dwErr, errno));
     1208        }
    11831209
    11841210        shfile_exec_win(&psh->fdtab, 0 /* done */, NULL, NULL);
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