void mk(char *target) { Node *node; int did = 0; nproc(); /* it can be updated dynamically */ nrep(); /* it can be updated dynamically */ runerrs = 0; node = graph(target); if(DEBUG(D_GRAPH)){ dumpn("new target\n", node); Bflush(&bout); } clrmade(node); while(node->flags&NOTMADE){ if(work(node, (Node *)0, (Arc *)0)) did = 1; /* found something to do */ else { if(waitup(1, (int *)0) > 0){ if(node->flags&(NOTMADE|BEINGMADE)){ assert(/*must be run errors*/ runerrs); break; /* nothing more waiting */ } } } } if(node->flags&BEINGMADE) waitup(-1, (int *)0); while(jobs) waitup(-2, (int *)0); assert(/*target didnt get done*/ runerrs || (node->flags&MADE)); if(did == 0) Bprint(&bout, "mk: '%s' is up to date\n", node->name); }
static int checkmouse(void) /* return button touched if any */ { int c, b; char *p; extern int confirm(int); b = waitdown(); last_but = 0; last_hit = -1; c = 0; if (button3(b)) { last_hit = emenuhit(3, &mouse, &mbut3); last_but = 3; } else if (button2(b)) { last_hit = emenuhit(2, &mouse, &mbut2); last_but = 2; } else { /* button1() */ pan(); last_but = 1; } waitup(); if (last_but == 3 && last_hit >= 0) { p = m3[last_hit]; c = p[strlen(p) - 1]; } if (c == '?' && !confirm(last_but)) last_hit = -1; return last_but; }
int confirm(int but) /* ask for confirmation if menu item ends with '?' */ { int c; static int but_cvt[8] = { 0, 1, 2, 0, 3, 0, 0, 0 }; esetcursor(&skull); c = waitdown(); waitup(); esetcursor(0); return but == but_cvt[c]; }
/* * Do a specific command for a specific host */ static void docmdhost(struct cmd *cmd, char **filev) { checkcmd(cmd); /* * If we're multi-threaded and we're the parent, spawn a * new child process. */ if (do_fork && !amchild) { pid_t pid; /* * If we're at maxchildren, wait for number of active * children to fall below max number of children. */ while (activechildren >= maxchildren) waitup(); pid = spawn(cmd, cmds); if (pid == 0) /* Child */ amchild = 1; else /* Parent */ return; } /* * Disable NFS checks */ if (cmd->c_flags & CMD_NOCHKNFS) FLAG_OFF(options, DO_CHKNFS); if (!nflag) { currenthost = (cmd->c_name) ? cmd->c_name : "<unknown>"; #if defined(SETARGS) || defined(HAVE_SETPROCTITLE) setproctitle("update %s", currenthost); #endif /* SETARGS || HAVE_SETPROCTITLE */ } switch (cmd->c_type) { case ARROW: doarrow(cmd, filev); break; case DCOLON: dodcolon(cmd, filev); break; default: fatalerr("illegal command type %d", cmd->c_type); } }
static pcmp(char *prog, char *p, char *q) { char buf[3*NAMEBLOCK]; int pid; Bflush(&bout); snprint(buf, sizeof buf, "%s '%s' '%s'\n", prog, p, q); pid = pipecmd(buf, 0, 0); while(waitup(-3, &pid) >= 0) ; return(pid? 2:1); }
void killchildren(char *msg) { Process *p; kflag = 1; /* to make sure waitup doesn't exit */ jobs = 0; /* make sure no more get scheduled */ for(p = phead; p; p = p->f) expunge(p->pid, msg); while(waitup(1, (int *)0) == 0) ; Bprint(&bout, "mk: %s\n", msg); Exit(); }
/* * Do the commands in cmds (initialized by yyparse). */ void docmds(struct namelist *hostlist, int argc, char **argv) { struct cmd *c; char *cp; int i; (void) signal(SIGHUP, sighandler); (void) signal(SIGINT, sighandler); (void) signal(SIGQUIT, sighandler); (void) signal(SIGTERM, sighandler); if (!nflag) mysetlinebuf(stdout); /* Make output (mostly) clean */ #if defined(USE_STATDB) if (!nflag && (dostatdb || juststatdb)) { extern long reccount; message(MT_INFO, "Making stat database [%s] ... \n", gettimestr()); if (mkstatdb() < 0) error("Warning: Make stat database failed."); message(MT_INFO, "Stat database created: %d files stored [%s].\n", reccount, gettimestr()); if (juststatdb) return; } #endif /* USE_STATDB */ /* * Print errors for any command line targets we didn't find. * If any errors are found, return to main() which will then exit. */ for (i = 0; i < argc; i++) { int found; for (found = FALSE, c = cmds; c != NULL; c = c->c_next) { if (c->c_label && argv[i] && strcmp(c->c_label, argv[i]) == 0) { found = TRUE; break; } } if (!found) error("Label \"%s\" is not defined in the distfile.", argv[i]); } if (nerrs) return; /* * Main command loop. Loop through all the commands. */ for (c = cmds; c != NULL; c = c->c_next) { checkcmd(c); if (do_fork) { /* * Let the children take care of their assigned host */ if (amchild) { if (strcmp(c->c_name, currenthost) != 0) continue; } else if (c->c_flags & CMD_ASSIGNED) { /* This cmd has been previously assigned */ debugmsg(DM_MISC, "prev assigned: %s\n", c->c_name); continue; } } if (hostlist) { /* Do specific hosts as specified on command line */ struct namelist *nlptr; for (nlptr = hostlist; nlptr; nlptr = nlptr->n_next) /* * Try an exact match and then a match * without '@' (if present). */ if ((strcmp(c->c_name, nlptr->n_name) == 0) || ((cp = strchr(c->c_name, '@')) && strcmp(++cp, nlptr->n_name) == 0)) docmd(c, argc, argv); continue; } else /* Do all of the command */ docmd(c, argc, argv); } if (do_fork) { /* * We're multi-threaded, so do appropriate shutdown * actions based on whether we're the parent or a child. */ if (amchild) { if (!IS_ON(options, DO_QUIET)) message(MT_VERBOSE, "updating of %s finished", currenthost); closeconn(); cleanup(0); exit(nerrs); } /* * Wait for all remaining active children to finish */ while (activechildren > 0) { debugmsg(DM_MISC, "Waiting for %d children to finish.\n", activechildren); waitup(); } } else if (!nflag) { /* * We're single-threaded so close down current connection */ closeconn(); cleanup(0); } }
void parse(char *f, int fd, int varoverride) { int hline; char *body; Word *head, *tail; int attr, set, pid; char *prog, *p; int newfd; Biobuf in; Bufblock *buf; if(fd < 0) { perror(f); Exit(); } ipush(); infile = strdup(f); mkinline = 1; Binit(&in, fd, OREAD); buf = newbuf(); while(assline(&in, buf)) { hline = mkinline; switch(rhead(buf->start, &head, &tail, &attr, &prog)) { case '<': p = wtos(tail, ' '); if(*p == 0) { SYNERR(-1); fprint(2, "missing include file name\n"); Exit(); } newfd = open(p, OREAD); if(newfd < 0) { fprint(2, "warning: skipping missing include file: "); perror(p); } else parse(p, newfd, 0); break; case '|': p = wtos(tail, ' '); if(*p == 0) { SYNERR(-1); fprint(2, "missing include program name\n"); Exit(); } execinit(); pid=pipecmd(p, envy, &newfd); if(newfd < 0) { fprint(2, "warning: skipping missing program file: "); perror(p); } else parse(p, newfd, 0); while(waitup(-3, &pid) >= 0) ; if(pid != 0) { fprint(2, "bad include program status\n"); Exit(); } break; case ':': body = rbody(&in); addrules(head, tail, body, attr, hline, prog); break; case '=': if(head->next) { SYNERR(-1); fprint(2, "multiple vars on left side of assignment\n"); Exit(); } if(symlook(head->s, S_OVERRIDE, 0)) { set = varoverride; } else { set = 1; if(varoverride) symlook(head->s, S_OVERRIDE, (void *)""); } if(set) { /* char *cp; dumpw("tail", tail); cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp); */ setvar(head->s, (void *) tail); symlook(head->s, S_WESET, (void *)""); } if(attr) symlook(head->s, S_NOEXPORT, (void *)""); break; default: SYNERR(hline); fprint(2, "expected one of :<=\n"); Exit(); break; } } close(fd); freebuf(buf); ipop(); }