summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr/lpq
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1997-12-02 20:46:22 +0000
committerwollman <wollman@FreeBSD.org>1997-12-02 20:46:22 +0000
commitbf21e6b4e0e85ae08cb5d1f2335da248f52e2d26 (patch)
tree041fd28f30eaadf848820e6ceed6899636d31478 /usr.sbin/lpr/lpq
parentfa82bf4e17d3b6422eb922374e04631e08af93ef (diff)
downloadFreeBSD-src-bf21e6b4e0e85ae08cb5d1f2335da248f52e2d26.zip
FreeBSD-src-bf21e6b4e0e85ae08cb5d1f2335da248f52e2d26.tar.gz
Mega lpd/lpd upgrade, part I:
- Get rid of a lot of the static variables which were shared by many routines and programs in the suite. - Create an abstract interface to the printcap database, so that other retrieval and iteration mechanisms could be developed (e.g., YP, Hesiod, or automatic retrieval from a trusted server). - Give each capability a human-readable name in addition to the historic two-character one. - Otherwise generally clean up a lot of dark corners. Many still remain. - When submitting jobs, use the official login name record (from getlogin()) if there is one, rather than reverse-mapping the uid. More to come...
Diffstat (limited to 'usr.sbin/lpr/lpq')
-rw-r--r--usr.sbin/lpr/lpq/Makefile9
-rw-r--r--usr.sbin/lpr/lpq/lpq.c87
2 files changed, 60 insertions, 36 deletions
diff --git a/usr.sbin/lpr/lpq/Makefile b/usr.sbin/lpr/lpq/Makefile
index 0240b57..c0938ed 100644
--- a/usr.sbin/lpr/lpq/Makefile
+++ b/usr.sbin/lpr/lpq/Makefile
@@ -1,13 +1,14 @@
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
+# From: @(#)Makefile 8.1 (Berkeley) 6/6/93
+# $Id$
PROG= lpq
-CFLAGS+=-I${.CURDIR}/../common_source
-SRCS= lpq.c displayq.c common.c
+CFLAGS+=-I${.CURDIR}/../common_source ${CWARNFLAGS}
+SRCS= lpq.c
BINOWN= root
BINGRP= daemon
BINMODE=6555
BINDIR= /usr/bin
MAN1= lpq.1
-.PATH: ${.CURDIR}/../common_source
+LDADD= -L${.OBJDIR}/../common_source -llpr
.include <bsd.prog.mk>
diff --git a/usr.sbin/lpr/lpq/lpq.c b/usr.sbin/lpr/lpq/lpq.c
index 9dc9c8a..81151a2 100644
--- a/usr.sbin/lpr/lpq/lpq.c
+++ b/usr.sbin/lpr/lpq/lpq.c
@@ -33,13 +33,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+/*
static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
+*/
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
/*
@@ -54,12 +58,14 @@ static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
#include <sys/param.h>
-#include <syslog.h>
+#include <ctype.h>
#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
+#include <err.h>
#include <stdio.h>
-#include <ctype.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <unistd.h>
+
#include "lp.h"
#include "lp.local.h"
#include "pathnames.h"
@@ -71,19 +77,19 @@ int users; /* # of users in user array */
uid_t uid, euid;
-static int ckqueue __P((char *));
+static int ckqueue __P((const struct printer *));
static void usage __P((void));
int
main(argc, argv)
- register int argc;
- register char **argv;
+ int argc;
+ char **argv;
{
- extern char *optarg;
- extern int optind;
- int ch, aflag, lflag;
- char *buf, *cp;
+ int ch, aflag, lflag;
+ char *printer;
+ struct printer myprinter, *pp = &myprinter;
+ printer = NULL;
euid = geteuid();
uid = getuid();
seteuid(uid);
@@ -115,47 +121,64 @@ main(argc, argv)
for (argc -= optind, argv += optind; argc; --argc, ++argv)
if (isdigit(argv[0][0])) {
if (requests >= MAXREQUESTS)
- fatal("too many requests");
+ fatal(0, "too many requests");
requ[requests++] = atoi(*argv);
}
else {
if (users >= MAXUSERS)
- fatal("too many users");
+ fatal(0, "too many users");
user[users++] = *argv;
}
if (aflag) {
- while (cgetnext(&buf, printcapdb) > 0) {
- if (ckqueue(buf) <= 0) {
- free(buf);
- continue; /* no jobs */
+ 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");
}
- for (cp = buf; *cp; cp++)
- if (*cp == '|' || *cp == ':') {
- *cp = '\0';
+ 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, pcaperr(status));
}
- printer = buf;
- printf("%s:\n", printer);
- displayq(lflag);
- free(buf);
- printf("\n");
+ } while (more && status);
}
- } else
- displayq(lflag);
+ } else {
+ int status;
+
+ init_printer(pp);
+ status = getprintcap(printer, pp);
+ if (status < 0)
+ fatal(pp, pcaperr(status));
+
+ displayq(pp, lflag);
+ }
exit(0);
}
static int
-ckqueue(cap)
- char *cap;
+ckqueue(pp)
+ const struct printer *pp;
{
register struct dirent *d;
DIR *dirp;
char *spooldir;
- if (cgetstr(cap, "sd", &spooldir) == -1)
- spooldir = _PATH_DEFSPOOL;
+ spooldir = pp->spool_dir;
if ((dirp = opendir(spooldir)) == NULL)
return (-1);
while ((d = readdir(dirp)) != NULL) {
OpenPOWER on IntegriCloud