Changeset 2463 for trunk/ash/exec.c


Ignore:
Timestamp:
Nov 19, 2005, 4:58:38 PM (20 years ago)
Author:
bird
Message:

OS/2 changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ash/exec.c

    r2462 r2463  
    8080#include "jobs.h"
    8181#include "alias.h"
     82#ifdef __INNOTEK_LIBC__
     83#include <InnoTekLIBC/backend.h>
     84#endif
    8285
    8386
     
    101104
    102105
    103 STATIC void tryexec(char *, char **, char **, int);
     106STATIC void tryexec(char *, char **, char **, int, int);
    104107STATIC void execinterp(char **, char **);
    105108STATIC void printentry(struct tblentry *, int);
     
    107110STATIC struct tblentry *cmdlookup(const char *, int);
    108111STATIC void delete_cmd_entry(void);
     112#ifdef PC_EXE_EXTS
     113STATIC int stat_pc_exec_exts(char *fullname, struct stat *st, int has_ext);
     114#endif
    109115
    110116
     
    121127        char *cmdname;
    122128        int e;
    123 
     129#ifdef PC_EXE_EXTS
     130        int has_ext = strlen(argv[0]) - 4;
     131        has_ext = has_ext > 0
     132            && argv[0][has_ext] == '.'
     133            /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
     134            && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
     135                      "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
     136                      "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
     137                      "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
     138                      "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
     139                      argv[0] + has_ext + 1)
     140               != NULL;
     141#else
     142        const int has_ext = 1;
     143#endif
     144        TRACE(("shellexec: argv[0]=%s idx=%d\n", argv[0], idx));
    124145        if (strchr(argv[0], '/') != NULL) {
    125                 tryexec(argv[0], argv, envp, vforked);
     146                cmdname = stalloc(strlen(argv[0]) + 5);
     147                strcpy(cmdname, argv[0]);
     148                tryexec(cmdname, argv, envp, vforked, has_ext);
     149                TRACE(("shellexec: cmdname=%s\n", cmdname));
     150                stunalloc(cmdname);
    126151                e = errno;
    127152        } else {
     
    129154                while ((cmdname = padvance(&path, argv[0])) != NULL) {
    130155                        if (--idx < 0 && pathopt == NULL) {
    131                                 tryexec(cmdname, argv, envp, vforked);
     156                                tryexec(cmdname, argv, envp, vforked, has_ext);
    132157                                if (errno != ENOENT && errno != ENOTDIR)
    133158                                        e = errno;
     
    149174                break;
    150175        }
    151         TRACE(("shellexec failed for %s, errno %d, vforked %d, suppressint %d\n",
     176        TRACE(("shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n",
    152177                argv[0], e, vforked, suppressint ));
    153178        exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC));
     
    157182
    158183STATIC void
    159 tryexec(char *cmd, char **argv, char **envp, int vforked)
     184tryexec(char *cmd, char **argv, char **envp, int vforked, int has_ext)
    160185{
    161186        int e;
    162 #ifndef BSD
     187#ifdef EXEC_HASH_BANG_SCRIPT
    163188        char *p;
     189#endif
     190#ifdef PC_EXE_EXTS
     191        /* exploit the effect of stat_pc_exec_exts which adds the
     192         * correct extentions to the file.
     193         */
     194        struct stat st;
     195        if (!has_ext)
     196            stat_pc_exec_exts(cmd, &st, 0);
     197#endif
     198#if defined __INNOTEK_LIBC__ && defined EXEC_HASH_BANG_SCRIPT
     199        __libc_Back_gfProcessHandleHashBangScripts = 0;
    164200#endif
    165201
     
    183219                setinputfile(cmd, 0);
    184220                commandname = arg0 = savestr(argv[0]);
    185 #ifndef BSD
     221#ifdef EXEC_HASH_BANG_SCRIPT
    186222                pgetc(); pungetc();             /* fill up input buffer */
    187223                p = parsenextc;
     
    198234
    199235
    200 #ifndef BSD
     236#ifdef EXEC_HASH_BANG_SCRIPT
    201237/*
    202238 * Execute an interpreter introduced by "#!", for systems where this
     
    249285                for (;;) {
    250286                        if (equal(p, "sh") || equal(p, "ash")) {
     287                                TRACE(("hash bang self\n"));
    251288                                return;
    252289                        }
     
    270307        ap = argv;
    271308        while (*ap2++ = *ap++);
    272         shellexec(new, envp, pathval(), 0);
     309        TRACE(("hash bang '%s'\n", new[0]));
     310        shellexec(new, envp, pathval(), 0, 0);
    273311        /* NOTREACHED */
    274312}
     
    300338                return NULL;
    301339        start = *path;
     340#ifdef PC_PATH_SEP
     341        for (p = start ; *p && *p != ';' && *p != '%' ; p++);
     342#else
    302343        for (p = start ; *p && *p != ':' && *p != '%' ; p++);
     344#endif
    303345        len = p - start + strlen(name) + 2;     /* "2" is for '/' and '\0' */
     346#ifdef PC_EXE_EXTS
     347        len += 4; /* "4" is for .exe/.com/.cmd/.bat/.btm */
     348#endif
    304349        while (stackblocksize() < len)
    305350                growstackblock();
     
    314359        if (*p == '%') {
    315360                pathopt = ++p;
     361#ifdef PC_PATH_SEP
     362                while (*p && *p != ';')  p++;
     363#else
    316364                while (*p && *p != ':')  p++;
    317         }
     365#endif
     366        }
     367#ifdef PC_PATH_SEP
     368        if (*p == ';')
     369#else
    318370        if (*p == ':')
     371#endif
    319372                *path = p + 1;
    320373        else
     
    322375        return stalloc(len);
    323376}
     377
     378
     379#ifdef PC_EXE_EXTS
     380STATIC int stat_pc_exec_exts(char *fullname, struct stat *st, int has_ext)
     381{
     382    /* skip the SYSV crap */
     383    if (stat(fullname, st) >= 0)
     384        return 0;
     385    if (!has_ext && errno == ENOENT)
     386    {
     387        char *psz = strchr(fullname, '\0');
     388        memcpy(psz, ".exe", 5);
     389        if (stat(fullname, st) >= 0)
     390            return 0;
     391        if (errno != ENOENT && errno != ENOTDIR)
     392            return -1;
     393
     394        memcpy(psz, ".cmd", 5);
     395        if (stat(fullname, st) >= 0)
     396            return 0;
     397        if (errno != ENOENT && errno != ENOTDIR)
     398            return -1;
     399
     400        memcpy(psz, ".bat", 5);
     401        if (stat(fullname, st) >= 0)
     402            return 0;
     403        if (errno != ENOENT && errno != ENOTDIR)
     404            return -1;
     405
     406        memcpy(psz, ".com", 5);
     407        if (stat(fullname, st) >= 0)
     408            return 0;
     409        if (errno != ENOENT && errno != ENOTDIR)
     410            return -1;
     411
     412        memcpy(psz, ".btm", 5);
     413        if (stat(fullname, st) >= 0)
     414            return 0;
     415        *psz = '\0';
     416    }
     417    return -1;
     418}
     419#endif /* PC_EXE_EXTS */
    324420
    325421
     
    366462                                printentry(cmdp, verbose);
    367463                        }
    368                         flushall();
     464                        output_flushall();
    369465                }
    370466                argptr++;
     
    434530        int e;
    435531        int (*bltin)(int,char **);
     532
     533#ifdef PC_EXE_EXTS
     534        int has_ext = strlen(name) - 4;
     535        has_ext = has_ext > 0
     536            && name[has_ext] == '.'
     537            /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
     538            && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
     539                      "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
     540                      "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
     541                      "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
     542                      "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
     543                      name + has_ext + 1)
     544               != NULL;
     545#endif
    436546
    437547        /* If name contains a slash, don't use PATH or hash table */
     
    532642                        goto success;
    533643                }
     644#ifdef PC_EXE_EXTS
     645                while (stat_pc_exec_exts(fullname, &statb, has_ext) < 0) {
     646#else
    534647                while (stat(fullname, &statb) < 0) {
     648#endif
    535649#ifdef SYSV
    536650                        if (errno == EINTR)
     
    539653                        if (errno != ENOENT && errno != ENOTDIR)
    540654                                e = errno;
     655
    541656                        goto loop;
    542657                }
     
    707822                if (*old != *new) {
    708823                        firstchange = idx;
     824#ifdef PC_PATH_SEP
     825                        if ((*old == '\0' && *new == ';')
     826                         || (*old == ';' && *new == '\0'))
     827#else
    709828                        if ((*old == '\0' && *new == ':')
    710829                         || (*old == ':' && *new == '\0'))
     830#endif
    711831                                firstchange++;
    712832                        old = new;      /* ignore subsequent differences */
     
    716836                if (*new == '%' && bltin < 0 && prefix("builtin", new + 1))
    717837                        bltin = idx;
     838#ifdef PC_PATH_SEP
     839                if (*new == ';') {
     840#else
    718841                if (*new == ':') {
     842#endif
    719843                        idx++;
    720844                }
Note: See TracChangeset for help on using the changeset viewer.