static void hrPrinter_get_OS_entries(void) { int status, more; struct printer myprinter, *pp = &myprinter; init_printer(pp); HRDBG("---->Getting printers ....."); more = firstprinter(pp, &status); if (status) goto errloop; while (more) { do { HRDBG("---->Got printer %s", pp->printer); handle_printer(pp); more = nextprinter(pp, &status); errloop: if (status) syslog(LOG_WARNING, "hrPrinterTable: printcap entry for %s " "has errors, skipping", pp->printer ? pp->printer : "<noname?>"); } while (more && status); } lastprinter(); printer_tick = this_tick; }
/* * 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); }
void generic(void (*specificrtn)(struct printer *_pp), int cmdopts, void (*initrtn)(int _argc, char *_argv[]), int argc, char *argv[]) { int cmdstatus, more, targc; struct printer myprinter, *pp; char **margv, **targv; if (argc == 1) { /* * Usage needs a special case for 'down': The user must * either include `-msg', or only the first parameter * that they give will be processed as a printer name. */ printf("usage: %s {all | printer ...}", argv[0]); if (strcmp(argv[0], "down") == 0) { printf(" -msg [<text> ...]\n"); printf(" or: down {all | printer} [<text> ...]"); } else if (cmdopts & LPC_MSGOPT) printf(" [-msg <text> ...]"); printf("\n"); return; } /* The first argument is the command name. */ generic_cmdname = *argv++; argc--; /* * The initialization routine for a command might set a generic * "wrapup" routine, which should be called after processing all * the printers in the command. This might print summary info. * * Note that the initialization routine may also parse (and * nullify) some of the parameters given on the command, leaving * only the parameters which have to do with printer names. */ pp = &myprinter; generic_wrapup = NULL; generic_qselect = QSEL_UNKNOWN; cmdstatus = 0; /* this just needs to be a distinct value of type 'char *' */ if (generic_nullarg == NULL) generic_nullarg = strdup(""); /* * Some commands accept a -msg argument, which indicates that * all remaining arguments should be combined into a string. */ generic_msg = NULL; if (cmdopts & LPC_MSGOPT) { targc = argc; targv = argv; for (; targc > 0; targc--, targv++) { if (strcmp(*targv, "-msg") == 0) { argc -= targc; generic_msg = args2line(targc - 1, targv + 1); break; } } } /* call initialization routine, if there is one for this cmd */ if (initrtn != NULL) { generic_initerr = 0; (*initrtn)(argc, argv); if (generic_initerr) return; /* * The initrtn may have null'ed out some of the parameters. * Compact the parameter list to remove those nulls, and * correct the arg-count. */ targc = argc; targv = argv; margv = argv; argc = 0; for (; targc > 0; targc--, targv++) { if (*targv != generic_nullarg) { if (targv != margv) *margv = *targv; margv++; argc++; } } } if (argc == 1 && strcmp(*argv, "all") == 0) { generic_qselect = QSEL_ALL; more = firstprinter(pp, &cmdstatus); if (cmdstatus) goto looperr; while (more) { (*specificrtn)(pp); do { more = nextprinter(pp, &cmdstatus); looperr: switch (cmdstatus) { case PCAPERR_TCOPEN: printf("warning: %s: unresolved " "tc= reference(s) ", pp->printer); case PCAPERR_SUCCESS: break; default: fatal(pp, "%s", pcaperr(cmdstatus)); } } while (more && cmdstatus); } goto wrapup; } generic_qselect = QSEL_BYNAME; /* specifically-named ptrs */ for (; argc > 0; argc--, argv++) { init_printer(pp); cmdstatus = getprintcap(*argv, pp); switch (cmdstatus) { default: fatal(pp, "%s", pcaperr(cmdstatus)); case PCAPERR_NOTFOUND: printf("unknown printer %s\n", *argv); continue; case PCAPERR_TCOPEN: printf("warning: %s: unresolved tc= reference(s)\n", *argv); break; case PCAPERR_SUCCESS: break; } (*specificrtn)(pp); } wrapup: if (generic_wrapup) { (*generic_wrapup)(cmdstatus); } free_printer(pp); if (generic_msg) free(generic_msg); }