Changeset 2289 for trunk/src/kash/show.c
- Timestamp:
- Feb 26, 2009, 5:58:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/show.c
r2287 r2289 397 397 opentrace(shinstance *psh) 398 398 { 399 char s[100]; 400 #if defined(O_APPEND) && !defined(_MSC_VER) 401 int flags; 402 #endif 399 static const char s[] = "./trace"; 403 400 int fd; 404 401 … … 409 406 return; 410 407 } 411 #ifdef not_this_way 412 { 413 char *p; 414 if ((p = getenv("HOME")) == NULL) { 415 if (sh_geteuid(psh) == 0) 416 p = "/"; 417 else 418 p = "/tmp"; 419 } 420 scopy(p, s); 421 strcat(s, "/trace"); 422 } 423 #else 424 scopy("./trace", s); 425 #endif /* not_this_way */ 408 426 409 if (tracefile) { 427 410 if (!freopen(s, "a", tracefile)) { … … 431 414 } 432 415 } else { 433 fd = shfile_open(&psh->fdtab,s, O_APPEND | O_RDWR | O_CREAT, 0600);416 fd = open(s, O_APPEND | O_RDWR | O_CREAT, 0600); 434 417 if (fd != -1) { 435 int fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 199); 436 if (fd2 == -1) 437 fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 99); 438 if (fd2 == -1) 439 fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 49); 440 if (fd2 == -1) 441 fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 18); 442 if (fd2 == -1) 443 fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 10); 418 # if K_OS == K_OS_WINDOWS 419 int fds[50]; 420 int i = 0; 421 while (i < 50) { 422 fds[i] = _dup(fd); 423 if (fds[i] == -1 || fds[i] > 199) 424 break; 425 i++; 426 } 427 if (i > 0) { 428 close(fd); 429 fd = fds[--i]; 430 } 431 while (i-- > 0) 432 close(fds[i]); 433 # else 434 int fdTarget = 199; 435 while (fdTarget > 10) 436 { 437 int fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, fdTarget); 438 if (fd2 != -1) 439 break; 440 fdTarget = (fdTarget + 1 / 2) - 1; 441 } 444 442 if (fd2 != -1) { 445 443 close(fd); 446 444 fd = fd2; 447 445 } 446 # endif 448 447 } 449 448 if (fd == -1 || (tracefile = fdopen(fd, "a")) == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.