儲存庫 kBuild 的更動 2296
- 時間撮記:
- 2009-3-1 上午01:54:30 (16 年 以前)
- 位置:
- trunk/src/kash
- 檔案:
-
- 修改 6 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/kash/shfile.c
r2294 r2296 43 43 #endif 44 44 45 #if def DEBUG45 #if defined(DEBUG) && defined(TRACE_VIA_STDIO) 46 46 extern FILE *tracefile; 47 47 #endif … … 150 150 while (new_size < fdMin) 151 151 new_size += SHFILE_GROW; 152 new_tab = sh_realloc( NULL, pfdtab->tab, new_size * sizeof(shfile));152 new_tab = sh_realloc(shthread_get_shell(), pfdtab->tab, new_size * sizeof(shfile)); 153 153 if (new_tab) 154 154 { 155 fd = i = pfdtab->size;156 if (fd < fdMin)157 fd = fdMin;158 155 for (i = pfdtab->size; i < new_size; i++) 159 156 { … … 162 159 new_tab[i].native = -1; 163 160 } 161 162 fd = pfdtab->size; 163 if (fd < fdMin) 164 fd = fdMin; 164 165 165 166 pfdtab->tab = new_tab; … … 610 611 #endif 611 612 612 #if def DEBUG613 #if defined(DEBUG) && defined(TRACE_VIA_STDIO) 613 614 if (tracefile) 615 #endif 614 616 TRACE2((NULL, "shfile_open(%p:{%s}, %#x, 0%o) -> %d [%d]\n", name, name, flags, mode, fd, errno)); 615 #endif616 617 return fd; 617 618 } … … 999 1000 1000 1001 #ifdef DEBUG 1002 # ifdef TRACE_VIA_STDIO 1001 1003 if (tracefile) 1004 # endif 1002 1005 switch (cmd) 1003 1006 { -
trunk/src/kash/shforkA-win.asm
r2294 r2296 107 107 mov [rax - 10h], r10 108 108 mov [rax - 18h], r11 109 int3110 109 cmp rax, r10 111 110 jb .below -
trunk/src/kash/shinstance.c
r2294 r2296 302 302 #endif 303 303 psh->ttyfd = -1; 304 305 /* show.c */ 306 psh->tracefd = -1; 304 307 305 308 /* link it. */ -
trunk/src/kash/shinstance.h
r2293 r2296 297 297 struct redirtab *redirlist; 298 298 int fd0_redirected/* = 0*/; 299 300 /* show.c */ 301 char tracebuf[1024]; 302 size_t tracepos; 303 int tracefd; 299 304 300 305 /* trap.h */ -
trunk/src/kash/show.c
r2293 r2296 44 44 #include <stdarg.h> 45 45 #include <stdlib.h> 46 #include <assert.h> 46 47 47 48 #include "shell.h" … … 266 267 */ 267 268 268 269 #ifdef DEBUG 270 #ifdef TRACE_VIA_STDIO 269 271 FILE *tracefile; 270 271 272 #ifdef DEBUG 272 #endif 273 274 /** @def TRY_GET_PSH_OR_RETURN 275 * Make sure @a psh is valid, trying to fetch it from TLS 276 * if it's NULL and returning (void) if that fails. */ 277 # define TRY_GET_PSH_OR_RETURN(psh) \ 278 if (!(psh)) { \ 279 psh = shthread_get_shell(); \ 280 if (!psh) \ 281 return; \ 282 } else do { } while (0) 283 284 /** @def RETURN_IF_NOT_TRACING 285 * Return if we're not tracing. */ 286 # ifdef TRACE_VIA_STDIO 287 # define RETURN_IF_NOT_TRACING(psh) \ 288 if (debug(psh) != 1 || !tracefile) 289 return; \ 290 else do {} while (0) 291 # else 292 # define RETURN_IF_NOT_TRACING(psh) \ 293 if (debug(psh) != 1 || psh->tracefd == -1) \ 294 return; \ 295 else do {} while (0) 296 # endif 297 298 /** @def TRACE_PUTC 299 * putc/trace_char wrapper. The @a psh / @a tracefile 300 * is taken from the context and not as a paramenter. */ 301 # ifdef TRACE_VIA_STDIO 302 # define TRACE_PUTC(c) fputc(c, tracefile) 303 # else 304 # define TRACE_PUTC(c) trace_char(psh, c) 305 # endif 306 307 308 # ifndef TRACE_VIA_STDIO 309 /* Flushes the tracebuf. */ 310 static void 311 trace_flush(shinstance *psh) 312 { 313 size_t pos = psh->tracepos; 314 315 if (pos > sizeof(psh->tracebuf)) { 316 char *end; 317 assert(0); 318 end = memchr(psh->tracebuf, '\0', sizeof(psh->tracebuf)); 319 pos = end ? end - &psh->tracebuf[0] : 0; 320 } 321 322 if (pos) { 323 char prefix[40]; 324 size_t len; 325 326 len = sprintf(prefix, "[%d] ", sh_getpid(psh)); 327 shfile_write(&psh->fdtab, psh->tracefd, prefix, len); 328 shfile_write(&psh->fdtab, psh->tracefd, psh->tracebuf, pos); 329 330 psh->tracepos = 0; 331 psh->tracebuf[0] = '\0'; 332 } 333 } 334 335 /* Adds a char to the trace buffer. */ 336 static void 337 trace_char(shinstance *psh, int c) 338 { 339 size_t pos = psh->tracepos; 340 if (pos >= sizeof(psh->tracebuf) - 1) { 341 trace_flush(psh); 342 pos = psh->tracepos; 343 } 344 psh->tracebuf[pos] = c; 345 psh->tracepos = pos + 1; 346 if (c == '\n') 347 trace_flush(psh); 348 else 349 psh->tracebuf[pos + 1] = '\0'; 350 } 351 352 /* Add a string to the trace buffer. */ 353 static void 354 trace_string(shinstance *psh, const char *str) 355 { 356 /* push it out line by line. */ 357 while (*str) { 358 /* find line/string length. */ 359 size_t pos; 360 size_t len; 361 const char *end = str; 362 int flush_it = 0; 363 while (*end) { 364 if (*end++ == '\n') { 365 flush_it = 1; 366 break; 367 } 368 } 369 len = end - str; 370 371 /* copy to the buffer */ 372 pos = psh->tracepos; 373 if (pos + len <= sizeof(psh->tracebuf)) { 374 memcpy(&psh->tracebuf[pos], str, len); 375 psh->tracepos = pos + len; 376 if (flush_it) 377 trace_flush(psh); 378 } else { 379 /* it's too big for some reason... */ 380 trace_flush(psh); 381 shfile_write(&psh->fdtab, psh->tracefd, str, len); 382 if (!flush_it) 383 shfile_write(&psh->fdtab, psh->tracefd, "[too long]\n", sizeof( "[too long]\n") - 1); 384 } 385 386 /* advance */ 387 str = end; 388 } 389 } 390 # endif 391 273 392 void 274 393 trputc(shinstance *psh, int c) 275 394 { 276 if (psh && debug(psh) != 1) 277 return; 278 putc(c, tracefile); 395 TRY_GET_PSH_OR_RETURN(psh); 396 RETURN_IF_NOT_TRACING(psh); 397 398 # ifdef TRACE_VIA_STDIO 399 putc(c, tracefile); 400 # else 401 trace_char(psh, c); 402 # endif 279 403 } 280 404 #endif … … 286 410 int savederrno = errno; 287 411 va_list va; 288 289 if (!tracefile || (psh && debug(psh) != 1)) 290 return; 412 # ifndef TRACE_VIA_STDIO 413 char buf[2048]; 414 # endif 415 416 TRY_GET_PSH_OR_RETURN(psh); 417 RETURN_IF_NOT_TRACING(psh); 418 419 # ifdef TRACE_VIA_STDIO 291 420 fprintf(tracefile, "[%d] ", sh_getpid(psh)); 292 421 va_start(va, fmt); 293 422 (void) vfprintf(tracefile, fmt, va); 294 423 va_end(va); 424 # else 425 va_start(va, fmt); 426 # ifdef _MSC_VER 427 _vsnprintf(buf, sizeof(buf), fmt, va); 428 # else 429 vsnprintf(buf, sizeof(buf), fmt, va); 430 # endif 431 va_end(va); 432 trace_string(psh, buf); 433 # endif 295 434 296 435 errno = savederrno; … … 303 442 #ifdef DEBUG 304 443 int savederrno = errno; 305 306 if (!tracefile || (psh && debug(psh) != 1)) 307 return; 444 # ifndef TRACE_VIA_STDIO 445 char buf[2048]; 446 # endif 447 448 TRY_GET_PSH_OR_RETURN(psh); 449 RETURN_IF_NOT_TRACING(psh); 450 451 # ifdef TRACE_VIA_STDIO 308 452 fprintf(tracefile, "[%d] ", sh_getpid(psh)); 309 453 (void) vfprintf(tracefile, fmt, va); 454 # else 455 # ifdef _MSC_VER 456 _vsnprintf(buf, sizeof(buf), fmt, va); 457 # else 458 vsnprintf(buf, sizeof(buf), fmt, va); 459 # endif 460 trace_string(psh, buf); 461 # endif 310 462 311 463 errno = savederrno; … … 320 472 int savederrno = errno; 321 473 322 if (!tracefile || (psh && debug(psh) != 1)) 323 return; 474 TRY_GET_PSH_OR_RETURN(psh); 475 RETURN_IF_NOT_TRACING(psh); 476 477 # ifdef TRACE_VIA_STDIO 324 478 fputs(s, tracefile); 479 # else 480 trace_string(psh, s); 481 # endif 325 482 326 483 errno = savederrno; … … 335 492 char c; 336 493 337 if (!tracefile || (psh && debug(psh) != 1)) 338 return; 339 putc('"', tracefile); 494 TRY_GET_PSH_OR_RETURN(psh); 495 RETURN_IF_NOT_TRACING(psh); 496 497 TRACE_PUTC('"'); 340 498 for (p = s ; *p ; p++) { 341 499 switch (*p) { … … 350 508 case CTLBACKQ: c = 'q'; goto backslash; 351 509 case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash; 352 backslash: putc('\\', tracefile);353 putc(c, tracefile);510 backslash: TRACE_PUTC('\\'); 511 TRACE_PUTC(c); 354 512 break; 355 513 default: 356 514 if (*p >= ' ' && *p <= '~') 357 putc(*p, tracefile);515 TRACE_PUTC(*p); 358 516 else { 359 putc('\\', tracefile);360 putc(*p >> 6 & 03, tracefile);361 putc(*p >> 3 & 07, tracefile);362 putc(*p & 07, tracefile);517 TRACE_PUTC('\\'); 518 TRACE_PUTC(*p >> 6 & 03); 519 TRACE_PUTC(*p >> 3 & 07); 520 TRACE_PUTC(*p & 07); 363 521 } 364 522 break; 365 523 } 366 524 } 367 putc('"', tracefile);525 TRACE_PUTC('"'); 368 526 369 527 errno = savederrno; … … 378 536 int savederrno = errno; 379 537 380 if (!tracefile || (psh && debug(psh) != 1)) 381 return; 538 TRY_GET_PSH_OR_RETURN(psh); 539 RETURN_IF_NOT_TRACING(psh); 540 382 541 while (*ap) { 383 542 trstring(psh, *ap++); 384 543 if (*ap) 385 putc(' ', tracefile);544 TRACE_PUTC(' '); 386 545 else 387 putc('\n', tracefile);546 TRACE_PUTC('\n'); 388 547 } 389 548 … … 398 557 { 399 558 static const char s[] = "./trace"; 559 # ifdef TRACE_VIA_STDIO 400 560 int fd; 401 402 if (psh && debug(psh) != 1) { 561 # endif 562 563 TRY_GET_PSH_OR_RETURN(psh); 564 if (debug(psh) != 1) { 565 # ifdef TRACE_VIA_STDIO 403 566 if (tracefile) 404 567 fflush(tracefile); 405 568 /* leave open because libedit might be using it */ 569 # else 570 if (psh->tracefd != -1) { 571 trace_flush(psh); 572 shfile_close(&psh->fdtab, psh->tracefd); 573 psh->tracefd = -1; 574 } 575 # endif 406 576 return; 407 577 } 408 578 579 # ifdef TRACE_VIA_STDIO 409 580 if (tracefile) { 410 581 if (!freopen(s, "a", tracefile)) { … … 416 587 fd = open(s, O_APPEND | O_RDWR | O_CREAT, 0600); 417 588 if (fd != -1) { 418 # if K_OS == K_OS_WINDOWS589 # if K_OS == K_OS_WINDOWS 419 590 int fds[50]; 420 591 int i = 0; … … 431 602 while (i-- > 0) 432 603 close(fds[i]); 433 # else604 # else 434 605 int fdTarget = 199; 435 606 while (fdTarget > 10) 436 607 { 437 608 int fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, fdTarget); 438 if (fd2 != -1) 439 break; 609 if (fd2 != -1) { 610 close(fd); 611 fd = fd2; 612 break; 613 } 440 614 fdTarget = (fdTarget + 1 / 2) - 1; 441 615 } 442 if (fd2 != -1) { 443 close(fd); 444 fd = fd2; 445 } 446 # endif 616 # endif 447 617 } 448 618 if (fd == -1 || (tracefile = fdopen(fd, "a")) == NULL) { … … 454 624 setvbuf(tracefile, (char *)NULL, _IOLBF, 1024); 455 625 fputs("\nTracing started.\n", tracefile); 626 627 # else /* !TRACE_VIA_STDIO */ 628 if (psh->tracefd != -1) { 629 return; 630 } 631 psh->tracefd = shfile_open(&psh->fdtab, s, O_APPEND | O_RDWR | O_CREAT, 0600); 632 if (psh->tracefd != -1) { 633 /* relocate it */ 634 int fdTarget = 199; 635 while (fdTarget > 10) 636 { 637 int fd2 = shfile_fcntl(&psh->fdtab, psh->tracefd, F_DUPFD, fdTarget); 638 if (fd2 != -1) { 639 shfile_close(&psh->fdtab, psh->tracefd); 640 psh->tracefd = fd2; 641 break; 642 } 643 fdTarget = (fdTarget + 1 / 2) - 1; 644 } 645 } 646 if (psh->tracefd == -1) { 647 fprintf(stderr, "Can't open %s\n", s); 648 debug(psh) = 0; 649 return; 650 } 651 trace_string(psh, "Tracing started.\n"); 652 653 # endif /* !TRACE_VIA_STDIO */ 456 654 } 457 655 #endif /* DEBUG */ -
trunk/src/kash/shthread.c
r2243 r2296 27 27 #include "shthread.h" 28 28 #include "shinstance.h" 29 #include <assert.h> 29 30 30 #if defined(_MSC_VER) || defined(__EMX__) 31 # include <process.h> 31 #if K_OS == K_OS_WINDOWS 32 # include <Windows.h> 33 #elif K_OS == K_OS_OS2 34 # include <InnoTekLIBC/FastInfoBlocks.h> 35 # include <InnoTekLIBC/thread.h> 32 36 #else 33 37 # include <pthread.h> … … 35 39 36 40 41 /******************************************************************************* 42 * Global Variables * 43 *******************************************************************************/ 44 #if K_OS == K_OS_WINDOWS 45 static DWORD sh_tls = TLS_OUT_OF_INDEXES; 46 #elif K_OS == K_OS_OS2 47 static int sh_tls = -1; 48 #else 49 static int sh_tls_inited = 0; 50 static int sh_tls; 51 #endif 52 53 54 /** 55 * Stores the shell instance pointer in a TLS entry. 56 * 57 * This will allocate the TLS entry on the first call. We assume 58 * there will no be races at that time. 59 * 60 * @param psh The shell instance. 61 */ 37 62 void shthread_set_shell(struct shinstance *psh) 38 63 { 64 #if K_OS == K_OS_WINDOWS 65 if (sh_tls == TLS_OUT_OF_INDEXES) 66 { 67 sh_tls = TlsAlloc(); 68 assert(sh_tls != TLS_OUT_OF_INDEXES); 69 } 70 if (!TlsSetValue(sh_tls, psh)) 71 assert(0); 39 72 73 #elif K_OS == K_OS_OS2 74 if (sh_tls == -1) 75 { 76 sh_tls = __libc_TLSAlloc(); 77 assert(sh_tls != -1); 78 } 79 if (__libc_TLSSet(sh_tls, psh) == -1) 80 assert(0); 81 #else 82 if (!sh_tls_inited) 83 { 84 if (pthread_key_create(&sh_tls, NULL) != 0) 85 assert(0); 86 sh_tls_inited = 1; 87 } 88 if (pthread_setspecific(sh_tls, psh) != 0) 89 assert(0); 90 #endif 40 91 } 41 92 93 /** 94 * Get the shell instance pointer from TLS. 95 * 96 * @returns The shell instance. 97 */ 42 98 struct shinstance *shthread_get_shell(void) 43 99 { 44 shinstance *psh = NULL; 100 shinstance *psh; 101 #if K_OS == K_OS_WINDOWS 102 psh = (shinstance *)TlsGetValue(sh_tls); 103 #elif K_OS == K_OS_OS2 104 psh = (shinstance *)__libc_TLSGet(iTls) 105 #else 106 psh = (shinstance *)pthread_getspecific(sh_tls); 107 #endif 45 108 return psh; 46 109 } 47 110 48
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器