- Timestamp:
- Sep 9, 2012 5:21:48 PM (12 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r2641 r2652 42 42 ## @todo bring over PC_SLASHES? 43 43 kash_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 45 46 kash_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_EXTS47 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 48 49 kash_DEFS.darwin = \ 49 50 HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME -
trunk/src/kash/exec.c
r2649 r2652 265 265 char **ap; 266 266 char *newargs[NEWARGS]; 267 int i;267 intptr_t i; 268 268 char **ap2; 269 269 char **new; 270 270 271 /* Split the string into arguments. */ 271 272 n = psh->parsenleft - 2; 272 273 inp = psh->parsenextc + 2; … … 290 291 } 291 292 292 /* Special optimizations / builtins. */293 /* /usr/bin/env emulation, very common with kash/kmk_ash. */ 293 294 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) { 303 311 p = strrchr(newargs[0], '/'); 304 312 if (!p) … … 310 318 } 311 319 312 /* Combine the argument lists and exec. */320 /* Combine the two argument lists and exec. */ 313 321 i = (char *)ap - (char *)newargs; /* size in bytes */ 314 322 if (i == 0) -
trunk/src/kash/generated/init.c
r2415 r2652 268 268 for (i = 0; psh->optlist[i].name; i++) 269 269 psh->optlist[i].val = 0; 270 # if DEBUG == 2 271 debug(psh) = 1; 272 # endif 270 273 optschanged(psh); 271 272 274 } 273 275 -
trunk/src/kash/options.c
r2290 r2652 261 261 for (i = 0; psh->optlist[i].name; i++) 262 262 psh->optlist[i].val = 0; 263 # if DEBUG == 2 264 debug(psh) = 1; 265 # endif 263 266 optschanged(psh); 264 265 267 } 266 268 #endif -
trunk/src/kash/shfile.c
r2650 r2652 164 164 static void shfile_native_close(intptr_t native, unsigned flags) 165 165 { 166 # if K_OS == K_OS_WINDOWS166 # if K_OS == K_OS_WINDOWS 167 167 BOOL fRc = CloseHandle((HANDLE)native); 168 168 assert(fRc); (void)fRc; 169 # else169 # else 170 170 int s = errno; 171 171 close(native); 172 172 errno = s; 173 # endif173 # endif 174 174 (void)flags; 175 175 } … … 289 289 } 290 290 291 # if K_OS != K_OS_WINDOWS291 # if K_OS != K_OS_WINDOWS 292 292 /** 293 293 * Makes a copy of the native file, closes the original, and inserts the copy … … 318 318 return fd; 319 319 } 320 # endif /* !K_OS_WINDOWS */320 # endif /* !K_OS_WINDOWS */ 321 321 322 322 /** … … 385 385 } 386 386 if ( *path == '/' 387 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2387 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2 388 388 || *path == '\\' 389 389 || ( *path … … 391 391 && ( (*path >= 'A' && *path <= 'Z') 392 392 || (*path >= 'a' && *path <= 'z'))) 393 # endif393 # endif 394 394 ) 395 395 { … … 419 419 } 420 420 421 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2421 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2 422 422 if (!strcmp(buf, "/dev/null")) 423 423 strcpy(buf, "NUL"); 424 # endif424 # endif 425 425 return 0; 426 426 } … … 528 528 529 529 /** 530 * Converts DOS slashes to UNIX slashes if necessary. 531 * 532 * @param pszPath The path to fix. 533 */ 534 static 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 /** 530 545 * Initializes the global variables in this file. 531 546 */ … … 574 589 if (getcwd(buf, sizeof(buf))) 575 590 { 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); 584 592 585 593 pfdtab->cwd = sh_strdup(NULL, buf); … … 1390 1398 rc = -1; 1391 1399 1392 # else1400 # ifdef DEBUG 1393 1401 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; 1395 1409 struct stat s; 1396 1410 int x; … … 1398 1412 TRACE2((NULL, "shfile_write(%d) - %lu bytes (%d) - pos %lu - before; %o\n", 1399 1413 fd, (long)s.st_size, x, (long)lseek(fd, 0, SEEK_CUR), s.st_mode )); 1400 errno = 0;1414 errno = iSavedErrno; 1401 1415 } 1402 1416 1403 1417 rc = write(fd, buf, len); 1404 #endif1405 1406 #ifdef DEBUG1407 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 }1415 1418 #endif 1416 1419 return rc; … … 1601 1604 char *abspath_copy = sh_strdup(psh, abspath); 1602 1605 char *free_me = abspath_copy; 1603 rc = chdir( path);1606 rc = chdir(abspath); 1604 1607 if (!rc) 1605 1608 { … … 1607 1610 shmtx_enter(&pfdtab->mtx, &tmp); 1608 1611 1612 shfile_fix_slashes(abspath_copy); 1609 1613 free_me = pfdtab->cwd; 1610 1614 pfdtab->cwd = abspath_copy; -
trunk/src/kash/shinstance.c
r2648 r2652 598 598 #ifdef _MSC_VER 599 599 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 } 600 611 #else 601 612 if (sigaction(signo, &g_sig_state[signo].sa, NULL)) 602 #endif603 613 assert(0); 614 #endif 604 615 605 616 shmtx_leave(&g_sh_mtx, &tmp); … … 1181 1192 errno = EINVAL; 1182 1193 } 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 } 1183 1209 1184 1210 shfile_exec_win(&psh->fdtab, 0 /* done */, NULL, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.