Changeset 2652 for trunk/src/kash/exec.c


Ignore:
Timestamp:
Sep 9, 2012, 7:21:48 PM (13 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.

File:
1 edited

Legend:

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