Changeset 3433 in kBuild
- Timestamp:
- Sep 2, 2020 5:25:31 PM (5 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r3409 r3433 43 43 kash_DEFS.win = \ 44 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 SH_DEAL_WITH_CRLF PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS EXEC_HASH_BANG_SCRIPT \ 46 KASH_USE_FORKSHELL2 46 47 kash_DEFS.os2 = \ 47 48 HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME PC_OS2_LIBPATHS \ -
trunk/src/kash/eval.c
r3065 r3433 413 413 414 414 415 #ifdef KASH_USE_FORKSHELL2 416 /* 417 * Child of evalsubshell. 418 */ 419 struct evalsubshellchild 420 { 421 int flags; 422 int backgnd; 423 }; 424 425 static int evalsubshell_child(shinstance *psh, union node *n, void *argp) 426 { 427 struct evalsubshellchild args = *(struct evalsubshellchild *)argp; 428 429 INTON; 430 if (args.backgnd) 431 args.flags &=~ EV_TESTED; 432 redirect(psh, n->nredir.redirect, 0); 433 /* never returns */ 434 evaltree(psh, n->nredir.n, args.flags | EV_EXIT); 435 /** @todo make us return here. */ 436 return 0; 437 } 438 #endif /* KASH_USE_FORKSHELL2 */ 439 415 440 416 441 /* … … 427 452 INTOFF; 428 453 jp = makejob(psh, n, 1); 454 #ifdef KASH_USE_FORKSHELL2 455 { 456 struct evalsubshellchild args; 457 args.flags = flags; 458 args.backgnd = backgnd; 459 forkshell2(psh, jp, n, backgnd ? FORK_BG : FORK_FG, 460 evalsubshell_child, n, &args, sizeof(args)); 461 } 462 #else 429 463 if (forkshell(psh, jp, n, backgnd ? FORK_BG : FORK_FG) == 0) { 430 464 INTON; … … 435 469 evaltree(psh, n->nredir.n, flags | EV_EXIT); 436 470 } 471 #endif 437 472 if (! backgnd) 438 473 psh->exitstatus = waitforjob(psh, jp); … … 475 510 476 511 512 #ifdef KASH_USE_FORKSHELL2 513 /* 514 * Child of evalpipe. 515 */ 516 struct evalpipechild 517 { 518 int prevfd; 519 int pip[2]; 520 }; 521 522 static int evalpipe_child(shinstance *psh, union node *n, void *argp) 523 { 524 struct evalpipechild args = *(struct evalpipechild *)argp; 525 526 if (args.prevfd > 0) { 527 movefd(psh, args.prevfd, 0); 528 } 529 if (args.pip[1] >= 0) { 530 shfile_close(&psh->fdtab, args.pip[0]); 531 if (args.pip[1] != 1) { 532 movefd(psh, args.pip[1], 1); 533 } 534 } 535 evaltree(psh, n, EV_EXIT); 536 /** @todo make it return thru here. */ 537 return 0; 538 } 539 #endif /* KASH_USE_FORKSHELL2 */ 477 540 478 541 /* … … 508 571 } 509 572 } 573 #ifdef KASH_USE_FORKSHELL2 574 { 575 struct evalpipechild args; 576 args.prevfd = prevfd; 577 args.pip[0] = pip[0]; 578 args.pip[1] = pip[1]; 579 forkshell2(psh, jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG, 580 evalpipe_child, lp->n, &args, sizeof(args)); 581 } 582 #else 510 583 if (forkshell(psh, jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) { 511 584 INTON; … … 521 594 evaltree(psh, lp->n, EV_EXIT); 522 595 } 596 #endif 523 597 if (prevfd >= 0) 524 598 shfile_close(&psh->fdtab, prevfd); … … 533 607 } 534 608 535 609 #ifdef KASH_USE_FORKSHELL2 610 /* 611 * evalbackcmd child. 612 */ 613 struct evalbackcmdchild 614 { 615 int pip[2]; 616 }; 617 618 static int evalbackcmd_child(shinstance *psh, union node *n, void *argp) 619 { 620 struct evalbackcmdchild args = *(struct evalbackcmdchild *)argp; 621 622 FORCEINTON; 623 shfile_close(&psh->fdtab, args.pip[0]); 624 if (args.pip[1] != 1) { 625 movefd(psh, args.pip[1], 1); 626 } 627 eflag(psh) = 0; 628 evaltree(psh, n, EV_EXIT); 629 /* NOTREACHED */ /** @todo make it return here to simplify thread handling (no need for setjmp). */ 630 return 0; 631 } 632 #endif /* KASH_USE_FORKSHELL2 */ 536 633 537 634 /* … … 574 671 error(psh, "Pipe call failed"); 575 672 jp = makejob(psh, n, 1); 673 #ifdef KASH_USE_FORKSHELL2 674 { 675 struct evalbackcmdchild args; 676 args.pip[0] = pip[0]; 677 args.pip[1] = pip[1]; 678 forkshell2(psh, jp, n, FORK_NOJOB, 679 evalbackcmd_child, n, &args, sizeof(args)); 680 } 681 #else 576 682 if (forkshell(psh, jp, n, FORK_NOJOB) == 0) { 577 683 FORCEINTON; … … 584 690 /* NOTREACHED */ 585 691 } 692 #endif 586 693 shfile_close(&psh->fdtab, pip[1]); 587 694 result->fd = pip[0]; -
trunk/src/kash/jobs.c
r3408 r3433 800 800 } 801 801 802 int forkshell2(struct shinstance *psh, struct job *jp, union node *n, int mode, 803 int (*child)(struct shinstance *, void *, union node *), 804 union node *nchild, void *argp, size_t arglen) 805 { 806 pid_t pid; 807 808 TRACE((psh, "forkshell2(%%%d, %p, %d, %p, %p, %p, %d) called\n", jp - psh->jobtab, n, mode, child, nchild, argp, (int)arglen)); 809 pid = sh_fork(psh); 810 if (pid == 0) 811 { 812 /* child */ 813 (void)arglen; 814 forkchild(psh, jp, n, mode, 0); 815 sh_exit(psh, child(psh, nchild, argp)); 816 return 0; 817 } 818 819 /* parent */ 820 if (pid != -1) 821 return forkparent(psh, jp, n, mode, pid); 822 TRACE((psh, "Fork failed, errno=%d\n", errno)); 823 INTON; 824 error(psh, "Cannot fork"); 825 return -1; /* won't get here */ 826 } 827 802 828 int 803 829 forkparent(shinstance *psh, struct job *jp, union node *n, int mode, pid_t pid) -
trunk/src/kash/jobs.h
r1233 r3433 96 96 struct job *makejob(struct shinstance *, union node *, int); 97 97 int forkshell(struct shinstance *, struct job *, union node *, int); 98 #ifdef KASH_USE_FORKSHELL2 99 int forkshell2(struct shinstance *, struct job *, union node *, int, 100 int (*child)(struct shinstance *, void *, union node *), 101 union node *, void *, size_t); 102 #endif 98 103 void forkchild(struct shinstance *, struct job *, union node *, int, int); 99 104 int forkparent(struct shinstance *, struct job *, union node *, int, pid_t); -
trunk/src/kash/redir.c
r2648 r3433 243 243 } 244 244 245 #ifdef KASH_USE_FORKSHELL2 246 struct openherechild 247 { 248 int pip[2]; 249 size_t len; 250 }; 251 static int openhere_child(shinstance *psh, union node *n, void *argp) 252 { 253 struct openherechild args = *(struct openherechild *)argp; 254 255 shfile_close(&psh->fdtab, args.pip[0]); 256 sh_signal(psh, SIGINT, SH_SIG_IGN); 257 sh_signal(psh, SIGQUIT, SH_SIG_IGN); 258 sh_signal(psh, SIGHUP, SH_SIG_IGN); 259 # ifdef SIGTSTP 260 sh_signal(psh, SIGTSTP, SH_SIG_IGN); 261 # endif 262 sh_signal(psh, SIGPIPE, SH_SIG_DFL); 263 if (n->type == NHERE) 264 xwrite(psh, args.pip[1], n->nhere.doc->narg.text, args.len); 265 else 266 expandhere(psh, n->nhere.doc, args.pip[1]); 267 return 0; 268 } 269 270 #endif /* KASH_USE_FORKSHELL2*/ 245 271 246 272 /* … … 265 291 } 266 292 } 293 #ifdef KASH_USE_FORKSHELL2 294 { 295 struct openherechild args; 296 args.pip[0] = pip[0]; 297 args.pip[1] = pip[1]; 298 args.len = len; 299 forkshell2(psh, (struct job *)NULL, (union node *)NULL, FORK_NOJOB, 300 openhere_child, redir, &args, sizeof(args)); 301 } 302 #else 267 303 if (forkshell(psh, (struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) { 268 304 shfile_close(&psh->fdtab, pip[0]); … … 280 316 sh__exit(psh, 0); 281 317 } 318 #endif 282 319 out: 283 320 shfile_close(&psh->fdtab, pip[1]); -
trunk/src/kash/tests/Makefile.kmk
r2423 r3433 45 45 pipe-1 \ 46 46 pipe-2 \ 47 exec-1 \48 47 ) 48 49 # exec-1 - lost 49 50 50 51
Note:
See TracChangeset
for help on using the changeset viewer.