VirtualBox

Changeset 2649 in kBuild for trunk/src


Ignore:
Timestamp:
Sep 9, 2012 3:47:26 AM (13 years ago)
Author:
bird
Message:

kash: detect shell invokations via /usr/bin/env in hash bang.

File:
1 edited

Legend:

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

    r2648 r2649  
    228228}
    229229
    230 
    231230#ifdef EXEC_HASH_BANG_SCRIPT
     231
     232/*
     233 * Checks if NAME is the (base) name of the shell executable or something
     234 * very similar.
     235 */
     236STATIC int
     237is_shell_exe_name(const char *name)
     238{
     239    return equal(name, "kmk_ash")
     240        || equal(name, "kmk_sh")
     241        || equal(name, "kash")
     242        || equal(name, "sh");
     243}
     244
    232245/*
    233246 * Execute an interpreter introduced by "#!", for systems where this
     
    277290        }
    278291
    279         /* if no args, maybe shell and no exec is needed. */
    280         if (ap == newargs + 1) {
     292        /* Special optimizations / builtins. */
     293        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. */
    281303                p = strrchr(newargs[0], '/');
    282304                if (!p)
    283305                        p = newargs[0];
    284                 if (equal(p, "kmk_ash") || equal(p, "kmk_sh") || equal(p, "kash") || equal(p, "sh")) {
     306                if (is_shell_exe_name(p)) {
    285307                        TRACE((psh, "hash bang self\n"));
    286308                        return;
     
    288310        }
    289311
     312        /* Combine the argument lists and exec. */
    290313        i = (char *)ap - (char *)newargs;               /* size in bytes */
    291314        if (i == 0)
     
    297320                *ap2++ = *ap++;
    298321        ap = argv;
    299         while (*ap2++ = *ap++);
     322        while ((*ap2++ = *ap++))
     323            /* nothing*/;
    300324        TRACE((psh, "hash bang '%s'\n", new[0]));
    301325        shellexec(psh, new, envp, pathval(psh), 0, 0);
    302326        /* NOTREACHED */
    303327}
    304 #endif
    305 
     328
     329#endif /* EXEC_HASH_BANG_SCRIPT */
    306330
    307331
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