From c6d1c01831f0239ba3bb32a654a9735a2b53a1bc Mon Sep 17 00:00:00 2001 From: Ralph Campbell Date: Fri, 17 Jun 1983 22:09:45 -0800 Subject: [PATCH] fixed `fc' and `fs' when 0177777 is needed. SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 4.8 SCCS-vsn: usr.sbin/lpr/common_source/common.c 4.6 SCCS-vsn: usr.sbin/lpr/common_source/displayq.c 4.7 SCCS-vsn: usr.sbin/lpr/common_source/lp.h 4.3 SCCS-vsn: usr.sbin/lpr/common_source/lp.local.h 4.2 SCCS-vsn: usr.sbin/lpr/lpd/recvjob.c 4.5 --- usr/src/usr.sbin/lpr/common_source/common.c | 14 +++--- usr/src/usr.sbin/lpr/common_source/displayq.c | 12 ++--- usr/src/usr.sbin/lpr/common_source/lp.h | 12 +++-- usr/src/usr.sbin/lpr/common_source/lp.local.h | 3 +- usr/src/usr.sbin/lpr/lpd/printjob.c | 49 ++++++++++++------- usr/src/usr.sbin/lpr/lpd/recvjob.c | 6 ++- 6 files changed, 58 insertions(+), 38 deletions(-) diff --git a/usr/src/usr.sbin/lpr/common_source/common.c b/usr/src/usr.sbin/lpr/common_source/common.c index 0f16a7c802..90e1e59697 100644 --- a/usr/src/usr.sbin/lpr/common_source/common.c +++ b/usr/src/usr.sbin/lpr/common_source/common.c @@ -1,4 +1,4 @@ -/* common.c 4.5 83/06/02 */ +/* common.c 4.6 83/06/17 */ /* * Routines and data common to all the line printer functions. */ @@ -7,6 +7,7 @@ int DU; /* daeomon user-id */ int MX; /* maximum number of blocks to copy */ +int MC; /* maximum number of copies allowed */ char *LP; /* line printer device name */ char *RM; /* remote machine name */ char *RP; /* remote printer name */ @@ -26,6 +27,7 @@ char *CF; /* name of cifplot filter (per job) */ char *PF; /* name of vrast filter (per job) */ char *FF; /* form feed string */ char *TR; /* trailer string to be output when Q empties */ +short SC; /* suppress multiple copies */ short SF; /* suppress FF on each print job */ short SH; /* suppress header page */ short SB; /* short banner instead of normal header */ @@ -35,10 +37,10 @@ short PL; /* page length */ short PX; /* page width in pixels */ short PY; /* page length in pixels */ short BR; /* baud rate if lp is a tty */ -short FC; /* flags to clear if lp is a tty */ -short FS; /* flags to set if lp is a tty */ -short XC; /* flags to clear for local mode */ -short XS; /* flags to set for local mode */ +int FC; /* flags to clear if lp is a tty */ +int FS; /* flags to set if lp is a tty */ +int XC; /* flags to clear for local mode */ +int XS; /* flags to set for local mode */ short RS; /* restricted to those with local accounts */ char line[BUFSIZ]; @@ -169,7 +171,7 @@ getq(namelist) int arraysz, compar(); DIR *dirp; - if ((dirp = opendir(".")) == NULL) + if ((dirp = opendir(SD)) == NULL) return(-1); if (fstat(dirp->dd_fd, &stbuf) < 0) goto errdone; diff --git a/usr/src/usr.sbin/lpr/common_source/displayq.c b/usr/src/usr.sbin/lpr/common_source/displayq.c index 1c7b980c0d..ce86140409 100644 --- a/usr/src/usr.sbin/lpr/common_source/displayq.c +++ b/usr/src/usr.sbin/lpr/common_source/displayq.c @@ -1,13 +1,13 @@ -/* displayq.c 4.6 83/06/15 */ +/* displayq.c 4.7 83/06/17 */ /* * Routines to display the state of the queue. */ #include "lp.h" -#define JOBCOL 40 /* column for job # in -l format */ -#define OWNCOL 7 /* start of Owner column in normal */ -#define SIZCOL 62 /* start of Size column in normal */ +#define JOBCOL 40 /* column for job # in -l format */ +#define OWNCOL 7 /* start of Owner column in normal */ +#define SIZCOL 62 /* start of Size column in normal */ /* * Stuff for handling job specifications @@ -118,7 +118,7 @@ displayq(format) fp = fopen(LO, "r"); if (fp == NULL || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) { if (fp != NULL) - fclose(fp); + fclose(fp); /* unlocks as well */ garbage = nitems; if (sendtorem) printf("\n%s: ", host); @@ -146,7 +146,7 @@ displayq(format) (void) flock(fd, LOCK_SH); while ((i = read(fd, line, sizeof(line))) > 0) (void) fwrite(line, 1, i, stdout); - (void) close(fd); + (void) close(fd); /* unlocks as well */ } else putchar('\n'); } diff --git a/usr/src/usr.sbin/lpr/common_source/lp.h b/usr/src/usr.sbin/lpr/common_source/lp.h index 40ecf49536..c3a1b53c5c 100644 --- a/usr/src/usr.sbin/lpr/common_source/lp.h +++ b/usr/src/usr.sbin/lpr/common_source/lp.h @@ -1,4 +1,4 @@ -/* lp.h 4.2 83/05/13 */ +/* lp.h 4.3 83/06/17 */ /* * Global definitions for the line printer system. */ @@ -21,6 +21,7 @@ extern int DU; /* daeomon user-id */ extern int MX; /* maximum number of blocks to copy */ +extern int MC; /* maximum number of copies allowed */ extern char *LP; /* line printer device name */ extern char *RM; /* remote machine name */ extern char *RP; /* remote printer name */ @@ -39,6 +40,7 @@ extern char *VF; /* name of raster filter (per job) */ extern char *CF; /* name of cifplot filter (per job) */ extern char *FF; /* form feed string */ extern char *TR; /* trailer string to be output when Q empties */ +extern short SC; /* suppress multiple copies */ extern short SF; /* suppress FF on each print job */ extern short SH; /* suppress header page */ extern short SB; /* short banner instead of normal header */ @@ -48,10 +50,10 @@ extern short PX; /* page width in pixels */ extern short PY; /* page length in pixels */ extern short PL; /* page length */ extern short BR; /* baud rate if lp is a tty */ -extern short FC; /* flags to clear if lp is a tty */ -extern short FS; /* flags to set if lp is a tty */ -extern short XC; /* flags to clear for local mode */ -extern short XS; /* flags to set for local mode */ +extern int FC; /* flags to clear if lp is a tty */ +extern int FS; /* flags to set if lp is a tty */ +extern int XC; /* flags to clear for local mode */ +extern int XS; /* flags to set for local mode */ extern short RS; /* restricted to those with local accounts */ extern char line[BUFSIZ]; diff --git a/usr/src/usr.sbin/lpr/common_source/lp.local.h b/usr/src/usr.sbin/lpr/common_source/lp.local.h index 923700544f..3bb72d30c0 100644 --- a/usr/src/usr.sbin/lpr/common_source/lp.local.h +++ b/usr/src/usr.sbin/lpr/common_source/lp.local.h @@ -1,4 +1,4 @@ -/* lp.local.h 4.1 83/04/29 */ +/* lp.local.h 4.2 83/06/17 */ /* * Possibly, local parameters to the spooling system */ @@ -32,6 +32,7 @@ #define DEFRLPR "/usr/lib/rlpr" #define DEFBINDIR "/usr/ucb" #define DEFMX 1000 +#define DEFMAXCOPIES 0 #define DEFFF "\f" #define DEFWIDTH 132 #define DEFLENGTH 66 diff --git a/usr/src/usr.sbin/lpr/lpd/printjob.c b/usr/src/usr.sbin/lpr/lpd/printjob.c index 7f0f62333f..be23a1f85c 100644 --- a/usr/src/usr.sbin/lpr/lpd/printjob.c +++ b/usr/src/usr.sbin/lpr/lpd/printjob.c @@ -1,4 +1,4 @@ -/* printjob.c 4.7 83/06/15 */ +/* printjob.c 4.8 83/06/17 */ /* * printjob -- print jobs in the queue. * @@ -60,11 +60,15 @@ printjob() } if (stat(LO, &stb) == 0 && (stb.st_mode & 0100)) exit(0); /* printing disabled */ - lfd = open(LO, O_WRONLY|O_CREAT, 0664); - if (lfd < 0 || flock(lfd, LOCK_EX|LOCK_NB) < 0) { + lfd = open(LO, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (lfd < 0) { + log("cannot create %s", LO); + exit(1); + } + if (flock(lfd, LOCK_EX|LOCK_NB) < 0) { if (errno == EWOULDBLOCK) /* active deamon present */ exit(0); - log("cannot create %s", LO); + log("cannot lock %s", LO); exit(1); } ftruncate(lfd, 0); @@ -86,6 +90,10 @@ printjob() } if (nitems == 0) /* no work to do */ exit(0); + if (stb.st_mode & 01) { /* reset queue flag */ + if (fchmod(lfd, stb.st_mode & 0776) < 0) + log("cannot chmod %s", LO); + } openpr(); /* open printer or remote */ again: /* @@ -108,10 +116,20 @@ again: else i = sendit(q->q_name); /* - * Check to see if we are supposed to stop printing. + * Check to see if we are supposed to stop printing or + * if we are to rebuild the queue. */ - if (stat(LO, &stb) == 0 && (stb.st_mode & 0100)) - goto done; + if (fstat(lfd, &stb) == 0) { + if (stb.st_mode & 0100) + goto done; + if (stb.st_mode & 01) { + for (free((char *) q); nitems--; free((char *) q)) + q = *qp++; + if (fchmod(lfd, stb.st_mode & 0776) < 0) + log("cannot chmod %s", LO); + break; + } + } /* * Check to see if we should try reprinting the job. */ @@ -866,13 +884,10 @@ init() { int status; - if ((status = pgetent(line, printer)) < 0) { - log("can't open printer description file"); - exit(1); - } else if (status == 0) { - log("unknown printer"); - exit(1); - } + if ((status = pgetent(line, printer)) < 0) + fatal("can't open printer description file"); + else if (status == 0) + fatal("unknown printer"); if ((LP = pgetstr("lp", &bp)) == NULL) LP = DEFDEVLP; if ((RP = pgetstr("rp", &bp)) == NULL) @@ -1054,10 +1069,8 @@ setty() } ttybuf.sg_ispeed = ttybuf.sg_ospeed = bp->speed; } - if (FC) - ttybuf.sg_flags &= ~FC; - if (FS) - ttybuf.sg_flags |= FS; + ttybuf.sg_flags &= ~FC; + ttybuf.sg_flags |= FS; if (ioctl(pfd, TIOCSETP, (char *)&ttybuf) < 0) { log("cannot set tty parameters"); exit(1); diff --git a/usr/src/usr.sbin/lpr/lpd/recvjob.c b/usr/src/usr.sbin/lpr/lpd/recvjob.c index 638e603fab..1b957f719b 100644 --- a/usr/src/usr.sbin/lpr/lpd/recvjob.c +++ b/usr/src/usr.sbin/lpr/lpd/recvjob.c @@ -1,4 +1,4 @@ -/* recvjob.c 4.4 83/06/15 */ +/* recvjob.c 4.5 83/06/17 */ /* * Receive printer jobs from the network, queue them and * start the printer daemon. @@ -143,8 +143,10 @@ readfile(file, size) amt = BUFSIZ; if (i + amt > size) amt = size - i; - if (err == 0 && write(fd, buf, amt) != amt) + if (write(fd, buf, amt) != amt) { err++; + break; + } } (void) close(fd); if (err) -- 2.20.1