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/lpq.c | |
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/lpq.c')
-rw-r--r-- | usr.sbin/lpr/lpq/lpq.c | 64 |
1 files changed, 34 insertions, 30 deletions
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); } |