Lines Matching refs:shp

89 	Shell_t	*shp = (Shell_t*)handle;  in fifo_check()  local
93 unlink(shp->fifo); in fifo_check()
94 sh_done(shp,0); in fifo_check()
107 static int iousepipe(Shell_t *shp) in iousepipe() argument
113 iounpipe(shp); in iousepipe()
121 shp->fdstatus[subpipe[2]] = shp->fdstatus[1]; in iousepipe()
124 shp->fdstatus[1] = shp->fdstatus[subpipe[1]]; in iousepipe()
126 if(subdup=shp->subdup) for(i=0; i < 10; i++) in iousepipe()
132 shp->fdstatus[i] = shp->fdstatus[1]; in iousepipe()
138 static void iounpipe(Shell_t *shp) in iounpipe() argument
144 shp->fdstatus[1] = shp->fdstatus[subpipe[2]]; in iounpipe()
152 shp->fdstatus[n] = shp->fdstatus[1]; in iounpipe()
155 shp->subdup = 0; in iounpipe()
207 static int p_time(Shell_t *shp, Sfio_t *out, const char *format, clock_t *tm) in p_time() argument
212 Stk_t *stkp = shp->stk; in p_time()
252 d = (double)tm[n]/shp->gd->lim.clk_tck; in p_time()
482 static struct Level *init_level(Shell_t *shp,int level) in init_level() argument
488 shp->last_root = nv_dict(DOTSHNOD); in init_level()
498 int sh_debug(Shell_t *shp, const char *trap, const char *name, const char *subscript, char *const a… in sh_debug() argument
500 Stk_t *stkp=shp->stk; in sh_debug()
508 if(shp->indebug) in sh_debug()
510 shp->indebug = 1; in sh_debug()
541 shp->st.lineno = error_info.line; in sh_debug()
542 level = shp->fn_depth+shp->dot_depth; in sh_debug()
543 shp->last_root = nv_dict(DOTSHNOD); in sh_debug()
545 init_level(shp,level); in sh_debug()
548 savst = shp->st; in sh_debug()
549 shp->st.trap[SH_DEBUGTRAP] = 0; in sh_debug()
552 shp->indebug = 0; in sh_debug()
553 if(shp->st.cmdname) in sh_debug()
554 error_info.id = shp->st.cmdname; in sh_debug()
555 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_debug()
556 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_debug()
557 shp->st = savst; in sh_debug()
571 Shell_t *shp = sh_getinterp(); in sh_eval() local
572 struct slnod *saveslp = shp->st.staklist; in sh_eval()
574 struct checkpt *pp = (struct checkpt*)shp->jmplist; in sh_eval()
575 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_eval()
578 int binscript=shp->binscript; in sh_eval()
579 char comsub = shp->comsub; in sh_eval()
581 shp->binscript = 0; in sh_eval()
582 shp->comsub = 0; in sh_eval()
587 shp->fn_reset = 1; in sh_eval()
589 sh_pushcontext(shp,buffp,SH_JMPEVAL); in sh_eval()
596 lineno = shp->inlineno; in sh_eval()
600 t = (Shnode_t*)sh_parse(shp,iop,(mode&(SH_READEVAL|SH_FUNEVAL))?mode&SH_FUNEVAL:SH_NL); in sh_eval()
611 if((mode&~SH_FUNEVAL) && shp->gd->hist_ptr) in sh_eval()
613 hist_flush(shp->gd->hist_ptr); in sh_eval()
620 sh_popcontext(shp,buffp); in sh_eval()
621 shp->binscript = binscript; in sh_eval()
622 shp->comsub = comsub; in sh_eval()
626 shp->inlineno = lineno; in sh_eval()
629 sh_freeup(shp); in sh_eval()
630 shp->st.staklist = saveslp; in sh_eval()
631 shp->fn_reset = 0; in sh_eval()
633 siglongjmp(*shp->jmplist,jmpval); in sh_eval()
634 return(shp->exitval); in sh_eval()
671 static int set_instance(Shell_t *shp,Namval_t *nq, Namval_t *node, struct Namref *nr) in set_instance() argument
681 nr->root = shp->var_tree; in set_instance()
682 nr->table = shp->last_table; in set_instance()
684 if(!nr->table && shp->namespace) in set_instance()
685 nr->table = shp->namespace; in set_instance()
687 shp->instance = 1; in set_instance()
690 shp->instance = 0; in set_instance()
691 if(shp->var_tree!=shp->var_base && !nv_search((char*)nq,nr->root,HASH_BUCKET|HASH_NOSCOPE)) in set_instance()
694 nr->root = shp->namespace?nv_dict(shp->namespace):shp->var_base; in set_instance()
696 nr->root = shp->var_base; in set_instance()
747 static void *sh_coinit(Shell_t *shp,char **argv) in sh_coinit() argument
759 nv_open(name,shp->var_tree,NV_IDENT|NV_NOADD); in sh_coinit()
794 int sh_coaddfile(Shell_t *shp, char *name) in sh_coaddfile() argument
796 Namval_t *np = dtmatch(shp->inpool,name); in sh_coaddfile()
801 (Namval_t*)dtinsert(shp->inpool,np); in sh_coaddfile()
802 shp->poolfiles++; in sh_coaddfile()
808 static int sh_coexec(Shell_t *shp,const Shnode_t *t, int filt) in sh_coexec() argument
810 struct cosh *csp = ((struct cosh*)shp->coshell); in sh_coexec()
817 if(!shp->strbuf2) in sh_coexec()
818 shp->strbuf2 = sfstropen(); in sh_coexec()
819 sfswap(shp->strbuf2,sfstdout); in sh_coexec()
821 for(sig=shp->st.trapmax;--sig>0;) in sh_coexec()
823 if((trap=shp->st.trapcom[sig]) && *trap==0) in sh_coexec()
834 if(shp->inpipe[2]>=20000) in sh_coexec()
835 …sfprintf(sfstdout,"command exec < /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->in… in sh_coexec()
836 …sfprintf(sfstdout,"command exec > /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->ou… in sh_coexec()
842 nv_scan(shp->fun_tree, print_fun, (void*)0,0, 0); in sh_coexec()
845 Dt_t *top = shp->var_tree; in sh_coexec()
846 sh_scope(shp,(struct argnod*)0,0); in sh_coexec()
847 shp->inpool = dtopen(&_Nvdisc,Dtset); in sh_coexec()
849 if(shp->poolfiles) in sh_coexec()
853 for(np=(Namval_t*)dtfirst(shp->inpool);np;np=(Namval_t*)dtnext(shp->inpool,np)) in sh_coexec()
860 dtclose(shp->inpool); in sh_coexec()
861 shp->inpool = 0; in sh_coexec()
862 shp->poolfiles = 0; in sh_coexec()
863 sh_unscope(shp); in sh_coexec()
864 shp->var_tree = top; in sh_coexec()
875 sfswap(shp->strbuf2,sfstdout); in sh_coexec()
876 str = sfstruse(shp->strbuf2); in sh_coexec()
880 cjp->local = shp->coshell; in sh_coexec()
884 sh_coaccept(shp,shp->inpipe,1); in sh_coexec()
885 sh_coaccept(shp,shp->outpipe,0); in sh_coexec()
888 shp->coutpipe = shp->inpipe[1]; in sh_coexec()
889 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; in sh_coexec()
899 static Sfio_t *openstream(Shell_t *shp, struct ionod *iop, int *save) in openstream() argument
901 int savein, fd = sh_redirect(shp,iop,3); in openstream()
909 shp->offsets[0] = -1; in openstream()
910 shp->offsets[1] = 0; in openstream()
917 static Namval_t *enter_namespace(Shell_t *shp, Namval_t *nsp) in enter_namespace() argument
919 Namval_t *path=nsp, *fpath=nsp, *onsp=shp->namespace; in enter_namespace()
926 else if(nv_dict(nsp)->view!=shp->var_base) in enter_namespace()
941 if(shp->var_tree==oroot) in enter_namespace()
943 shp->var_tree = shp->var_tree->view; in enter_namespace()
944 oroot = shp->var_base; in enter_namespace()
949 if(shp->var_tree==shp->var_base) in enter_namespace()
950 shp->var_tree = nv_dict(nsp); in enter_namespace()
953 for(root=shp->var_tree; root->view!=oroot;root=root->view); in enter_namespace()
957 shp->namespace = nsp; in enter_namespace()
958 if(path && (path = nv_search(PATHNOD->nvname,shp->var_tree,HASH_NOSCOPE)) && (val=nv_getval(path))) in enter_namespace()
960 …if(fpath && (fpath = nv_search(FPATHNOD->nvname,shp->var_tree,HASH_NOSCOPE)) && (val=nv_getval(fpa… in enter_namespace()
968 register Shell_t *shp = sh_getinterp(); in sh_exec() local
969 Stk_t *stkp = shp->stk; in sh_exec()
971 sh_sigcheck(shp); in sh_exec()
972 if(t && !shp->st.execbrk && !sh_isoption(SH_NOEXEC)) in sh_exec()
985 int topfd = shp->topfd; in sh_exec()
1011 if(!shp->intrap) in sh_exec()
1012 shp->oldexit=shp->exitval; in sh_exec()
1013 shp->exitval=0; in sh_exec()
1014 shp->lastsig = 0; in sh_exec()
1015 shp->lastpath = 0; in sh_exec()
1025 shp->bltindata.invariant = type>>(COMBITS+2); in sh_exec()
1028 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
1029 com = sh_argbuild(shp,&argn,&(t->com),OPTIMIZE); in sh_exec()
1035 sh_sigcheck(shp); in sh_exec()
1040 …if(np && shp->namespace && nq!=shp->namespace && nv_isattr(np,NV_BLTIN|NV_INTEGER|BLT_SPC)!=(NV_BL… in sh_exec()
1043 if(mp = sh_fsearch(shp,com[0],0)) in sh_exec()
1045 nq = shp->namespace; in sh_exec()
1051 shp->xargexit = 0; in sh_exec()
1054 register int n = b_command(0,com,&shp->bltindata); in sh_exec()
1061 np = nv_bfsearch(com0, shp->bltin_tree, &nq, &cp); in sh_exec()
1063 if(shp->xargexit) in sh_exec()
1065 shp->xargmin -= command; in sh_exec()
1066 shp->xargmax -= command; in sh_exec()
1069 shp->xargmin = 0; in sh_exec()
1072 if(argn && shp->inpool) in sh_exec()
1075 sh_redirect(shp,io,0); in sh_exec()
1082 sh_coaddfile(shp,*argv); in sh_exec()
1091 shp->coshell = sh_coinit(shp,com); in sh_exec()
1102 if(shp->namespace && (mp=sh_fsearch(shp,np->nvname,0))) in sh_exec()
1106 np = dtsearch(shp->fun_tree,np); in sh_exec()
1111 if(path_xattr(shp,np->nvname,(char*)0)) in sh_exec()
1113 dtdelete(shp->bltin_tree,np); in sh_exec()
1126 Dt_t *root = command?shp->bltin_tree:shp->fun_tree; in sh_exec()
1129 if(shp->namespace && !nq && !cp) in sh_exec()
1130 np = sh_fsearch(shp,com0,0); in sh_exec()
1136 if(shp->envlist = argp = t->com.comset) in sh_exec()
1155 if(!shp->st.var_local) in sh_exec()
1157 sh_scope(shp,(struct argnod*)0,0); in sh_exec()
1158 shp->st.var_local = shp->var_tree; in sh_exec()
1167 shp->typeinit = np; in sh_exec()
1182 if(shp->namespace) in sh_exec()
1184 if(!shp->strbuf2) in sh_exec()
1185 shp->strbuf2 = sfstropen(); in sh_exec()
1186 sfprintf(shp->strbuf2,"%s%s%c",NV_CLASS,nv_name(shp->namespace),0); in sh_exec()
1187 shp->prefix = strdup(sfstruse(shp->strbuf2)); in sh_exec()
1188 nv_open(shp->prefix,shp->var_base,NV_VARNAME); in sh_exec()
1192 shp->prefix = NV_CLASS; in sh_exec()
1197 if((shp->fn_depth && !shp->prefix) || np==SYSLOCAL) in sh_exec()
1211 if(np==shp->typeinit) in sh_exec()
1212 shp->typeinit = 0; in sh_exec()
1213 shp->envlist = argp; in sh_exec()
1217 last_table = shp->last_table; in sh_exec()
1218 shp->last_table = 0; in sh_exec()
1239 sh_trace(shp,com-command,tflags); in sh_exec()
1241 sh_redirect(shp,io,SH_SHOWME); in sh_exec()
1247 sh_trace(shp,com-command,tflags); in sh_exec()
1248 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
1250 int n = sh_debug(shp,trap,(char*)0,(char*)0, com, ARG_RAW); in sh_exec()
1251 if(n==255 && shp->fn_depth+shp->dot_depth) in sh_exec()
1264 sfsync(shp->outpool); in sh_exec()
1265 shp->lastpath = 0; in sh_exec()
1268 if(path_search(shp,com0,NIL(Pathcomp_t**),1)) in sh_exec()
1270 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
1272 if(!shp->namespace || !(np=sh_fsearch(shp,com0,0))) in sh_exec()
1274 np=nv_search(com0,shp->fun_tree,0); in sh_exec()
1277 Namval_t *mp=nv_search(com0,shp->bltin_tree,0); in sh_exec()
1284 if((np=nv_search(com0,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_exec()
1285 np=nv_search(nv_getval(np),shp->bltin_tree,0); in sh_exec()
1304 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1307 bp = &shp->bltindata; in sh_exec()
1326 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_exec()
1341 type = (execflg && !shp->subshell && !shp->st.trapcom[0]); in sh_exec()
1342 shp->redir0 = 1; in sh_exec()
1343 sh_redirect(shp,io,type); in sh_exec()
1349 if(!shp->pwd) in sh_exec()
1350 path_pwd(shp,0); in sh_exec()
1351 if(shp->pwd) in sh_exec()
1358 save_prompt = shp->nextprompt; in sh_exec()
1359 shp->nextprompt = 0; in sh_exec()
1364 sh_scope(shp,argp,0); in sh_exec()
1370 shp->exitval = 0; in sh_exec()
1371 shp->bltinfun = (Shbltin_f)funptr(np); in sh_exec()
1379 if(shp->subshell && nv_isattr(np,BLT_NOSFIO)) in sh_exec()
1380 sh_subtmpfile(shp); in sh_exec()
1381 if(execflg && !shp->subshell && in sh_exec()
1382 … !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && shp->fn_depth==0 && !nv_isattr(np,BLT_ENV)) in sh_exec()
1386 for(fd=0; fd < shp->gd->lim.open_max; fd++) in sh_exec()
1387 if((shp->fdstatus[fd]&IOCLEX)&&fd!=shp->infd) in sh_exec()
1391 shp->exitval = (*shp->bltinfun)(argn,com,(void*)bp); in sh_exec()
1394 ((Shnode_t*)t)->com.comstate = shp->bltindata.data; in sh_exec()
1396 if(sh.exitval && errno==EINTR && shp->lastsig) in sh_exec()
1397 sh.exitval = SH_EXITSIG|shp->lastsig; in sh_exec()
1398 else if(!nv_isattr(np,BLT_EXIT) && shp->exitval!=SH_RUNPROG) in sh_exec()
1399 shp->exitval &= SH_EXITMASK; in sh_exec()
1409 if(shp->gd->hist_ptr && item->strm == shp->gd->hist_ptr->histfp) in sh_exec()
1410 hist_close(shp->gd->hist_ptr); in sh_exec()
1415 if(shp->bltinfun && (error_info.flags&ERROR_NOTIFY)) in sh_exec()
1416 (*shp->bltinfun)(-2,com,(void*)bp); in sh_exec()
1431 if(shp->pwd) in sh_exec()
1437 chdir(shp->pwd); in sh_exec()
1443 sfpool(sfstderr,shp->outpool,SF_WRITE); in sh_exec()
1445 shp->nextprompt = save_prompt; in sh_exec()
1447 sh_popcontext(shp,buffp); in sh_exec()
1450 shp->bltinfun = 0; in sh_exec()
1460 sh_unscope(shp); in sh_exec()
1464 if((shp->topfd>topfd) && !(shp->subshell && np==SYSEXEC)) in sh_exec()
1465 sh_iorestore(shp,topfd,jmpval); in sh_exec()
1467 shp->redir0 = 0; in sh_exec()
1469 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1474 if(shp->exitval >=0) in sh_exec()
1484 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1495 indx = path_search(shp,com0,NIL(Pathcomp_t**),0); in sh_exec()
1499 if(shp->namespace) in sh_exec()
1500 np = sh_fsearch(shp,com0,0); in sh_exec()
1503 np = nv_search(com0,shp->fun_tree,HASH_NOSCOPE); in sh_exec()
1511 shp->exitval = ERROR_NOEXEC; in sh_exec()
1516 shp->exitval = ERROR_NOENT; in sh_exec()
1530 shp->last_table = last_table; in sh_exec()
1531 mode = set_instance(shp,nq,&node,&nr); in sh_exec()
1535 indx = shp->topfd; in sh_exec()
1536 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_exec()
1543 indx = sh_redirect(shp,io,execflg); in sh_exec()
1551 namespace = nv_search(np->nvname,shp->var_base,HASH_NOSCOPE); in sh_exec()
1555 namespace = enter_namespace(shp,namespace); in sh_exec()
1557 sh_funct(shp,np,argn,com,t->com.comset,(flags&~OPTIMIZE_FLAG)); in sh_exec()
1560 enter_namespace(shp,namespace); in sh_exec()
1566 sh_popcontext(shp,buffp); in sh_exec()
1567 sh_iorestore(shp,indx,jmpval); in sh_exec()
1574 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1591 if(shp->inpool) in sh_exec()
1597 if(shp->subshell) in sh_exec()
1599 sh_subtmpfile(shp); in sh_exec()
1600 if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK)) in sh_exec()
1601 unpipe=iousepipe(shp); in sh_exec()
1605 no_fork = !ntflag && !(type&(FAMP|FPOU)) && !shp->subshell && in sh_exec()
1606 !(shp->st.trapcom[SIGINT] && *shp->st.trapcom[SIGINT]) && in sh_exec()
1607 !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && in sh_exec()
1608 ((struct checkpt*)shp->jmplist)->mode!=SH_JMPEVAL && in sh_exec()
1609 (execflg2 || (execflg && shp->fn_depth==0 && in sh_exec()
1612 if(sh_isstate(SH_PROFILE) || shp->dot_depth) in sh_exec()
1639 restorefd = shp->topfd; in sh_exec()
1644 if(shp->coshell) in sh_exec()
1646 if(shp->cpipe[0]<0 || shp->cpipe[1] < 0) in sh_exec()
1648 sh_copipe(shp,shp->outpipe=shp->cpipe,0); in sh_exec()
1649 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; in sh_exec()
1651 sh_copipe(shp,shp->inpipe=pipes,0); in sh_exec()
1652 parent = sh_coexec(shp,t,3); in sh_exec()
1653 shp->cpid = parent; in sh_exec()
1654 jobid = job_post(shp,parent,0); in sh_exec()
1658 coproc_init(shp,pipes); in sh_exec()
1663 if(shp->coshell) in sh_exec()
1665 parent = sh_coexec(shp,t,0); in sh_exec()
1666 jobid = job_post(shp,parent,0); in sh_exec()
1673 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1675 parent = sh_fork(shp,type,&jobid); in sh_exec()
1678 if(shp->comsub==1 && usepipe && unpipe) in sh_exec()
1679 iounpipe(shp); in sh_exec()
1686 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1688 parent = sh_fork(shp,type,&jobid); in sh_exec()
1690 if((parent = sh_ntfork(shp,t,com,&jobid,ntflag))<=0) in sh_exec()
1695 if(shp->comsub==1 && usepipe && unpipe) in sh_exec()
1696 iounpipe(shp); in sh_exec()
1700 parent = sh_fork(shp,type,&jobid); in sh_exec()
1719 sh_close(shp->inpipe[0]); in sh_exec()
1721 shp->bckpid = parent; in sh_exec()
1726 if(!(shp->sigflag[SIGINT]&(SH_SIGFAULT|SH_SIGOFF))) in sh_exec()
1728 shp->trapnote |= SH_SIGIGNORE; in sh_exec()
1730 if(shp->pipepid) in sh_exec()
1731 shp->pipepid = parent; in sh_exec()
1734 if(shp->topfd > topfd) in sh_exec()
1735 sh_iorestore(shp,topfd,0); in sh_exec()
1737 iounpipe(shp); in sh_exec()
1740 shp->trapnote &= ~SH_SIGIGNORE; in sh_exec()
1741 if(shp->exitval == (SH_EXITSIG|SIGINT)) in sh_exec()
1752 sfprintf(sfstderr,"[%d]\t%s\n",jobid,sh_pid2str(shp,parent)); in sh_exec()
1769 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1774 sh_pushcontext(shp,buffp,SH_JMPEXIT); in sh_exec()
1783 if(!shp->st.ioset) in sh_exec()
1796 if(shp->fifo && (type&(FPIN|FPOU))) in sh_exec()
1799 void *fifo_timer=sh_timeradd(500,1,fifo_check,(void*)shp); in sh_exec()
1800 fn = sh_open(shp->fifo,fd?O_WRONLY:O_RDONLY); in sh_exec()
1802 sh_iorenumber(shp,fn,fd); in sh_exec()
1805 unlink(shp->fifo); in sh_exec()
1806 free(shp->fifo); in sh_exec()
1807 shp->fifo = 0; in sh_exec()
1814 if(shp->inpipe[2]>20000) in sh_exec()
1815 sh_coaccept(shp,shp->inpipe,0); in sh_exec()
1817 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1819 sh_close(shp->inpipe[1]); in sh_exec()
1824 if(shp->outpipe[2]>20000) in sh_exec()
1825 sh_coaccept(shp,shp->outpipe,1); in sh_exec()
1827 sh_iorenumber(shp,shp->outpipe[1],1); in sh_exec()
1828 sh_pclose(shp->outpipe); in sh_exec()
1831 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1832 if(shp->topfd) in sh_exec()
1833 sh_iounsave(shp); in sh_exec()
1834 topfd = shp->topfd; in sh_exec()
1843 sh_redirect(shp,t->tre.treio,1); in sh_exec()
1848 _sh_fork(shp,parent, 0, (int*)0); in sh_exec()
1852 job_post(shp,parent,0); in sh_exec()
1854 sh_iorestore(shp,topfd,SH_JMPCMD); in sh_exec()
1855 sh_done(shp,(shp->exitval&SH_EXITSIG)?(shp->exitval&SH_EXITMASK):0); in sh_exec()
1873 sh_freeup(shp); in sh_exec()
1874 path_exec(shp,com0,com,t->com.comset); in sh_exec()
1877 sh_popcontext(shp,buffp); in sh_exec()
1879 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1880 sh_done(shp,0); in sh_exec()
1893 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1895 if(shp->inpool) in sh_exec()
1897 sh_redirect(shp,t->fork.forkio,0); in sh_exec()
1902 if(shp->subshell) in sh_exec()
1904 sh_pushcontext(shp,buffp,SH_JMPIO); in sh_exec()
1909 sh_iosave(shp,0,shp->topfd,(char*)0); in sh_exec()
1910 shp->pipepid = simple; in sh_exec()
1911 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1923 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1927 if(shp->comsub==1) in sh_exec()
1929 sh_redirect(shp,t->fork.forkio,execflg); in sh_exec()
1934 sfsync(shp->outpool); in sh_exec()
1935 sh_popcontext(shp,buffp); in sh_exec()
1936 sh_iorestore(shp,buffp->topfd,jmpval); in sh_exec()
1942 type = shp->exitval; in sh_exec()
1946 if(shp->pipepid>1) in sh_exec()
1948 job_wait(shp->pipepid); in sh_exec()
1949 type = shp->exitval; in sh_exec()
1954 shp->exitval = type; in sh_exec()
1956 if(shp->comsub==1 && usepipe) in sh_exec()
1957 iounpipe(shp); in sh_exec()
1958 shp->pipepid = 0; in sh_exec()
1959 shp->st.ioset = 0; in sh_exec()
1967 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1973 if(shp->inpool) in sh_exec()
1981 …if(!shp->subshell && !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && (flags&sh_state(SH_NOFORK… in sh_exec()
1985 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1986 shp->st.otrapcom = 0; in sh_exec()
1987 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_exec()
1990 memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_exec()
1991 shp->st.otrapcom = (char**)savsig; in sh_exec()
1994 sh_pushcontext(shp,buffp,SH_JMPEXIT); in sh_exec()
1998 sh_popcontext(shp,buffp); in sh_exec()
2000 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2001 if(shp->exitval > 256) in sh_exec()
2002 shp->exitval -= 128; in sh_exec()
2003 sh_done(shp,0); in sh_exec()
2010 _sh_fork(shp,pid,0,0); in sh_exec()
2014 shp->st.trapcom[0]=0; in sh_exec()
2015 sh_done(shp,0); in sh_exec()
2019 sh_subshell(shp,t->par.partre,flags,0); in sh_exec()
2044 if(shp->inpool) in sh_exec()
2061 if(shp->subshell) in sh_exec()
2063 sh_subtmpfile(shp); in sh_exec()
2064 if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK)) in sh_exec()
2065 iousepipe(shp); in sh_exec()
2067 shp->inpipe = pvo; in sh_exec()
2068 shp->outpipe = pvn; in sh_exec()
2089 if(shp->coshell && !showme) in sh_exec()
2093 sh_copipe(shp,pvn,0); in sh_exec()
2094 type = sh_coexec(shp,t,1+copipe); in sh_exec()
2099 job_post(shp,type,0); in sh_exec()
2111 sh_copipe(shp,pvn,0); in sh_exec()
2136 shp->inpipe = pvn; in sh_exec()
2137 shp->outpipe = 0; in sh_exec()
2157 n = shp->exitval; in sh_exec()
2164 shp->intrap++; in sh_exec()
2166 shp->intrap--; in sh_exec()
2180 shp->exitval = n; in sh_exec()
2183 tcsetpgrp(JOBTTY,shp->gd->pid); in sh_exec()
2207 if(shp->inpool) in sh_exec()
2223 if(shp->inpool) in sh_exec()
2247 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
2248 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
2249 void *optlist = shp->optlist; in sh_exec()
2250 shp->optlist = 0; in sh_exec()
2252 sh_pushcontext(shp,buffp,jmpval); in sh_exec()
2257 error_info.line = t->for_.forline-shp->st.firstline; in sh_exec()
2260 args=shp->st.dolv+1; in sh_exec()
2261 nargs = shp->st.dolc; in sh_exec()
2262 argsav=sh_arguse(shp); in sh_exec()
2266 args=sh_argbuild(shp,&argn,tp,0); in sh_exec()
2269 np = nv_open(t->for_.fornam, shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOREF); in sh_exec()
2271 shp->st.loopcnt++; in sh_exec()
2273 while(cp && shp->st.execbrk==0) in sh_exec()
2285 save_prompt = shp->nextprompt; in sh_exec()
2286 shp->nextprompt = 3; in sh_exec()
2287 shp->timeout = 0; in sh_exec()
2288 shp->exitval=sh_readline(shp,&nullptr,0,1,(size_t)0,1000*shp->st.tmout); in sh_exec()
2289 shp->nextprompt = save_prompt; in sh_exec()
2290 if(shp->exitval||sfeof(sfstdin)||sferror(sfstdin)) in sh_exec()
2292 shp->exitval = 1; in sh_exec()
2295 if(!(val=nv_getval(sh_scoped(shp,REPLYNOD)))) in sh_exec()
2324 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2331 sh_debug(shp,trap,(char*)0,(char*)0,av,0); in sh_exec()
2334 if(shp->inpool) in sh_exec()
2336 poolfiles = shp->poolfiles; in sh_exec()
2338 if(poolfiles==shp->poolfiles) in sh_exec()
2346 if((cp=nv_getval(sh_scoped(shp,REPLYNOD))) && *cp==0) in sh_exec()
2352 if(shp->st.breakcnt<0) in sh_exec()
2353 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
2357 sh_popcontext(shp,buffp); in sh_exec()
2359 sh_optclear(shp,optlist); in sh_exec()
2361 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2363 if(shp->st.breakcnt>0) in sh_exec()
2364 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
2365 shp->st.loopcnt--; in sh_exec()
2366 sh_argfree(shp,argsav,0); in sh_exec()
2381 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
2382 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
2383 void *optlist = shp->optlist; in sh_exec()
2386 if(shp->inpool) in sh_exec()
2392 sh_redirect(shp,tt->com.comio,0); in sh_exec()
2401 poolfiles = shp->poolfiles; in sh_exec()
2406 while(poolfiles != shp->poolfiles); in sh_exec()
2411 shp->optlist = 0; in sh_exec()
2414 sh_pushcontext(shp,buffp,jmpval); in sh_exec()
2422 iop = openstream(shp,tt->com.comio,&savein); in sh_exec()
2427 shp->st.loopcnt++; in sh_exec()
2428 while(shp->st.execbrk==0) in sh_exec()
2433 if(!(shp->cur_line=sfgetr(iop,'\n',SF_STRING))) in sh_exec()
2441 if(shp->st.breakcnt<0) in sh_exec()
2442 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
2444 if(shp->st.execbrk==0 && t->wh.whinc) in sh_exec()
2449 shp->offsets[0] = -1; in sh_exec()
2450 shp->offsets[1] = 0; in sh_exec()
2455 sh_popcontext(shp,buffp); in sh_exec()
2458 sh_optclear(shp,optlist); in sh_exec()
2460 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2462 if(shp->st.breakcnt>0) in sh_exec()
2463 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
2464 shp->st.loopcnt--; in sh_exec()
2465 shp->exitval= r; in sh_exec()
2472 shp->cur_line = 0; in sh_exec()
2481 error_info.line = t->ar.arline-shp->st.firstline; in sh_exec()
2484 arg[1] = sh_macpat(shp,t->ar.arexpr,OPTIMIZE|ARG_ARITH); in sh_exec()
2489 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2490 sh_debug(shp,trap,(char*)0, (char*)0, arg, ARG_ARITH); in sh_exec()
2493 sh_trace(shp,NIL(char**),0); in sh_exec()
2497 shp->exitval = !arith_exec((Arith_t*)t->ar.arcomp); in sh_exec()
2499 shp->exitval = !sh_arith(shp,arg[1]); in sh_exec()
2505 if(shp->inpool) in sh_exec()
2518 shp->exitval=0; /* force zero exit for if-then-fi */ in sh_exec()
2524 char *trap, *r = sh_macpat(shp,tt->sw.swarg,OPTIMIZE); in sh_exec()
2525 error_info.line = t->sw.swline-shp->st.firstline; in sh_exec()
2527 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2534 sh_debug(shp,trap, (char*)0, (char*)0, av, 0); in sh_exec()
2540 if(shp->inpool) in sh_exec()
2551 s = sh_macpat(shp,rex,OPTIMIZE|ARG_EXP); in sh_exec()
2589 if(shp->inpool) in sh_exec()
2599 shp->exitval = !shp->exitval; in sh_exec()
2605 if(shp->subshell && shp->comsub==1) in sh_exec()
2632 at = shp->gd->lim.clk_tck*(ta.tv_sec-tb.tv_sec); in sh_exec()
2633 …at += ((shp->gd->lim.clk_tck*(((1000000L/2)/shp->gd->lim.clk_tck)+(ta.tv_usec-tb.tv_usec)))/10000… in sh_exec()
2640 Namval_t *np = nv_open("TIMEFORMAT",shp->var_tree,NV_NOADD); in sh_exec()
2656 p_time(shp,sfstderr,sh_translate(format),tm); in sh_exec()
2667 if(shp->inpool) in sh_exec()
2677 Namval_t *oldnspace = shp->namespace; in sh_exec()
2684 np = nv_open(stkptr(stkp,offset),shp->var_tree,flags); in sh_exec()
2693 dtview(root,shp->var_base); in sh_exec()
2695 oldnspace = enter_namespace(shp,np); in sh_exec()
2697 enter_namespace(shp,oldnspace); in sh_exec()
2702 error_info.line = t->funct.functline-shp->st.firstline; in sh_exec()
2704 if(cp || shp->prefix) in sh_exec()
2707 if(shp->prefix) in sh_exec()
2709 cp = shp->prefix; in sh_exec()
2710 shp->prefix = 0; in sh_exec()
2711 npv = nv_open(cp,shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2712 shp->prefix = cp; in sh_exec()
2719 npv = nv_open(stkptr(stkp,offset),shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2725 else if((mp=nv_search(fname,shp->bltin_tree,0)) && nv_isattr(mp,BLT_SPC)) in sh_exec()
2728 if(shp->namespace && !shp->prefix && *fname!='.') in sh_exec()
2729 np = sh_fsearch(shp,fname,NV_ADD|HASH_NOSCOPE); in sh_exec()
2735 if(!shp->mktype) in sh_exec()
2746 if(shp->funload) in sh_exec()
2754 shp->last_root = rp->sdict; in sh_exec()
2767 np->nvalue.rp = new_of(struct Ufunction,shp->funload?sizeof(Dtlink_t):0); in sh_exec()
2785 np->nvalue.rp->nspace = shp->namespace; in sh_exec()
2789 np->nvalue.rp->fdict = shp->fun_tree; in sh_exec()
2795 if(shp->funload) in sh_exec()
2799 if(!shp->fpathdict) in sh_exec()
2800 shp->fpathdict = dtopen(&_Rpdisc,Dtobag); in sh_exec()
2801 if(shp->fpathdict) in sh_exec()
2802 dtinsert(shp->fpathdict,rp); in sh_exec()
2825 if(shp->inpool) in sh_exec()
2830 error_info.line = t->tst.tstline-shp->st.firstline; in sh_exec()
2835 n = !shp->exitval; in sh_exec()
2844 left = sh_macpat(shp,&(t->lst.lstlef->arg),OPTIMIZE); in sh_exec()
2846 right = sh_macpat(shp,&(t->lst.lstrit->arg),((n==TEST_PEQ||n==TEST_PNE)?ARG_EXP:0)|OPTIMIZE); in sh_exec()
2847 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2851 traceon = sh_trace(shp,NIL(char**),0); in sh_exec()
2868 sh_debug(shp,trap,(char*)0,(char*)0,argv, 0); in sh_exec()
2870 n = test_unop(shp,n,left); in sh_exec()
2888 sh_debug(shp,trap,(char*)0,(char*)0,argv, pattern); in sh_exec()
2890 n = test_binop(shp,n,left,right); in sh_exec()
2903 shp->exitval = ((!n)^negate); in sh_exec()
2909 if(shp->trapnote || (shp->exitval && sh_isstate(SH_ERREXIT)) && in sh_exec()
2911 sh_chktrap(shp); in sh_exec()
2918 sh_done(shp,0); in sh_exec()
2919 if(shp->lastarg!= lastarg && shp->lastarg) in sh_exec()
2920 free(shp->lastarg); in sh_exec()
2924 shp->lastarg = strcpy(lastarg,comn); in sh_exec()
2929 shp->lastarg = strdup(comn); in sh_exec()
2935 if(!shp->inpool && !(OPTIMIZE)) in sh_exec()
2945 if(shp->trapnote&SH_SIGSET) in sh_exec()
2946 sh_exit(SH_EXITSIG|shp->lastsig); in sh_exec()
2954 return(shp->exitval); in sh_exec()
2959 Shell_t *shp = sh_getinterp(); in sh_run() local
2966 bltindata = shp->bltindata; in sh_run()
2975 t->comnamp = (void*)nv_bfsearch(argv[0],shp->fun_tree,(Namval_t**)&t->comnamq,(char**)0); in sh_run()
2978 shp->bltindata = bltindata; in sh_run()
3008 int sh_trace(Shell_t *shp,register char *argv[], register int nl) in sh_trace() argument
3018 if(!(cp=nv_getval(sh_scoped(shp,PS4NOD)))) in sh_trace()
3023 cp = sh_mactry(shp,cp); in sh_trace()
3042 if(decl && shp->prefix && cp!=argv0 && *cp!='-') in sh_trace()
3045 cp = shp->prefix; in sh_trace()
3047 sfputr(sfstderr,shp->prefix,'.'); in sh_trace()
3081 pid_t _sh_fork(Shell_t *shp,register pid_t parent,int flags,int *jobid) in _sh_fork() argument
3089 sh_sigcheck(shp); in _sh_fork()
3112 shp->gd->nforks++; in _sh_fork()
3136 shp->cpid = parent; in _sh_fork()
3142 myjob = job_post(shp,parent,postid); in _sh_fork()
3146 myjob = job_post(shp,parent,postid); in _sh_fork()
3159 if(shp->comsub==1 && usepipe) in _sh_fork()
3163 if(shp->topfd > restorefd) in _sh_fork()
3164 sh_iorestore(shp,restorefd,0); in _sh_fork()
3165 iounpipe(shp); in _sh_fork()
3173 shp->outpipepid = ((flags&FPOU)?getpid():0); in _sh_fork()
3175 if(shp->trapnote&SH_SIGTERM) in _sh_fork()
3177 shp->gd->nforks=0; in _sh_fork()
3205 shp->login_sh = 0; in _sh_fork()
3209 if (shp->fn_reset) in _sh_fork()
3210 shp->fn_depth = shp->fn_reset = 0; in _sh_fork()
3218 shp->subshell = 0; in _sh_fork()
3219 shp->comsub = 0; in _sh_fork()
3220 shp->spid = 0; in _sh_fork()
3221 if((flags&FAMP) && shp->coutpipe>1) in _sh_fork()
3222 sh_close(shp->coutpipe); in _sh_fork()
3223 sig = shp->savesig; in _sh_fork()
3224 shp->savesig = 0; in _sh_fork()
3227 sh_sigcheck(shp); in _sh_fork()
3232 pid_t sh_fork(Shell_t *shp,int flags, int *jobid) in sh_fork() argument
3236 if(!shp->pathlist) in sh_fork()
3237 path_get(shp,""); in sh_fork()
3239 shp->trapnote &= ~SH_SIGTERM; in sh_fork()
3241 shp->savesig = -1; in sh_fork()
3242 while(_sh_fork(shp,parent=fork(),flags,jobid) < 0); in sh_fork()
3244 if(!shp->subshell) in sh_fork()
3246 sig = shp->savesig; in sh_fork()
3247 shp->savesig = 0; in sh_fork()
3267 Shell_t *shp = ((struct Tdata*)data)->sh; in local_exports() local
3272 …if((cp = nv_getval(np)) && (mp = nv_search(nv_name(np), shp->var_tree, NV_ADD|HASH_NOSCOPE)) && nv… in local_exports()
3279 Sfdouble_t sh_mathfun(Shell_t *shp,void *fp, int nargs, Sfdouble_t *arg) in sh_mathfun() argument
3297 *nr++ = mp = nv_namptr(shp->mathnodes,i); in sh_mathfun()
3323 register Shell_t *shp = sh_getinterp(); in sh_funscope() local
3325 struct sh_scoped savst, *prevscope = shp->st.self; in sh_funscope()
3332 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_funscope()
3333 Namval_t *nspace = shp->namespace; in sh_funscope()
3334 Dt_t *last_root = shp->last_root; in sh_funscope()
3336 options = shp->options; in sh_funscope()
3337 if(shp->fn_depth==0) in sh_funscope()
3338 shp->glob_options = shp->options; in sh_funscope()
3340 shp->options = shp->glob_options; in sh_funscope()
3342 shp->st.lineno = error_info.line; in sh_funscope()
3344 *prevscope = shp->st; in sh_funscope()
3346 shp->st.prevst = prevscope; in sh_funscope()
3347 shp->st.self = &savst; in sh_funscope()
3348 shp->topscope = (Shscope_t*)shp->st.self; in sh_funscope()
3349 shp->st.opterror = shp->st.optchar = 0; in sh_funscope()
3350 shp->st.optindex = 1; in sh_funscope()
3351 shp->st.loopcnt = 0; in sh_funscope()
3355 shp->st.real_fun = (fp->node)->nvalue.rp; in sh_funscope()
3358 prevscope->save_tree = shp->var_tree; in sh_funscope()
3359 n = dtvnext(prevscope->save_tree)!= (shp->namespace?shp->var_base:0); in sh_funscope()
3360 sh_scope(shp,envlist,1); in sh_funscope()
3365 tdata.sh = shp; in sh_funscope()
3369 shp->st.save_tree = shp->var_tree; in sh_funscope()
3377 shp->st.cmdname = argv[0]; in sh_funscope()
3379 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_funscope()
3382 memcpy(savstak=stakalloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_funscope()
3385 argsav = sh_argnew(shp,argv,&saveargfor); in sh_funscope()
3386 sh_pushcontext(shp,buffp,SH_JMPFUN); in sh_funscope()
3389 shp->st.var_local = shp->var_tree; in sh_funscope()
3392 shp->st.filename = fp->node->nvalue.rp->fname; in sh_funscope()
3393 shp->st.funname = nv_name(fp->node); in sh_funscope()
3394 shp->last_root = nv_dict(DOTSHNOD); in sh_funscope()
3395 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funscope()
3396 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funscope()
3401 if(shp->fn_depth++ > MAXDEPTH) in sh_funscope()
3403 shp->toomany = 1; in sh_funscope()
3404 siglongjmp(*shp->jmplist,SH_JMPERRFN); in sh_funscope()
3410 char **arg = shp->st.real_fun->argv; in sh_funscope()
3414 shp->last_root = 0; in sh_funscope()
3417 np = nv_search(arg[r],shp->var_tree,HASH_NOSCOPE|NV_ADD); in sh_funscope()
3427 r = shp->exitval; in sh_funscope()
3430 if(shp->topscope != (Shscope_t*)shp->st.self) in sh_funscope()
3431 sh_setscope(shp->topscope); in sh_funscope()
3432 if(--shp->fn_depth==1 && jmpval==SH_JMPERRFN) in sh_funscope()
3434 sh_popcontext(shp,buffp); in sh_funscope()
3435 sh_unscope(shp); in sh_funscope()
3436 shp->namespace = nspace; in sh_funscope()
3437 shp->var_tree = (Dt_t*)prevscope->save_tree; in sh_funscope()
3438 sh_argreset(shp,argsav,saveargfor); in sh_funscope()
3439 trap = shp->st.trapcom[0]; in sh_funscope()
3440 shp->st.trapcom[0] = 0; in sh_funscope()
3442 shp->st = *prevscope; in sh_funscope()
3443 shp->topscope = (Shscope_t*)prevscope; in sh_funscope()
3444 nv_getval(sh_scoped(shp,IFSNOD)); in sh_funscope()
3446 memcpy((char*)&shp->st.trapcom[0],savstak,nsig); in sh_funscope()
3447 shp->trapnote=0; in sh_funscope()
3450 shp->options = options; in sh_funscope()
3451 shp->last_root = last_root; in sh_funscope()
3453 siglongjmp(*shp->jmplist,jmpval); in sh_funscope()
3460 r=shp->exitval; in sh_funscope()
3465 sh_chktrap(shp); in sh_funscope()
3466 siglongjmp(*shp->jmplist,jmpval); in sh_funscope()
3471 static void sh_funct(Shell_t *shp,Namval_t *np,int argn, char *argv[],struct argnod *envlist,int ex… in sh_funct() argument
3476 int level, pipepid=shp->pipepid, comsub=shp->comsub; in sh_funct()
3477 shp->comsub = 0; in sh_funct()
3478 shp->pipepid = 0; in sh_funct()
3481 lp = init_level(shp,0); in sh_funct()
3482 if((struct sh_scoped*)shp->topscope != shp->st.self) in sh_funct()
3483 sh_setscope(shp->topscope); in sh_funct()
3484 level = lp->maxlevel = shp->dot_depth + shp->fn_depth+1; in sh_funct()
3486 shp->st.lineno = error_info.line; in sh_funct()
3491 int loopcnt = shp->st.loopcnt; in sh_funct()
3492 shp->posix_fun = np; in sh_funct()
3495 shp->st.funname = nv_name(np); in sh_funct()
3496 shp->last_root = nv_dict(DOTSHNOD); in sh_funct()
3500 shp->st.loopcnt = 0; in sh_funct()
3501 b_dot_cmd(argn+1,argv-1,&shp->bltindata); in sh_funct()
3502 shp->st.loopcnt = loopcnt; in sh_funct()
3519 shp->last_root = nv_dict(DOTSHNOD); in sh_funct()
3520 shp->comsub = comsub; in sh_funct()
3522 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funct()
3526 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funct()
3527 shp->pipepid = pipepid; in sh_funct()
3538 Shell_t *shp = sh_getinterp(); in sh_fun() local
3544 char *prefix = shp->prefix; in sh_fun()
3551 shp->prefix = 0; in sh_fun()
3561 mode = set_instance(shp,nq,&node, &nr); in sh_fun()
3565 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_fun()
3566 Shbltin_t *bp = &shp->bltindata; in sh_fun()
3567 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_fun()
3577 shp->exitval = 0; in sh_fun()
3578 shp->exitval = ((Shbltin_f)funptr(np))(n,argv,bp); in sh_fun()
3580 sh_popcontext(shp,buffp); in sh_fun()
3582 siglongjmp(*shp->jmplist,jmpval); in sh_fun()
3585 sh_funct(shp,np,n,argv,(struct argnod*)0,sh_isstate(SH_ERREXIT)); in sh_fun()
3591 shp->prefix = prefix; in sh_fun()
3592 return(shp->exitval); in sh_fun()
3612 static void coproc_init(Shell_t *shp, int pipes[]) in coproc_init() argument
3615 if(shp->coutpipe>=0 && shp->cpid) in coproc_init()
3617 shp->cpid = 0; in coproc_init()
3618 if(shp->cpipe[0]<=0 || shp->cpipe[1]<=0) in coproc_init()
3621 sh_pclose(shp->cpipe); in coproc_init()
3622 sh_pipe(shp->cpipe); in coproc_init()
3623 if((outfd=shp->cpipe[1]) < 10) in coproc_init()
3625 int fd=fcntl(shp->cpipe[1],F_DUPFD,10); in coproc_init()
3628 shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); in coproc_init()
3630 shp->fdstatus[outfd] = IOCLOSE; in coproc_init()
3631 shp->cpipe[1] = fd; in coproc_init()
3634 if(fcntl(*shp->cpipe,F_SETFD,FD_CLOEXEC)>=0) in coproc_init()
3635 shp->fdstatus[shp->cpipe[0]] |= IOCLEX; in coproc_init()
3636 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; in coproc_init()
3638 if(fcntl(shp->cpipe[1],F_SETFD,FD_CLOEXEC) >=0) in coproc_init()
3639 shp->fdstatus[shp->cpipe[1]] |= IOCLEX; in coproc_init()
3641 shp->outpipe = shp->cpipe; in coproc_init()
3642 sh_pipe(shp->inpipe=pipes); in coproc_init()
3643 shp->coutpipe = shp->inpipe[1]; in coproc_init()
3644 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; in coproc_init()
3645 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) in coproc_init()
3646 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; in coproc_init()
3657 static int run_subshell(Shell_t *shp,const Shnode_t *t,pid_t grp) in run_subshell() argument
3667 arglist[0] = error_info.id?error_info.id:shp->shname; in run_subshell()
3678 nv_scan(shp->fun_tree, print_fun, (void*)0,0, 0); in run_subshell()
3679 if(shp->st.dolc>0) in run_subshell()
3682 char **argv = shp->st.dolv+1; in run_subshell()
3688 pin = (shp->inpipe?shp->inpipe[1]:0); in run_subshell()
3689 pout = (shp->outpipe?shp->outpipe[0]:0); in run_subshell()
3692 if(shp->fdstatus[i]&IOCLEX && i!=pin && i!=pout) in run_subshell()
3715 if(!shp->gd->shpath) in run_subshell()
3716 shp->gd->shpath = pathshell(); in run_subshell()
3717 pid = spawnveg(shp->shpath,arglist,envlist,grp); in run_subshell()
3721 if(shp->fdstatus[i]&IOCLEX && i!=pin && i!=pout) in run_subshell()
3730 static void sigreset(Shell_t *shp,int mode) in sigreset() argument
3733 register int sig=shp->st.trapmax; in sigreset()
3738 if((trap=shp->st.trapcom[sig]) && *trap==0) in sigreset()
3746 static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,int flag) in sh_ntfork() argument
3751 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_ntfork()
3793 if(!np && path && !nv_search(path,shp->fun_tree,0)) in sh_ntfork()
3797 sh_pushcontext(shp,buffp,SH_JMPIO); in sh_ntfork()
3804 if(!shp->st.ioset) in sh_ntfork()
3806 sh_iosave(shp,0,buffp->topfd,(char*)0); in sh_ntfork()
3807 sh_iorenumber(shp,sh_chkopen(e_devnull),0); in sh_ntfork()
3812 int fd = shp->inpipe[1]; in sh_ntfork()
3813 sh_iosave(shp,0,buffp->topfd,(char*)0); in sh_ntfork()
3814 sh_iorenumber(shp,shp->inpipe[0],0); in sh_ntfork()
3816 shp->fdstatus[fd] |= IOCLEX; in sh_ntfork()
3821 if(shp->outpipe[2] > 20000) in sh_ntfork()
3822 sh_coaccept(shp,shp->outpipe,1); in sh_ntfork()
3824 sh_iosave(shp,1,buffp->topfd,(char*)0); in sh_ntfork()
3825 sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1); in sh_ntfork()
3826 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) in sh_ntfork()
3827 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; in sh_ntfork()
3831 sh_redirect(shp,t->fork.forkio,0); in sh_ntfork()
3850 spawnpid = run_subshell(shp,t,grp); in sh_ntfork()
3859 sh_popcontext(shp,buffp); in sh_ntfork()
3865 …if((otype&FPIN) && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(shp->inpipe[1],F_SETFD,FD_CLOEXEC)>=0) in sh_ntfork()
3866 shp->fdstatus[shp->inpipe[1]] &= ~IOCLEX; in sh_ntfork()
3868 sh_iorestore(shp,buffp->topfd,jmpval); in sh_ntfork()
3879 _sh_fork(shp,spawnpid,otype,jobid); in sh_ntfork()
3888 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()
3891 sh_close(shp->coutpipe); in sh_ntfork()
3892 sh_close(shp->cpipe[1]); in sh_ntfork()
3893 shp->cpipe[1] = -1; in sh_ntfork()
3894 shp->coutpipe = -1; in sh_ntfork()
3896 shp->exitval = 0; in sh_ntfork()
3900 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_ntfork()
3912 sh_redirect(shp,t->com.comio,0); in sh_ntfork()
3917 sh_scope(shp,t->com.comset,0); in sh_ntfork()
3922 if((np=nv_search(path,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_ntfork()
3924 else if(path_absolute(shp,path,NIL(Pathcomp_t*))) in sh_ntfork()
3926 path = stkptr(shp->stk,PATH_OFFSET); in sh_ntfork()
3927 stkfreeze(shp->stk,0); in sh_ntfork()
3931 pp=path_get(shp,path); in sh_ntfork()
3950 shp->exitval = 0; in sh_ntfork()
3970 sigreset(shp,0); /* set signals to ignore */ in sh_ntfork()
3973 for(pp=path_get(shp,argv[0]); pp && !pp->lib ; pp=pp->next); in sh_ntfork()
3976 spawnpid = path_spawn(shp,path,argv,arge,pp,(grp<<1)|1); in sh_ntfork()
3986 sfprintf(shp->strbuf,"/dev/fd/%d",fd); in sh_ntfork()
3987 if(stat(devfd=sfstruse(shp->strbuf),&statb)>=0) in sh_ntfork()
3990 if(!shp->gd->shpath) in sh_ntfork()
3991 shp->gd->shpath = pathshell(); in sh_ntfork()
3992 spawnpid = path_spawn(shp,shp->gd->shpath,&argv[-1],arge,pp,(grp<<1)|1); in sh_ntfork()
4000 if(spawnpid < 0) switch(errno=shp->path_err) in sh_ntfork()
4010 sh_popcontext(shp,buffp); in sh_ntfork()
4021 sigreset(shp,1); /* restore ignored signals */ in sh_ntfork()
4024 sh_unscope(shp); in sh_ntfork()
4029 sh_iorestore(shp,buffp->topfd,jmpval); in sh_ntfork()
4031 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()
4034 _sh_fork(shp,spawnpid,otype,jobid); in sh_ntfork()