void dotrap(void) { Var *trapreq; Word *starval; while(refdec(&ntrap) >= 0) { if(flag['S']) exits(truestatus()?"":getstatus()); starval=vlook("*")->val; trapreq=vlook("sysint"); if(trapreq->fn){ start(trapreq->fn, trapreq->pc, (Var*)0); runq->local=newvar(strdup("*"), runq->local); runq->local->val=copywords(starval, (Word*)0); runq->local->changed=1; runq->redir=runq->startredir=0; } else { /* * run the stack down until we uncover the * command reading loop. Xreturn will exit * if there is none (i.e. if this is not * an interactive rc.) */ while(!runq->iflag) Xreturn(); } } }
void dotrap(void) { int i; struct var *trapreq; struct word *starval; starval = vlook("*")->val; while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){ --trap[i]; --ntrap; if(getpid()!=mypid) Exit(getstatus()); trapreq = vlook(Signame[i]); if(trapreq->fn){ start(trapreq->fn, trapreq->pc, (struct var *)0); runq->local = newvar(strdup("*"), runq->local); runq->local->val = copywords(starval, (struct word *)0); runq->local->changed = 1; runq->redir = runq->startredir = 0; } else if(i==SIGINT || i==SIGQUIT){ /* * run the stack down until we uncover the * command reading loop. Xreturn will exit * if there is none (i.e. if this is not * an interactive rc.) */ while(!runq->iflag) Xreturn(); } else Exit(getstatus()); } }
void Xrdfn(void) { int f, len; Dir *e; char envname[Maxenvname]; static Dir *ent, *allocent; static int nent; for(;;){ if(nent == 0){ free(allocent); nent = dirread(envdir, &allocent); ent = allocent; } if(nent <= 0) break; while(nent){ e = ent++; nent--; len = e->length; if(len && strncmp(e->name, "fn#", 3)==0){ snprint(envname, sizeof envname, "/env/%s", e->name); if((f = open(envname, 0))>=0){ execcmds(openfd(f)); return; } } } } close(envdir); Xreturn(); }
void Xerror1(char *s) { if(strcmp(argv0, "rc")==0 || strcmp(argv0, "/bin/rc")==0) pfmt(err, "rc: %s\n", s); else pfmt(err, "rc (%s): %s\n", argv0, s); flush(err); setstatus("error"); while(!runq->iflag) Xreturn(); }
void Xrdcmds(void) { struct thread *p = runq; word *prompt; flush(err); nerror = 0; if(flag['s'] && !truestatus()) pfmt(err, "status=%v\n", vlook("status")->val); if(runq->iflag){ prompt = vlook("prompt")->val; if(prompt) promptstr = prompt->word; else promptstr="% "; } Noerror(); if(yyparse()){ if(!p->iflag || p->eof && !Eintr()){ if(p->cmdfile) efree(p->cmdfile); closeio(p->cmdfd); Xreturn(); /* should this be omitted? */ } else{ if(Eintr()){ pchr(err, '\n'); p->eof = 0; } --p->pc; /* go back for next command */ } } else{ ntrap = 0; /* avoid double-interrupts during blocked writes */ --p->pc; /* re-execute Xrdcmds after codebuf runs */ start(codebuf, 1, runq->local); } freenodes(); }