Lines Matching refs:shp

73     Shell_t *shp;           // shell interpreter  member
113 void sh_subtmpfile(Shell_t *shp) { in sh_subtmpfile() argument
116 checkpt_t *pp = shp->jmplist; in sh_subtmpfile()
120 shp->fdstatus[fd] = shp->fdstatus[1] | IOCLEX; in sh_subtmpfile()
127 if (shp->comsub != 1) sfdisc(sfstdout, SF_POPDISC); in sh_subtmpfile()
146 shp->fdstatus[fd] = IOREAD | IOWRITE; in sh_subtmpfile()
153 shp->fdstatus[1] = shp->fdstatus[fd]; in sh_subtmpfile()
154 shp->fdstatus[fd] = IOCLOSE; in sh_subtmpfile()
157 sh_iostream(shp, 1, 1); in sh_subtmpfile()
159 sfpool(sfstdout, shp->outpool, SF_WRITE); in sh_subtmpfile()
171 Shell_t *shp = sp->shp; in sh_subfork() local
172 long curenv = shp->curenv; in sh_subfork()
173 int comsub = shp->comsub; in sh_subfork()
175 char *trap = shp->st.trapcom[0]; in sh_subfork()
179 if (sp->pipe) sh_subtmpfile(shp); in sh_subfork()
180 shp->curenv = 0; in sh_subfork()
181 shp->savesig = -1; in sh_subfork()
182 pid = sh_fork(shp, FSHOWME, NULL); in sh_subfork()
185 shp->curenv = curenv; in sh_subfork()
192 siglongjmp(shp->jmplist->buff, SH_JMPSUB); in sh_subfork()
196 shp->cpid = 0; in sh_subfork()
197 sh_onstate(shp, SH_FORKED); in sh_subfork()
198 sh_onstate(shp, SH_NOLOG); in sh_subfork()
199 sh_offoption(shp, SH_MONITOR); in sh_subfork()
200 sh_offstate(shp, SH_MONITOR); in sh_subfork()
202 shp->subshell = 0; in sh_subfork()
203 shp->savesig = 0; in sh_subfork()
206 sh_iorenumber(shp, sp->tmpfd, 1); in sh_subfork()
207 shp->savesig = -1; in sh_subfork()
209 shp->comsub = 0; in sh_subfork()
212 shp->st.trapcom[0] = trap; in sh_subfork()
247 Shell_t *shp; in sh_assignok() local
258 shp = sp->shp; in sh_assignok()
259 dp = shp->var_tree; in sh_assignok()
262 shp->last_root = ap->table; in sh_assignok()
275 Dt_t *walk, *root = shp->var_tree; in sh_assignok()
299 save = shp->subshell; in sh_assignok()
300 shp->subshell = 0; in sh_assignok()
303 shp->subshell = save; in sh_assignok()
347 sh_envput(sp->shp, mp); in nv_restore()
349 env_delete(sp->shp->env, nv_name(mp)); in nv_restore()
368 Dt_t *sh_subaliastree(Shell_t *shp, int create) { in sh_subaliastree() argument
370 if (!sp || shp->curenv == 0) return shp->alias_tree; in sh_subaliastree()
373 dtuserdata(sp->salias, shp, 1); in sh_subaliastree()
374 dtview(sp->salias, shp->alias_tree); in sh_subaliastree()
375 shp->alias_tree = sp->salias; in sh_subaliastree()
384 Dt_t *sh_subfuntree(Shell_t *shp, bool create) { in sh_subfuntree() argument
386 if (!sp || shp->curenv == 0) return shp->fun_tree; in sh_subfuntree()
389 dtuserdata(sp->sfun, shp, 1); in sh_subfuntree()
390 dtview(sp->sfun, shp->fun_tree); in sh_subfuntree()
391 shp->fun_tree = sp->sfun; in sh_subfuntree()
393 return sp->shp->fun_tree; in sh_subfuntree()
444 Sfio_t *sh_subshell(Shell_t *shp, Shnode_t *t, volatile int flags, int comsub) { in sh_subshell() argument
448 long savecurenv = shp->curenv; in sh_subshell()
462 sfsync(shp->outpool); in sh_subshell()
463 sh_sigcheck(shp); in sh_subshell()
464 shp->savesig = -1; in sh_subshell()
465 argsav = sh_arguse(shp); in sh_subshell()
467 if (shp->curenv == 0) { in sh_subshell()
471 shp->curenv = ++subenv_level; in sh_subshell()
472 if (shp->curenv <= 0) shp->curenv = subenv_level = 1; in sh_subshell()
473 savst = shp->st; in sh_subshell()
474 sh_pushcontext(shp, &buff, SH_JMPSUB); in sh_subshell()
475 shp->subshell++; in sh_subshell()
476 STORE_VT(VAR_sh_subshell->nvalue, i16, shp->subshell); in sh_subshell()
478 sp->shp = shp; in sh_subshell()
482 sp->var = shp->var_tree; in sh_subshell()
483 sp->options = shp->options; in sh_subshell()
485 sp->subdup = shp->subdup; in sh_subshell()
486 shp->subdup = 0; in sh_subshell()
488 if (!shp->pathlist) { in sh_subshell()
489 shp->pathinit = 1; in sh_subshell()
490 path_get(shp, e_dot); in sh_subshell()
491 shp->pathinit = 0; in sh_subshell()
493 if (!shp->pwd) path_pwd(shp); in sh_subshell()
494 sp->bckpid = shp->bckpid; in sh_subshell()
500 sp->subshare = shp->subshare; in sh_subshell()
501 sp->comsub = shp->comsub; in sh_subshell()
502 shp->subshare = comsub == 2 || (comsub && sh_isoption(shp, SH_SUBSHARE)); in sh_subshell()
503 if (!shp->subshare) sp->pathlist = path_dup(shp->pathlist); in sh_subshell()
505 shp->comsub = comsub; in sh_subshell()
508 if (!comsub || !shp->subshare) { in sh_subshell()
509 sp->shpwd = shp->pwd; in sh_subshell()
510 sp->shpwdfd = ((shp->pwdfd >= 0)) ? sh_fcntl(shp->pwdfd, F_DUPFD_CLOEXEC, 10) : -1; in sh_subshell()
518 sp->pwd = (shp->pwd ? strdup(shp->pwd) : 0); in sh_subshell()
519 sp->mask = shp->mask; in sh_subshell()
522 shp->st.otrapcom = NULL; in sh_subshell()
523 shp->st.otrap = savst.trap; in sh_subshell()
524 nsig = shp->st.trapmax; in sh_subshell()
525 if (nsig > 0 || shp->st.trapcom[0]) { in sh_subshell()
529 savsig[isig] = shp->st.trapcom[isig] ? strdup(shp->st.trapcom[isig]) : NULL; in sh_subshell()
532 shp->st.otrapcom = savsig; in sh_subshell()
534 sp->cpid = shp->cpid; in sh_subshell()
535 sp->coutpipe = shp->coutpipe; in sh_subshell()
536 sp->cpipe = shp->cpipe[1]; in sh_subshell()
537 shp->cpid = 0; in sh_subshell()
538 sh_sigreset(shp, 0); in sh_subshell()
544 shp->spid = 0; in sh_subshell()
546 sp->monitor = (sh_isstate(shp, SH_MONITOR) != 0); in sh_subshell()
548 sh_offstate(shp, SH_MONITOR); in sh_subshell()
561 sp->fdstatus = shp->fdstatus[1]; in sh_subshell()
572 shp->fdstatus[1] = IOWRITE; in sh_subshell()
573 sp->nofork = sh_isstate(shp, SH_NOFORK); in sh_subshell()
574 if (!sp->nofork) sh_onstate(shp, SH_NOFORK); in sh_subshell()
580 if (shp->savesig < 0) { in sh_subshell()
581 shp->savesig = 0; in sh_subshell()
582 sh_exec(shp, t, flags); in sh_subshell()
585 if (comsub != 2 && jmpval != SH_JMPSUB && shp->st.trapcom[0] && shp->subshell) { in sh_subshell()
587 char *trap = shp->st.trapcom[0]; in sh_subshell()
588 shp->st.trapcom[0] = 0; // prevent recursion in sh_subshell()
589 shp->oldexit = shp->exitval; in sh_subshell()
590 sh_trap(shp, trap, 0); in sh_subshell()
593 sh_popcontext(shp, &buff); in sh_subshell()
594 if (shp->subshell == 0) { // must be child process in sh_subshell()
595 shp->st.trapcom[0] = 0; in sh_subshell()
597 if (jmpval == SH_JMPSCRIPT) siglongjmp(shp->jmplist->buff, jmpval); in sh_subshell()
598 shp->exitval &= SH_EXITMASK; in sh_subshell()
599 sh_done(shp, 0); in sh_subshell()
601 if (!shp->savesig) shp->savesig = -1; in sh_subshell()
605 if (!sp->nofork) sh_offstate(shp, SH_NOFORK); in sh_subshell()
607 if (sp->monitor) sh_onstate(shp, SH_MONITOR); in sh_subshell()
610 iop = sh_iostream(shp, sp->pipefd, sp->pipefd); in sh_subshell()
613 if (shp->spid) { in sh_subshell()
614 int c = shp->savexit; in sh_subshell()
615 job_wait(shp->spid); in sh_subshell()
616 shp->exitval = c; in sh_subshell()
617 if (shp->pipepid == shp->spid) shp->spid = 0; in sh_subshell()
618 shp->pipepid = 0; in sh_subshell()
629 int fd = sfsetfd(iop, sh_get_unused_fd(shp, 3)); in sh_subshell()
631 shp->toomany = 1; in sh_subshell()
632 shp->jmplist->mode = SH_JMPERREXIT; in sh_subshell()
636 if (fd >= shp->gd->lim.open_max && !sh_iovalidfd(shp, fd)) abort(); in sh_subshell()
637 shp->sftable[fd] = iop; in sh_subshell()
639 shp->fdstatus[fd] = (shp->fdstatus[1] | IOCLEX); in sh_subshell()
640 shp->fdstatus[1] = IOCLOSE; in sh_subshell()
655 shp->fdstatus[1] = sp->fdstatus; in sh_subshell()
657 if (!shp->subshare) { in sh_subshell()
658 path_delete(shp->pathlist); in sh_subshell()
659 shp->pathlist = sp->pathlist; in sh_subshell()
661 job_subrestore(shp, sp->jobs); in sh_subshell()
662 shp->jobenv = savecurenv; in sh_subshell()
665 shp->bckpid = sp->bckpid; in sh_subshell()
668 shp->options = sp->options; in sh_subshell()
670 shp->alias_tree = dtview(sp->salias, 0); in sh_subshell()
675 shp->fun_tree = dtview(sp->sfun, 0); in sh_subshell()
679 n = shp->st.trapmax - savst.trapmax; in sh_subshell()
680 sh_sigreset(shp, 1); in sh_subshell()
681 if (n > 0) memset(&shp->st.trapcom[savst.trapmax], 0, n * sizeof(char *)); in sh_subshell()
682 shp->st = savst; in sh_subshell()
683 shp->curenv = savecurenv; in sh_subshell()
684 shp->st.otrap = NULL; in sh_subshell()
687 if (shp->st.trapcom[isig]) { in sh_subshell()
688 free(shp->st.trapcom[isig]); in sh_subshell()
691 memcpy(shp->st.trapcom, savsig, nsig * sizeof(char *)); in sh_subshell()
692 shp->st.otrapcom = NULL; in sh_subshell()
695 shp->options = sp->options; in sh_subshell()
696 if (!shp->pwd || strcmp(sp->pwd, shp->pwd)) { in sh_subshell()
698 Namval_t *pwdnod = sh_scoped(shp, VAR_PWD); in sh_subshell()
699 if (shp->pwd) { in sh_subshell()
700 shp->pwd = sp->pwd; in sh_subshell()
702 if (sp->shpwdfd < 0) chdir(shp->pwd); in sh_subshell()
704 path_newdir(shp, shp->pathlist); in sh_subshell()
707 } else if (sp->shpwd != shp->pwd) { in sh_subshell()
708 shp->pwd = sp->pwd; in sh_subshell()
719 if (sp->mask != shp->mask) umask(shp->mask = sp->mask); in sh_subshell()
720 if (shp->coutpipe != sp->coutpipe) { in sh_subshell()
721 sh_close(shp->coutpipe); in sh_subshell()
722 sh_close(shp->cpipe[1]); in sh_subshell()
724 shp->cpid = sp->cpid; in sh_subshell()
725 shp->cpipe[1] = sp->cpipe; in sh_subshell()
726 shp->coutpipe = sp->coutpipe; in sh_subshell()
729 if (shp->pwdfd >= 0) sh_close(shp->pwdfd); in sh_subshell()
730 shp->pwdfd = sp->shpwdfd; in sh_subshell()
731 sh_fchdir(shp->pwdfd); in sh_subshell()
733 shp->subshare = sp->subshare; in sh_subshell()
734 shp->subdup = sp->subdup; in sh_subshell()
735 if (shp->subshell) STORE_VT(VAR_sh_subshell->nvalue, i16, --shp->subshell); in sh_subshell()
737 if (!argsav || argsav->dolrefcnt == argcnt) sh_argfree(shp, argsav); in sh_subshell()
738 if (shp->topfd != buff.topfd) sh_iorestore(shp, buff.topfd | IOSUBSHELL, jmpval); in sh_subshell()
740 if ((vp = shp->vexp) && vp->cur) sh_vexrestore(shp, buff.vexi); in sh_subshell()
747 sh_chktrap(shp); in sh_subshell()
750 sh_sigcheck(shp); in sh_subshell()
751 shp->trapnote = 0; in sh_subshell()
752 nsig = shp->savesig; in sh_subshell()
753 shp->savesig = 0; in sh_subshell()
756 shp->spid = sp->subpid; in sh_subshell()
759 if (comsub > 1) sh_iounpipe(shp); in sh_subshell()
761 shp->comsub = sp->comsub; in sh_subshell()
763 if (shp->trapnote) sh_chktrap(shp); in sh_subshell()
764 if (shp->exitval > SH_EXITSIG) { in sh_subshell()
765 int sig = shp->exitval & SH_EXITMASK; in sh_subshell()
769 shp->jmplist->mode = SH_JMPERREXIT; in sh_subshell()
770 shp->toomany = 1; in sh_subshell()
774 if (shp->ignsig) kill(getpid(), shp->ignsig); in sh_subshell()
775 if (jmpval == SH_JMPSUB && shp->lastsig) kill(getpid(), shp->lastsig); in sh_subshell()
776 if (jmpval && shp->toomany) siglongjmp(shp->jmplist->buff, jmpval); in sh_subshell()