chkprintcap.c (70520) | chkprintcap.c (88004) |
---|---|
1/* 2 * Copyright 1997 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 16 unchanged lines hidden (view full) --- 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30static const char copyright[] = 31 "Copyright (C) 1997, Massachusetts Institute of Technology\r\n"; 32static const char rcsid[] = | 1/* 2 * Copyright 1997 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 16 unchanged lines hidden (view full) --- 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30static const char copyright[] = 31 "Copyright (C) 1997, Massachusetts Institute of Technology\r\n"; 32static const char rcsid[] = |
33 "$FreeBSD: head/usr.sbin/lpr/chkprintcap/chkprintcap.c 70520 2000-12-30 20:56:04Z phk $"; | 33 "$FreeBSD: head/usr.sbin/lpr/chkprintcap/chkprintcap.c 88004 2001-12-15 23:35:55Z gad $"; |
34 35#include <sys/types.h> 36#include <sys/queue.h> 37#include <sys/stat.h> 38 39#include <err.h> 40#include <errno.h> 41#include <grp.h> 42#include <stdio.h> 43#include <string.h> 44#include <stdlib.h> 45#include <unistd.h> 46 47#include <sys/param.h> /* needed for lp.h but not used here */ 48#include <dirent.h> /* ditto */ 49#include "lp.h" 50#include "lp.local.h" | 34 35#include <sys/types.h> 36#include <sys/queue.h> 37#include <sys/stat.h> 38 39#include <err.h> 40#include <errno.h> 41#include <grp.h> 42#include <stdio.h> 43#include <string.h> 44#include <stdlib.h> 45#include <unistd.h> 46 47#include <sys/param.h> /* needed for lp.h but not used here */ 48#include <dirent.h> /* ditto */ 49#include "lp.h" 50#include "lp.local.h" |
51#include "pathnames.h" 52#include "skimprintcap.h" |
|
51 52static void check_spool_dirs(void); 53static int interpret_error(const struct printer *pp, int error); 54static void make_spool_dir(const struct printer *pp); 55static void note_spool_dir(const struct printer *pp, const struct stat *st); 56static void usage(void) __dead2; 57 58static int problems; /* number of problems encountered */ 59 60/* 61 * chkprintcap - check the printcap file for syntactic and semantic errors 62 * Returns the number of problems found. 63 */ 64int 65main(int argc, char **argv) 66{ | 53 54static void check_spool_dirs(void); 55static int interpret_error(const struct printer *pp, int error); 56static void make_spool_dir(const struct printer *pp); 57static void note_spool_dir(const struct printer *pp, const struct stat *st); 58static void usage(void) __dead2; 59 60static int problems; /* number of problems encountered */ 61 62/* 63 * chkprintcap - check the printcap file for syntactic and semantic errors 64 * Returns the number of problems found. 65 */ 66int 67main(int argc, char **argv) 68{ |
67 int c, error, makedirs, more; | 69 struct skiminfo *skres; 70 char *pcap_fname; 71 int c, error, makedirs, more, queuecnt, verbosity; |
68 struct printer myprinter, *pp; 69 70 makedirs = 0; | 72 struct printer myprinter, *pp; 73 74 makedirs = 0; |
75 queuecnt = 0; 76 verbosity = 0; 77 pcap_fname = NULL; |
|
71 pp = &myprinter; 72 | 78 pp = &myprinter; 79 |
73 while ((c = getopt(argc, argv, "df:")) != -1) { | 80 while ((c = getopt(argc, argv, "df:v")) != -1) { |
74 switch (c) { 75 case 'd': 76 makedirs = 1; 77 break; 78 79 case 'f': | 81 switch (c) { 82 case 'd': 83 makedirs = 1; 84 break; 85 86 case 'f': |
80 setprintcap(optarg); | 87 pcap_fname = strdup(optarg); 88 setprintcap(pcap_fname); |
81 break; 82 | 89 break; 90 |
91 case 'v': 92 verbosity++; 93 break; 94 |
|
83 default: 84 usage(); 85 } 86 } 87 88 if (optind != argc) 89 usage(); 90 | 95 default: 96 usage(); 97 } 98 } 99 100 if (optind != argc) 101 usage(); 102 |
103 if (pcap_fname == NULL) 104 pcap_fname = strdup(_PATH_PRINTCAP); 105 106 /* 107 * Skim through the printcap file looking for simple user-mistakes 108 * which will produce the wrong result for the user, but which may 109 * be pretty hard for the user to notice. Such user-mistakes will 110 * only generate warning messages. The (fatal-) problem count will 111 * only be incremented if there is a system problem trying to read 112 * the printcap file. 113 */ 114 skres = skim_printcap(pcap_fname, verbosity); 115 if (skres->fatalerr) 116 return (skres->fatalerr); 117 118 /* 119 * Now use the standard capability-db routines to check the values 120 * in each of the queues defined in the printcap file. 121 */ |
|
91 more = firstprinter(pp, &error); 92 if (interpret_error(pp, error) && more) 93 goto next; 94 95 while (more) { 96 struct stat stab; 97 | 122 more = firstprinter(pp, &error); 123 if (interpret_error(pp, error) && more) 124 goto next; 125 126 while (more) { 127 struct stat stab; 128 |
129 queuecnt++; |
|
98 errno = 0; 99 if (stat(pp->spool_dir, &stab) < 0) { 100 if (errno == ENOENT && makedirs) { 101 make_spool_dir(pp); 102 } else { 103 problems++; 104 warn("%s: %s", pp->printer, pp->spool_dir); 105 } 106 } else { 107 note_spool_dir(pp, &stab); 108 } 109 | 130 errno = 0; 131 if (stat(pp->spool_dir, &stab) < 0) { 132 if (errno == ENOENT && makedirs) { 133 make_spool_dir(pp); 134 } else { 135 problems++; 136 warn("%s: %s", pp->printer, pp->spool_dir); 137 } 138 } else { 139 note_spool_dir(pp, &stab); 140 } 141 |
110 /* Make other validity checks here... */ | 142 /* Make other queue-specific validity checks here... */ |
111 112next: 113 more = nextprinter(pp, &error); 114 if (interpret_error(pp, error) && more) 115 goto next; 116 } | 143 144next: 145 more = nextprinter(pp, &error); 146 if (interpret_error(pp, error) && more) 147 goto next; 148 } |
149 |
|
117 check_spool_dirs(); | 150 check_spool_dirs(); |
118 return problems; | 151 152 if (queuecnt != skres->entries) { 153 warnx("WARNING: found %d entries when skimming %s,", 154 skres->entries, pcap_fname); 155 warnx("WARNING: but only found %d queues to process!", 156 queuecnt); 157 } 158 return (problems); |
119} 120 121/* 122 * Interpret the error code. Returns 1 if we should skip to the next 123 * record (as this record is unlikely to make sense). If the problem 124 * is very severe, exit. Otherwise, return zero. 125 */ 126static int --- 140 unchanged lines hidden (view full) --- 267 err(++problems, "stat: %s", sd); 268 269 note_spool_dir(pp, &stab); 270} 271 272static void 273usage(void) 274{ | 159} 160 161/* 162 * Interpret the error code. Returns 1 if we should skip to the next 163 * record (as this record is unlikely to make sense). If the problem 164 * is very severe, exit. Otherwise, return zero. 165 */ 166static int --- 140 unchanged lines hidden (view full) --- 307 err(++problems, "stat: %s", sd); 308 309 note_spool_dir(pp, &stab); 310} 311 312static void 313usage(void) 314{ |
275 fprintf(stderr, "usage:\n\tchkprintcap [-d] [-f printcapfile]\n"); | 315 fprintf(stderr, "usage:\n\tchkprintcap [-dv] [-f printcapfile]\n"); |
276 exit(1); 277} | 316 exit(1); 317} |