Lines Matching refs:shp

60 	Shell_t		*shp;	/* shell interpreter */  member
108 void sh_subtmpfile(Shell_t *shp) in sh_subtmpfile() argument
113 register struct checkpt *pp = (struct checkpt*)shp->jmplist; in sh_subtmpfile()
119 shp->fdstatus[fd] = shp->fdstatus[1]|IOCLEX; in sh_subtmpfile()
126 if(shp->comsub != 1) in sh_subtmpfile()
147 shp->fdstatus[fd] = IOREAD|IOWRITE; in sh_subtmpfile()
154 shp->fdstatus[1] = shp->fdstatus[fd]; in sh_subtmpfile()
155 shp->fdstatus[fd] = IOCLOSE; in sh_subtmpfile()
158 sh_iostream(shp,1,1); in sh_subtmpfile()
160 sfpool(sfstdout,shp->outpool,SF_WRITE); in sh_subtmpfile()
175 Shell_t *shp = sp->shp; in sh_subfork() local
176 long curenv = shp->curenv; in sh_subfork()
177 int comsub=shp->comsub; in sh_subfork()
179 char *trap = shp->st.trapcom[0]; in sh_subfork()
184 sh_subtmpfile(shp); in sh_subfork()
185 shp->curenv = 0; in sh_subfork()
186 shp->savesig = -1; in sh_subfork()
187 if(pid = sh_fork(shp,FSHOWME,NIL(int*))) in sh_subfork()
189 shp->curenv = curenv; in sh_subfork()
200 siglongjmp(*shp->jmplist,SH_JMPSUB); in sh_subfork()
206 shp->cpid = 0; in sh_subfork()
207 sh_onstate(shp,SH_FORKED); in sh_subfork()
208 sh_onstate(shp,SH_NOLOG); in sh_subfork()
209 sh_offoption(shp,SH_MONITOR); in sh_subfork()
210 sh_offstate(shp,SH_MONITOR); in sh_subfork()
212 shp->subshell = 0; in sh_subfork()
213 shp->savesig = 0; in sh_subfork()
217 sh_iorenumber(shp, sp->tmpfd, 1); in sh_subfork()
218 shp->savesig = -1; in sh_subfork()
220 shp->comsub = 0; in sh_subfork()
223 shp->st.trapcom[0] = trap; in sh_subfork()
264 Shell_t *shp; in sh_assignok() local
272 shp = sp->shp; in sh_assignok()
273 dp = shp->var_tree; in sh_assignok()
275 if(sp->var!=shp->var_tree && sp->var!=shp->var_base && shp->last_root==shp->var_tree) in sh_assignok()
279 shp->last_root = ap->table; in sh_assignok()
296 Dt_t *walk, *root=shp->var_tree; in sh_assignok()
318 save = shp->subshell; in sh_assignok()
319 shp->subshell = 0; in sh_assignok()
324 shp->subshell = save; in sh_assignok()
379 sh_envput(sp->shp,mp); in nv_restore()
384 env_delete(sp->shp->env,nv_name(mp)); in nv_restore()
402 Dt_t *sh_subaliastree(Shell_t *shp,int create) in sh_subaliastree() argument
405 if(!sp || shp->curenv==0) in sh_subaliastree()
406 return(shp->alias_tree); in sh_subaliastree()
410 dtuserdata(sp->salias,shp,1); in sh_subaliastree()
411 dtview(sp->salias,shp->alias_tree); in sh_subaliastree()
412 shp->alias_tree = sp->salias; in sh_subaliastree()
421 Dt_t *sh_subfuntree(Shell_t *shp,int create) in sh_subfuntree() argument
424 if(!sp || shp->curenv==0) in sh_subfuntree()
425 return(shp->fun_tree); in sh_subfuntree()
429 dtuserdata(sp->sfun,shp,1); in sh_subfuntree()
430 dtview(sp->sfun,shp->fun_tree); in sh_subfuntree()
431 shp->fun_tree = sp->sfun; in sh_subfuntree()
433 return(sp->shp->fun_tree); in sh_subfuntree()
484 Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub) in sh_subshell() argument
489 long savecurenv = shp->curenv; in sh_subshell()
504 sfsync(shp->outpool); in sh_subshell()
505 sh_sigcheck(shp); in sh_subshell()
506 shp->savesig = -1; in sh_subshell()
507 if(argsav = sh_arguse(shp)) in sh_subshell()
509 if(shp->curenv==0) in sh_subshell()
514 shp->curenv = ++subenv; in sh_subshell()
515 if(shp->curenv<=0) in sh_subshell()
516 shp->curenv = subenv = 1; in sh_subshell()
517 savst = shp->st; in sh_subshell()
518 sh_pushcontext(shp,&buff,SH_JMPSUB); in sh_subshell()
519 subshell = shp->subshell+1; in sh_subshell()
521 shp->subshell = subshell; in sh_subshell()
523 sp->shp = shp; in sh_subshell()
527 sp->var = shp->var_tree; in sh_subshell()
528 sp->options = shp->options; in sh_subshell()
530 sp->subdup = shp->subdup; in sh_subshell()
531 shp->subdup = 0; in sh_subshell()
533 sp->coshell = shp->coshell; in sh_subshell()
534 shp->coshell = 0; in sh_subshell()
537 if(!shp->pathlist) in sh_subshell()
539 shp->pathinit = 1; in sh_subshell()
540 path_get(shp,e_dot); in sh_subshell()
541 shp->pathinit = 0; in sh_subshell()
543 if(!shp->pwd) in sh_subshell()
544 path_pwd(shp,0); in sh_subshell()
545 sp->bckpid = shp->bckpid; in sh_subshell()
550 sp->subshare = shp->subshare; in sh_subshell()
551 sp->comsub = shp->comsub; in sh_subshell()
552 shp->subshare = comsub==2 || (comsub && sh_isoption(shp,SH_SUBSHARE)); in sh_subshell()
553 if(!shp->subshare) in sh_subshell()
554 sp->pathlist = path_dup((Pathcomp_t*)shp->pathlist); in sh_subshell()
557 shp->comsub = comsub; in sh_subshell()
558 if(comsub==1 && !(pipefail=sh_isoption(shp,SH_PIPEFAIL))) in sh_subshell()
559 sh_onoption(shp,SH_PIPEFAIL); in sh_subshell()
562 if(!comsub || !shp->subshare) in sh_subshell()
564 sp->shpwd = shp->pwd; in sh_subshell()
565 sp->shpwdfd=((shp->pwdfd >= 0))?sh_fcntl(shp->pwdfd, F_dupfd_cloexec, 10):-1; in sh_subshell()
570 sp->pwd = (shp->pwd?strdup(shp->pwd):0); in sh_subshell()
571 sp->mask = shp->mask; in sh_subshell()
574 shp->st.otrapcom = 0; in sh_subshell()
575 shp->st.otrap = savst.trap; in sh_subshell()
576 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_subshell()
579 memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_subshell()
581 shp->st.otrapcom = (char**)savsig; in sh_subshell()
583 sp->cpid = shp->cpid; in sh_subshell()
584 sp->coutpipe = shp->coutpipe; in sh_subshell()
585 sp->cpipe = shp->cpipe[1]; in sh_subshell()
586 shp->cpid = 0; in sh_subshell()
587 sh_sigreset(shp,0); in sh_subshell()
595 shp->spid = 0; in sh_subshell()
597 sp->monitor = (sh_isstate(shp,SH_MONITOR)!=0); in sh_subshell()
599 sh_offstate(shp,SH_MONITOR); in sh_subshell()
615 sp->fdstatus = shp->fdstatus[1]; in sh_subshell()
626 shp->fdstatus[1] = IOWRITE; in sh_subshell()
628 sh_onstate(shp,SH_NOFORK); in sh_subshell()
636 if(shp->savesig < 0) in sh_subshell()
638 shp->savesig = 0; in sh_subshell()
639 sh_exec(shp,t,flags); in sh_subshell()
642 if(comsub!=2 && jmpval!=SH_JMPSUB && shp->st.trapcom[0] && shp->subshell) in sh_subshell()
645 char *trap=shp->st.trapcom[0]; in sh_subshell()
646 shp->st.trapcom[0] = 0; /* prevent recursion */ in sh_subshell()
647 shp->oldexit = shp->exitval; in sh_subshell()
648 sh_trap(shp,trap,0); in sh_subshell()
651 sh_popcontext(shp,&buff); in sh_subshell()
652 if(shp->subshell==0) /* must be child process */ in sh_subshell()
654 shp->st.trapcom[0] = 0; in sh_subshell()
657 siglongjmp(*shp->jmplist,jmpval); in sh_subshell()
658 shp->exitval &= SH_EXITMASK; in sh_subshell()
659 sh_done(shp,0); in sh_subshell()
661 if(!shp->savesig) in sh_subshell()
662 shp->savesig = -1; in sh_subshell()
668 sh_offstate(shp,SH_NOFORK); in sh_subshell()
671 sh_onstate(shp,SH_MONITOR); in sh_subshell()
675 iop = sh_iostream(shp,sp->pipefd,sp->pipefd); in sh_subshell()
681 if(shp->spid) in sh_subshell()
683 int c = shp->savexit; in sh_subshell()
684 job_wait(shp->spid); in sh_subshell()
685 shp->exitval = c; in sh_subshell()
686 if(shp->pipepid==shp->spid) in sh_subshell()
687 shp->spid = 0; in sh_subshell()
688 shp->pipepid = 0; in sh_subshell()
691 sh_offoption(shp,SH_PIPEFAIL); in sh_subshell()
705 shp->toomany = 1; in sh_subshell()
706 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; in sh_subshell()
709 if(fd >= shp->gd->lim.open_max) in sh_subshell()
710 sh_iovalidfd(shp,fd); in sh_subshell()
711 shp->sftable[fd] = iop; in sh_subshell()
713 shp->fdstatus[fd] = (shp->fdstatus[1]|IOCLEX); in sh_subshell()
714 shp->fdstatus[1] = IOCLOSE; in sh_subshell()
732 shp->fdstatus[1] = sp->fdstatus; in sh_subshell()
734 if(!shp->subshare) in sh_subshell()
736 path_delete((Pathcomp_t*)shp->pathlist); in sh_subshell()
737 shp->pathlist = (void*)sp->pathlist; in sh_subshell()
739 job_subrestore(shp,sp->jobs); in sh_subshell()
740 shp->jobenv = savecurenv; in sh_subshell()
743 shp->bckpid = sp->bckpid; in sh_subshell()
747 shp->options = sp->options; in sh_subshell()
750 shp->alias_tree = dtview(sp->salias,0); in sh_subshell()
756 shp->fun_tree = dtview(sp->sfun,0); in sh_subshell()
760 n = shp->st.trapmax-savst.trapmax; in sh_subshell()
761 sh_sigreset(shp,1); in sh_subshell()
763 memset(&shp->st.trapcom[savst.trapmax],0,n*sizeof(char*)); in sh_subshell()
764 shp->st = savst; in sh_subshell()
765 shp->curenv = savecurenv; in sh_subshell()
766 shp->st.otrap = 0; in sh_subshell()
769 memcpy((char*)&shp->st.trapcom[0],savsig,nsig); in sh_subshell()
772 shp->options = sp->options; in sh_subshell()
773 if(!shp->pwd || strcmp(sp->pwd,shp->pwd)) in sh_subshell()
776 Namval_t *pwdnod = sh_scoped(shp,PWDNOD); in sh_subshell()
777 if(shp->pwd) in sh_subshell()
779 shp->pwd=sp->pwd; in sh_subshell()
782 chdir(shp->pwd); in sh_subshell()
784 path_newdir(shp,shp->pathlist); in sh_subshell()
789 else if(sp->shpwd != shp->pwd) in sh_subshell()
791 shp->pwd = sp->pwd; in sh_subshell()
804 if(sp->mask!=shp->mask) in sh_subshell()
805 umask(shp->mask=sp->mask); in sh_subshell()
806 if(shp->coutpipe!=sp->coutpipe) in sh_subshell()
808 sh_close(shp->coutpipe); in sh_subshell()
809 sh_close(shp->cpipe[1]); in sh_subshell()
811 shp->cpid = sp->cpid; in sh_subshell()
812 shp->cpipe[1] = sp->cpipe; in sh_subshell()
813 shp->coutpipe = sp->coutpipe; in sh_subshell()
817 if(shp->pwdfd >=0) in sh_subshell()
818 sh_close(shp->pwdfd); in sh_subshell()
819 shp->pwdfd=sp->shpwdfd; in sh_subshell()
820 fchdir(shp->pwdfd); in sh_subshell()
822 shp->subshare = sp->subshare; in sh_subshell()
823 shp->subdup = sp->subdup; in sh_subshell()
825 shp->coshell = sp->coshell; in sh_subshell()
827 if(shp->subshell) in sh_subshell()
828 SH_SUBSHELLNOD->nvalue.s = --shp->subshell; in sh_subshell()
829 subshell = shp->subshell; in sh_subshell()
832 sh_argfree(shp,argsav,0); in sh_subshell()
833 if(shp->topfd != buff.topfd) in sh_subshell()
834 sh_iorestore(shp,buff.topfd|IOSUBSHELL,jmpval); in sh_subshell()
836 if((vp=(Spawnvex_t*)shp->vexp) && vp->cur) in sh_subshell()
837 sh_vexrestore(shp,buff.vexi); in sh_subshell()
846 sh_chktrap(shp); in sh_subshell()
849 sh_sigcheck(shp); in sh_subshell()
850 shp->trapnote = 0; in sh_subshell()
851 nsig = shp->savesig; in sh_subshell()
852 shp->savesig = 0; in sh_subshell()
856 shp->spid = sp->subpid; in sh_subshell()
861 sh_iounpipe(shp); in sh_subshell()
863 shp->comsub = sp->comsub; in sh_subshell()
866 if(shp->trapnote) in sh_subshell()
867 sh_chktrap(shp); in sh_subshell()
868 if(shp->exitval > SH_EXITSIG) in sh_subshell()
870 int sig = shp->exitval&SH_EXITMASK; in sh_subshell()
876 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; in sh_subshell()
877 shp->toomany = 1; in sh_subshell()
880 if(shp->ignsig) in sh_subshell()
881 kill(getpid(),shp->ignsig); in sh_subshell()
882 if(jmpval==SH_JMPSUB && shp->lastsig) in sh_subshell()
883 kill(getpid(),shp->lastsig); in sh_subshell()
884 if(jmpval && shp->toomany) in sh_subshell()
885 siglongjmp(*shp->jmplist,jmpval); in sh_subshell()