/* * Make a pass through the printcap database and start printing any * files left from the last time the machine went down. */ static void startup(void) { int pid, status, more; struct printer myprinter, *pp = &myprinter; more = firstprinter(pp, &status); if (status) goto errloop; while (more) { if (ckqueue(pp) <= 0) { goto next; } if (lflag) syslog(LOG_INFO, "lpd startup: work for %s", pp->printer); if ((pid = fork()) < 0) { syslog(LOG_WARNING, "lpd startup: cannot fork for %s", pp->printer); mcleanup(0); } if (pid == 0) { lastprinter(); printjob(pp); /* NOTREACHED */ } do { next: more = nextprinter(pp, &status); errloop: if (status) syslog(LOG_WARNING, "lpd startup: printcap entry for %s has errors, skipping", pp->printer ? pp->printer : "<noname?>"); } while (more && status); } }
int main(int argc, char **argv) { int ch, aflag, lflag; const char *printer; struct printer myprinter, *pp = &myprinter; printer = NULL; euid = geteuid(); uid = getuid(); seteuid(uid); progname = *argv; if (gethostname(local_host, sizeof(local_host))) err(1, "gethostname"); openlog("lpd", 0, LOG_LPR); aflag = lflag = 0; while ((ch = getopt(argc, argv, "alP:")) != -1) switch((char)ch) { case 'a': ++aflag; break; case 'l': /* long output */ ++lflag; break; case 'P': /* printer name */ printer = optarg; break; case '?': default: usage(); } if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; for (argc -= optind, argv += optind; argc; --argc, ++argv) if (isdigit(argv[0][0])) { if (requests >= MAXREQUESTS) fatal(0, "too many requests"); requ[requests++] = atoi(*argv); } else { if (users >= MAXUSERS) fatal(0, "too many users"); user[users++] = *argv; } if (aflag) { int more, status; more = firstprinter(pp, &status); if (status) goto looperr; while (more) { if (ckqueue(pp) > 0) { printf("%s:\n", pp->printer); displayq(pp, lflag); printf("\n"); } do { more = nextprinter(pp, &status); looperr: switch (status) { case PCAPERR_TCOPEN: printf("warning: %s: unresolved " "tc= reference(s) ", pp->printer); case PCAPERR_SUCCESS: break; default: fatal(pp, "%s", pcaperr(status)); } } while (more && status); } } else { int status; init_printer(pp); status = getprintcap(printer, pp); if (status < 0) fatal(pp, "%s", pcaperr(status)); displayq(pp, lflag); } exit(0); }
int main(int argc, char **argv) { int ch, aflag, lflag; char *buf, *cp; long l; effective_uid = geteuid(); real_uid = getuid(); effective_gid = getegid(); real_gid = getgid(); PRIV_END; /* be safe */ if (gethostname(host, sizeof(host)) != 0) err(1, "gethostname"); openlog("lpq", 0, LOG_LPR); aflag = lflag = 0; while ((ch = getopt(argc, argv, "alP:w:")) != -1) { switch(ch) { case 'a': ++aflag; break; case 'l': /* long output */ ++lflag; break; case 'P': /* printer name */ printer = optarg; break; case 'w': l = strtol(optarg, &cp, 10); if (*cp != '\0' || l < 0 || l >= INT_MAX) errx(1, "wait time must be postive integer: %s", optarg); wait_time = (u_int)l; if (wait_time < 30) warnx("warning: wait time less than 30 seconds"); break; case '?': default: usage(); } } if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; for (argc -= optind, argv += optind; argc; --argc, ++argv) if (isdigit((unsigned char)argv[0][0])) { if (requests >= MAXREQUESTS) fatal("too many requests"); requ[requests++] = atoi(*argv); } else { if (users >= MAXUSERS) fatal("too many users"); user[users++] = *argv; } if (aflag) { while (cgetnext(&buf, printcapdb) > 0) { if (ckqueue(buf) <= 0) { free(buf); continue; /* no jobs */ } for (cp = buf; *cp; cp++) if (*cp == '|' || *cp == ':') { *cp = '\0'; break; } printer = buf; printf("%s:\n", printer); displayq(lflag); free(buf); printf("\n"); } } else displayq(lflag); exit(0); }