diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-05-20 23:13:51 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-05-20 23:13:51 +0000 |
commit | b2a7fd194eceff2b87de78d7cec611dbe9852f58 (patch) | |
tree | 964c1ee0a29425901306badd36cf127d4a351291 /usr.sbin/lpr/lpq | |
parent | 1c6d6f81973745cbc85a424ec5f1931f07e8ebf7 (diff) |
Pull in useful bits from NetBSD and make our lp* easier to diff and
do some minor cleanup of my own:
o IPv6 support
o ANSI function headers
o use getopt()
o synce usage() with man pages
o passes -Wall on both 32bit and 64bit platforms
o add an option to set the max number of children lpd will fork off
o add an lpd option to bind to specific addresses instead of INADDR_ANY.
o allow user to specify how long to wait for a connection to remote servers
o more strlcpy() and snprintf() usage
o Use FOO_FILENO constants instead of hard-coding 0-2
o Add some keeps to man the page SYNOPSIS to avoid options being split
Diffstat (limited to 'usr.sbin/lpr/lpq')
-rw-r--r-- | usr.sbin/lpr/lpq/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/lpr/lpq/lpq.1 | 44 | ||||
-rw-r--r-- | usr.sbin/lpr/lpq/lpq.c | 64 |
3 files changed, 57 insertions, 55 deletions
diff --git a/usr.sbin/lpr/lpq/Makefile b/usr.sbin/lpr/lpq/Makefile index b8227017f7a..79e229243dd 100644 --- a/usr.sbin/lpr/lpq/Makefile +++ b/usr.sbin/lpr/lpq/Makefile @@ -1,9 +1,9 @@ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $OpenBSD: Makefile,v 1.2 1997/01/17 16:12:44 millert Exp $ +# $OpenBSD: Makefile,v 1.3 2002/05/20 23:13:50 millert Exp $ PROG= lpq CFLAGS+=-I${.CURDIR}/../common_source -SRCS= lpq.c displayq.c common.c +SRCS= lpq.c displayq.c common.c common_vars.c BINOWN= root BINGRP= daemon BINMODE=6555 diff --git a/usr.sbin/lpr/lpq/lpq.1 b/usr.sbin/lpr/lpq/lpq.1 index 331d52b9ff6..5ad81b9df7d 100644 --- a/usr.sbin/lpr/lpq/lpq.1 +++ b/usr.sbin/lpr/lpq/lpq.1 @@ -1,4 +1,5 @@ -.\" $OpenBSD: lpq.1,v 1.6 2000/03/19 17:57:06 aaron Exp $ +.\" $OpenBSD: lpq.1,v 1.7 2002/05/20 23:13:50 millert Exp $ +.\" $NetBSD: lpq.1,v 1.11 2002/01/19 03:23:11 wiz Exp $ .\" .\" Copyright (c) 1983, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -41,8 +42,7 @@ .Nd spool queue examination program .Sh SYNOPSIS .Nm lpq -.Op Fl a -.Op Fl l +.Op Fl al .Op Fl P Ns Ar printer .Op Ar job# Ar ... .Op Ar user Ar ... @@ -52,7 +52,7 @@ examines the spooling area used by .Xr lpd 8 for printing files on the line printer, and reports the status of the specified jobs or all jobs associated with a user. -.Nm lpq +.Nm invoked without any arguments reports on any jobs currently in the queue. .Pp @@ -77,7 +77,7 @@ rather than just the specified printer. .Pp For each job submitted (i.e., invocation of .Xr lpr 1 ) -.Nm lpq +.Nm reports the user's name, current rank in the queue, the names of files comprising the job, the job identifier (a number which may be supplied to @@ -91,14 +91,12 @@ to be File names comprising a job may be unavailable (when .Xr lpr 1 -is used as a sink in a pipeline) in which case the file -is indicated as +is used as a sink in a pipeline) in which case the file is indicated as .Dq (standard input) . .Pp If -.Nm lpq -warns that there is no daemon present (i.e., due to some malfunction), -the +.Nm +warns that there is no daemon present (i.e., due to some malfunction), the .Xr lpc 8 command can be used to restart the printer daemon. .Sh ENVIRONMENT @@ -109,16 +107,21 @@ If the following environment variable exists, it is used by Specifies an alternate default printer. .El .Sh FILES -.Bl -tag -width "/var/spool/*/lock" -compact +.Bl -tag -width "/var/spool/output/*/lock" -compact .It Pa /etc/printcap -for determining printer characteristics +To determine printer characteristics. .It Pa /var/spool/* -spooling directory, as determined from printcap -.It Pa /var/spool/*/cf* -control files specifying jobs -.It Pa /var/spool/*/lock -lock file to obtain the currently active job +The spooling directory, as determined from printcap. +.It Pa /var/spool/output/*/cf* +Control files specifying jobs. +.It Pa /var/spool/output/*/lock +The lock file to obtain the currently active job. .El +.Sh DIAGNOSTICS +Unable to open various files. +The lock file being malformed. +Garbage files when there is no daemon active, but files in the +spooling directory. .Sh SEE ALSO .Xr lpr 1 , .Xr lprm 1 , @@ -130,12 +133,7 @@ appeared in .Bx 3 . .Sh BUGS Due to the dynamic nature of the information in the spooling directory, -.Nm lpq +.Nm may report unreliably. Output formatting is sensitive to the line length of the terminal; this can result in widely spaced columns. -.Sh DIAGNOSTICS -Unable to open various files. -The lock file being malformed. -Garbage -files when there is no daemon active, but files in the spooling directory. diff --git a/usr.sbin/lpr/lpq/lpq.c b/usr.sbin/lpr/lpq/lpq.c index 7d578382b3e..bc90790276d 100644 --- a/usr.sbin/lpr/lpq/lpq.c +++ b/usr.sbin/lpr/lpq/lpq.c @@ -1,4 +1,5 @@ -/* $OpenBSD: lpq.c,v 1.11 2002/02/16 21:28:04 millert Exp $ */ +/* $OpenBSD: lpq.c,v 1.12 2002/05/20 23:13:50 millert Exp $ */ +/* $NetBSD: lpq.c,v 1.9 1999/12/07 14:54:47 mrg Exp $ */ /* * Copyright (c) 1983, 1993 @@ -44,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpq.c,v 1.11 2002/02/16 21:28:04 millert Exp $"; +static const char rcsid[] = "$OpenBSD: lpq.c,v 1.12 2002/05/20 23:13:50 millert Exp $"; #endif #endif /* not lint */ @@ -60,12 +61,14 @@ static const char rcsid[] = "$OpenBSD: lpq.c,v 1.11 2002/02/16 21:28:04 millert #include <sys/param.h> -#include <syslog.h> +#include <ctype.h> #include <dirent.h> +#include <err.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> -#include <ctype.h> +#include <syslog.h> + #include "lp.h" #include "lp.local.h" #include "pathnames.h" @@ -75,36 +78,29 @@ int requests; /* # of spool requests */ char *user[MAXUSERS]; /* users to process */ int users; /* # of users in user array */ -uid_t uid, euid; - volatile sig_atomic_t gotintr; static int ckqueue(char *); -void usage(void); +static __dead void usage(void); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { - extern char *optarg; - extern int optind; int ch, aflag, lflag; char *buf, *cp; + long l; euid = geteuid(); uid = getuid(); seteuid(uid); - if (gethostname(host, sizeof(host))) { - perror("lpq: gethostname"); - exit(1); - } - openlog("lpd", 0, LOG_LPR); + if (gethostname(host, sizeof(host)) != 0) + err(1, "gethostname"); + openlog("lpq", 0, LOG_LPR); aflag = lflag = 0; - while ((ch = getopt(argc, argv, "alP:")) != -1) - switch((char)ch) { + while ((ch = getopt(argc, argv, "alP:w:")) != -1) { + switch(ch) { case 'a': ++aflag; break; @@ -114,18 +110,23 @@ main(argc, argv) 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) { - char *p; - + if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; - if ((p = getenv("PRINTER")) != NULL) - printer = p; - } for (argc -= optind, argv += optind; argc; --argc, ++argv) if (isdigit(argv[0][0])) { @@ -162,8 +163,7 @@ main(argc, argv) } static int -ckqueue(cap) - char *cap; +ckqueue(char *cap) { struct dirent *d; DIR *dirp; @@ -183,9 +183,13 @@ ckqueue(cap) return (0); } -void -usage() +static __dead void +usage(void) { - puts("usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]"); + extern char *__progname; + + fprintf(stderr, + "usage: %s [-a] [-l] [-Pprinter] [user ...] [job ...]\n", + __progname); exit(1); } |