extern void funcall(char **av) { Jbwrap j; Edata jreturn, star; Estack e1, e2; if (sigsetjmp(j.j, 1)) return; starassign(*av, av+1, TRUE); jreturn.jb = &j; star.name = "*"; except(eReturn, jreturn, &e1); except(eVarstack, star, &e2); walk(treecpy(fnlookup(*av), nalloc), TRUE); varrm("*", TRUE); unexcept(eVarstack); unexcept(eReturn); }
extern void exec(List *s, bool parent) { char **av, **ev = NULL; int pid, stat; builtin_t *b; char *path = NULL; bool didfork, returning, saw_exec, saw_builtin; av = list2array(s, dashex); saw_builtin = saw_exec = FALSE; do { if (*av == NULL || isabsolute(*av)) b = NULL; else if (!saw_builtin && fnlookup(*av) != NULL) b = funcall; else b = isbuiltin(*av); /* a builtin applies only to the immmediately following command, e.g., builtin exec echo hi */ saw_builtin = FALSE; if (b == b_exec) { av++; saw_exec = TRUE; parent = FALSE; } else if (b == b_builtin) { av++; saw_builtin = TRUE; } } while (b == b_exec || b == b_builtin); if (*av == NULL && saw_exec) { /* do redirs and return on a null exec */ doredirs(); return; } /* force an exit on exec with any rc_error, but not for null commands as above */ if (saw_exec) rc_pid = -1; if (b == NULL) { path = which(*av, TRUE); if (path == NULL && *av != NULL) { /* perform null commands for redirections */ set(FALSE); redirq = NULL; if (parent) return; rc_exit(1); } ev = makeenv(); /* environment only needs to be built for execve() */ } /* If parent & the redirq is nonnull, builtin or not it has to fork. If the fifoq is nonnull, then it must be emptied at the end so we must fork no matter what. */ if ((parent && (b == NULL || redirq != NULL)) || outstanding_cmdarg()) { pid = rc_fork(); didfork = TRUE; } else { pid = 0; didfork = FALSE; } returning = (!didfork && parent); switch (pid) { case -1: uerror("fork"); rc_error(NULL); /* NOTREACHED */ case 0: if (!returning) setsigdefaults(FALSE); pop_cmdarg(FALSE); doredirs(); /* null commands performed for redirections */ if (*av == NULL || b != NULL) { if (b != NULL) (*b)(av); if (returning) return; rc_exit(getstatus()); } execve(path, (char * const *) av, (char * const *) ev); uerror(*av); rc_exit(1); /* NOTREACHED */ default: redirq = NULL; rc_wait4(pid, &stat, TRUE); setstatus(-1, stat); if ((stat & 0xff) == 0) nl_on_intr = FALSE; SIGCHK; nl_on_intr = TRUE; pop_cmdarg(TRUE); } }
static void b_whatis(char **av) { bool ess, eff, vee, pee, bee; bool f, found; int i, ac, c; List *s; Node *n; char *e; for (rc_optind = ac = 0; av[ac] != NULL; ac++) ; /* count the arguments for getopt */ ess = eff = vee = pee = bee = FALSE; while ((c = rc_getopt(ac, av, "sfvpb")) != -1) switch (c) { default: set(FALSE); return; case 's': ess = TRUE; break; case 'f': eff = TRUE; break; case 'v': vee = TRUE; break; case 'p': pee = TRUE; break; case 'b': bee = TRUE; break; } av += rc_optind; if (*av == NULL) { if (vee|eff) whatare_all_vars(eff, vee); if (ess) whatare_all_signals(); if (bee) for (i = 0; i < arraysize(builtins); i++) fprint(1, "builtin %s\n", builtins[i].name); if (pee) fprint(2, "whatis -p: must specify argument\n"); if (show(FALSE)) /* no options? */ whatare_all_vars(TRUE, TRUE); set(TRUE); return; } found = TRUE; for (i = 0; av[i] != NULL; i++) { f = FALSE; errno = ENOENT; if (show(vee) && (s = varlookup(av[i])) != NULL) { f = TRUE; prettyprint_var(1, av[i], s); } if (((show(ess)&&issig(av[i])) || show(eff)) && (n = fnlookup(av[i])) != NULL) { f = TRUE; prettyprint_fn(1, av[i], n); } else if (show(bee) && isbuiltin(av[i]) != NULL) { f = TRUE; fprint(1, "builtin %s\n", av[i]); } else if (show(pee) && (e = which(av[i], FALSE)) != NULL) { f = TRUE; fprint(1, "%S\n", e); } if (!f) { found = FALSE; if (errno != ENOENT) uerror(av[i]); else fprint(2, "%s not found\n", av[i]); } } set(found); }