Deleted Added
full compact
lpq.c (29780) lpq.c (31492)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef lint
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef lint
36static char copyright[] =
36static const char copyright[] =
37"@(#) Copyright (c) 1983, 1993\n\
38 The Regents of the University of California. All rights reserved.\n";
39#endif /* not lint */
40
41#ifndef lint
37"@(#) Copyright (c) 1983, 1993\n\
38 The Regents of the University of California. All rights reserved.\n";
39#endif /* not lint */
40
41#ifndef lint
42/*
42static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
43static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
44*/
45static const char rcsid[] =
46 "$Id$";
43#endif /* not lint */
44
45/*
46 * Spool Queue examination program
47 *
48 * lpq [-a] [-l] [-Pprinter] [user...] [job...]
49 *
50 * -a show all non-null queues on the local machine
51 * -l long output
52 * -P used to identify printer as per lpr/lprm
53 */
54
55#include <sys/param.h>
56
47#endif /* not lint */
48
49/*
50 * Spool Queue examination program
51 *
52 * lpq [-a] [-l] [-Pprinter] [user...] [job...]
53 *
54 * -a show all non-null queues on the local machine
55 * -l long output
56 * -P used to identify printer as per lpr/lprm
57 */
58
59#include <sys/param.h>
60
57#include <syslog.h>
61#include <ctype.h>
58#include <dirent.h>
62#include <dirent.h>
59#include <unistd.h>
60#include <stdlib.h>
63#include <err.h>
61#include <stdio.h>
64#include <stdio.h>
62#include <ctype.h>
65#include <stdlib.h>
66#include <syslog.h>
67#include <unistd.h>
68
63#include "lp.h"
64#include "lp.local.h"
65#include "pathnames.h"
66
67int requ[MAXREQUESTS]; /* job number of spool entries */
68int requests; /* # of spool requests */
69char *user[MAXUSERS]; /* users to process */
70int users; /* # of users in user array */
71
72uid_t uid, euid;
73
69#include "lp.h"
70#include "lp.local.h"
71#include "pathnames.h"
72
73int requ[MAXREQUESTS]; /* job number of spool entries */
74int requests; /* # of spool requests */
75char *user[MAXUSERS]; /* users to process */
76int users; /* # of users in user array */
77
78uid_t uid, euid;
79
74static int ckqueue __P((char *));
80static int ckqueue __P((const struct printer *));
75static void usage __P((void));
76
77int
78main(argc, argv)
81static void usage __P((void));
82
83int
84main(argc, argv)
79 register int argc;
80 register char **argv;
85 int argc;
86 char **argv;
81{
87{
82 extern char *optarg;
83 extern int optind;
84 int ch, aflag, lflag;
85 char *buf, *cp;
88 int ch, aflag, lflag;
89 char *printer;
90 struct printer myprinter, *pp = &myprinter;
86
91
92 printer = NULL;
87 euid = geteuid();
88 uid = getuid();
89 seteuid(uid);
90 name = *argv;
91 if (gethostname(host, sizeof(host)))
92 err(1, "gethostname");
93 openlog("lpd", 0, LOG_LPR);
94

--- 15 unchanged lines hidden (view full) ---

110 }
111
112 if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL)
113 printer = DEFLP;
114
115 for (argc -= optind, argv += optind; argc; --argc, ++argv)
116 if (isdigit(argv[0][0])) {
117 if (requests >= MAXREQUESTS)
93 euid = geteuid();
94 uid = getuid();
95 seteuid(uid);
96 name = *argv;
97 if (gethostname(host, sizeof(host)))
98 err(1, "gethostname");
99 openlog("lpd", 0, LOG_LPR);
100

--- 15 unchanged lines hidden (view full) ---

116 }
117
118 if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL)
119 printer = DEFLP;
120
121 for (argc -= optind, argv += optind; argc; --argc, ++argv)
122 if (isdigit(argv[0][0])) {
123 if (requests >= MAXREQUESTS)
118 fatal("too many requests");
124 fatal(0, "too many requests");
119 requ[requests++] = atoi(*argv);
120 }
121 else {
122 if (users >= MAXUSERS)
125 requ[requests++] = atoi(*argv);
126 }
127 else {
128 if (users >= MAXUSERS)
123 fatal("too many users");
129 fatal(0, "too many users");
124 user[users++] = *argv;
125 }
126
127 if (aflag) {
130 user[users++] = *argv;
131 }
132
133 if (aflag) {
128 while (cgetnext(&buf, printcapdb) > 0) {
129 if (ckqueue(buf) <= 0) {
130 free(buf);
131 continue; /* no jobs */
134 int more, status;
135
136 more = firstprinter(pp, &status);
137 if (status)
138 goto looperr;
139 while (more) {
140 if (ckqueue(pp) > 0) {
141 printf("%s:\n", pp->printer);
142 displayq(pp, lflag);
143 printf("\n");
132 }
144 }
133 for (cp = buf; *cp; cp++)
134 if (*cp == '|' || *cp == ':') {
135 *cp = '\0';
145 do {
146 more = nextprinter(pp, &status);
147looperr:
148 switch (status) {
149 case PCAPERR_TCOPEN:
150 printf("warning: %s: unresolved "
151 "tc= reference(s) ",
152 pp->printer);
153 case PCAPERR_SUCCESS:
136 break;
154 break;
155 default:
156 fatal(pp, pcaperr(status));
137 }
157 }
138 printer = buf;
139 printf("%s:\n", printer);
140 displayq(lflag);
141 free(buf);
142 printf("\n");
158 } while (more && status);
143 }
159 }
144 } else
145 displayq(lflag);
160 } else {
161 int status;
162
163 init_printer(pp);
164 status = getprintcap(printer, pp);
165 if (status < 0)
166 fatal(pp, pcaperr(status));
167
168 displayq(pp, lflag);
169 }
146 exit(0);
147}
148
149static int
170 exit(0);
171}
172
173static int
150ckqueue(cap)
151 char *cap;
174ckqueue(pp)
175 const struct printer *pp;
152{
153 register struct dirent *d;
154 DIR *dirp;
155 char *spooldir;
156
176{
177 register struct dirent *d;
178 DIR *dirp;
179 char *spooldir;
180
157 if (cgetstr(cap, "sd", &spooldir) == -1)
158 spooldir = _PATH_DEFSPOOL;
181 spooldir = pp->spool_dir;
159 if ((dirp = opendir(spooldir)) == NULL)
160 return (-1);
161 while ((d = readdir(dirp)) != NULL) {
162 if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
163 continue; /* daemon control files only */
164 closedir(dirp);
165 return (1); /* found something */
166 }
167 closedir(dirp);
168 return (0);
169}
170
171static void
172usage()
173{
174 fprintf(stderr,
175 "usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]\n");
176 exit(1);
177}
182 if ((dirp = opendir(spooldir)) == NULL)
183 return (-1);
184 while ((d = readdir(dirp)) != NULL) {
185 if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
186 continue; /* daemon control files only */
187 closedir(dirp);
188 return (1); /* found something */
189 }
190 closedir(dirp);
191 return (0);
192}
193
194static void
195usage()
196{
197 fprintf(stderr,
198 "usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]\n");
199 exit(1);
200}