Changeset 2463 for trunk/ash/exec.c
- Timestamp:
- Nov 19, 2005, 4:58:38 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ash/exec.c
r2462 r2463 80 80 #include "jobs.h" 81 81 #include "alias.h" 82 #ifdef __INNOTEK_LIBC__ 83 #include <InnoTekLIBC/backend.h> 84 #endif 82 85 83 86 … … 101 104 102 105 103 STATIC void tryexec(char *, char **, char **, int );106 STATIC void tryexec(char *, char **, char **, int, int); 104 107 STATIC void execinterp(char **, char **); 105 108 STATIC void printentry(struct tblentry *, int); … … 107 110 STATIC struct tblentry *cmdlookup(const char *, int); 108 111 STATIC void delete_cmd_entry(void); 112 #ifdef PC_EXE_EXTS 113 STATIC int stat_pc_exec_exts(char *fullname, struct stat *st, int has_ext); 114 #endif 109 115 110 116 … … 121 127 char *cmdname; 122 128 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)); 124 145 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); 126 151 e = errno; 127 152 } else { … … 129 154 while ((cmdname = padvance(&path, argv[0])) != NULL) { 130 155 if (--idx < 0 && pathopt == NULL) { 131 tryexec(cmdname, argv, envp, vforked );156 tryexec(cmdname, argv, envp, vforked, has_ext); 132 157 if (errno != ENOENT && errno != ENOTDIR) 133 158 e = errno; … … 149 174 break; 150 175 } 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", 152 177 argv[0], e, vforked, suppressint )); 153 178 exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC)); … … 157 182 158 183 STATIC void 159 tryexec(char *cmd, char **argv, char **envp, int vforked )184 tryexec(char *cmd, char **argv, char **envp, int vforked, int has_ext) 160 185 { 161 186 int e; 162 #if ndef BSD187 #ifdef EXEC_HASH_BANG_SCRIPT 163 188 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; 164 200 #endif 165 201 … … 183 219 setinputfile(cmd, 0); 184 220 commandname = arg0 = savestr(argv[0]); 185 #if ndef BSD221 #ifdef EXEC_HASH_BANG_SCRIPT 186 222 pgetc(); pungetc(); /* fill up input buffer */ 187 223 p = parsenextc; … … 198 234 199 235 200 #if ndef BSD236 #ifdef EXEC_HASH_BANG_SCRIPT 201 237 /* 202 238 * Execute an interpreter introduced by "#!", for systems where this … … 249 285 for (;;) { 250 286 if (equal(p, "sh") || equal(p, "ash")) { 287 TRACE(("hash bang self\n")); 251 288 return; 252 289 } … … 270 307 ap = argv; 271 308 while (*ap2++ = *ap++); 272 shellexec(new, envp, pathval(), 0); 309 TRACE(("hash bang '%s'\n", new[0])); 310 shellexec(new, envp, pathval(), 0, 0); 273 311 /* NOTREACHED */ 274 312 } … … 300 338 return NULL; 301 339 start = *path; 340 #ifdef PC_PATH_SEP 341 for (p = start ; *p && *p != ';' && *p != '%' ; p++); 342 #else 302 343 for (p = start ; *p && *p != ':' && *p != '%' ; p++); 344 #endif 303 345 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 304 349 while (stackblocksize() < len) 305 350 growstackblock(); … … 314 359 if (*p == '%') { 315 360 pathopt = ++p; 361 #ifdef PC_PATH_SEP 362 while (*p && *p != ';') p++; 363 #else 316 364 while (*p && *p != ':') p++; 317 } 365 #endif 366 } 367 #ifdef PC_PATH_SEP 368 if (*p == ';') 369 #else 318 370 if (*p == ':') 371 #endif 319 372 *path = p + 1; 320 373 else … … 322 375 return stalloc(len); 323 376 } 377 378 379 #ifdef PC_EXE_EXTS 380 STATIC 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 */ 324 420 325 421 … … 366 462 printentry(cmdp, verbose); 367 463 } 368 flushall();464 output_flushall(); 369 465 } 370 466 argptr++; … … 434 530 int e; 435 531 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 436 546 437 547 /* If name contains a slash, don't use PATH or hash table */ … … 532 642 goto success; 533 643 } 644 #ifdef PC_EXE_EXTS 645 while (stat_pc_exec_exts(fullname, &statb, has_ext) < 0) { 646 #else 534 647 while (stat(fullname, &statb) < 0) { 648 #endif 535 649 #ifdef SYSV 536 650 if (errno == EINTR) … … 539 653 if (errno != ENOENT && errno != ENOTDIR) 540 654 e = errno; 655 541 656 goto loop; 542 657 } … … 707 822 if (*old != *new) { 708 823 firstchange = idx; 824 #ifdef PC_PATH_SEP 825 if ((*old == '\0' && *new == ';') 826 || (*old == ';' && *new == '\0')) 827 #else 709 828 if ((*old == '\0' && *new == ':') 710 829 || (*old == ':' && *new == '\0')) 830 #endif 711 831 firstchange++; 712 832 old = new; /* ignore subsequent differences */ … … 716 836 if (*new == '%' && bltin < 0 && prefix("builtin", new + 1)) 717 837 bltin = idx; 838 #ifdef PC_PATH_SEP 839 if (*new == ';') { 840 #else 718 841 if (*new == ':') { 842 #endif 719 843 idx++; 720 844 }
Note:
See TracChangeset
for help on using the changeset viewer.