From 6f038d7b3df1756ed5e57967001b4f630dde1ea4 Mon Sep 17 00:00:00 2001 From: Ralph Campbell Date: Thu, 2 Dec 1982 19:59:21 -0800 Subject: [PATCH] Updated directory scanning and sorting for new dir.h SCCS-vsn: usr.sbin/lpr/lpr/lpr.c 4.4 SCCS-vsn: usr.sbin/lpr/Makefile 1.4 SCCS-vsn: usr.sbin/lpr/common_source/lp.local.h 1.3 --- usr/src/usr.sbin/lpr/Makefile | 31 ++--- usr/src/usr.sbin/lpr/common_source/lp.local.h | 17 +-- usr/src/usr.sbin/lpr/lpr/lpr.c | 114 +++++++++--------- 3 files changed, 77 insertions(+), 85 deletions(-) diff --git a/usr/src/usr.sbin/lpr/Makefile b/usr/src/usr.sbin/lpr/Makefile index 166232e252..4ecd488e1e 100644 --- a/usr/src/usr.sbin/lpr/Makefile +++ b/usr/src/usr.sbin/lpr/Makefile @@ -20,17 +20,17 @@ all: lpd lpr sq dq lpdrestart filters filters: necf lpf laf -lpd: lpd.o lpdchar.o printcap.o - ${CC} -o lpd ${LDFLAGS} lpd.o lpdchar.o printcap.o +lpd: lpd.o lpdchar.o printcap.o getqueue.o + ${CC} -o lpd ${LDFLAGS} lpd.o lpdchar.o printcap.o getqueue.o lpr: lpr.o printcap.o ${CC} -o lpr ${LDFLAGS} lpr.o printcap.o -sq: sq.o printcap.o - ${CC} -o sq ${LDFLAGS} sq.o -ltermcap printcap.o +sq: sq.o printcap.o getqueue.o + ${CC} -o sq ${LDFLAGS} sq.o -ltermcap printcap.o getqueue.o -dq: dq.o printcap.o - ${CC} -o dq ${LDFLAGS} dq.o printcap.o +dq: dq.o printcap.o scandir.o + ${CC} -o dq ${LDFLAGS} dq.o printcap.o scandir.o lpdrestart: lpdrestart.o ${CC} -o lpdrestart ${LDFLAGS} lpdrestart.o @@ -45,23 +45,24 @@ necf: necf.c ${CC} -o necf ${CFLAGS} ${LDFLAGS} necf.c lpr.o lpd.o sq.o dq.o lpdrestart.o: lp.local.h +lpd.o sq.o getqueue.o: getqueue.h install: all cp lpd ${LIBDIR}/lpd - cp sq ${BINDIR}/sq - cp dq ${BINDIR}/dq + cp sq ${BINDIR}/lpq + cp dq ${BINDIR}/lprm cp lpr ${BINDIR}/lpr # rm -f ${BINDIR}/opr ${BINDIR}/print # ln ${BINDIR}/lpr ${BINDIR}/print # ln ${BINDIR}/lpr ${BINDIR}/opr - chown ${ROOT} ${BINDIR}/lpr ${BINDIR}/sq - chown ${DAEMON} ${BINDIR}/dq ${LIBDIR}/lpd - chgrp ${SPGRP} ${LIBDIR}/lpd ${BINDIR}/lpr ${BINDIR}/dq ${BINDIR}/sq - chmod 6711 ${LIBDIR}/lpd ${BINDIR}/lpr ${BINDIR}/dq - chmod 2711 ${BINDIR}/sq - chmod 775 ${SPOOLDIR} - chgrp ${SPGRP} ${SPOOLDIR} + chown ${ROOT} ${BINDIR}/lpr + chown ${DAEMON} $(BINDIR)/lpq ${BINDIR}/lprm ${LIBDIR}/lpd + chgrp ${SPGRP} ${LIBDIR}/lpd ${BINDIR}/lpr ${BINDIR}/lpq ${BINDIR}/lprm + chmod 6711 ${LIBDIR}/lpd ${BINDIR}/lpr ${BINDIR}/lprm + chmod 2711 ${BINDIR}/lpq chown ${DAEMON} ${SPOOLDIR} + chgrp ${SPGRP} ${SPOOLDIR} + chmod 775 ${SPOOLDIR} clean: rm -f laf dq sq lpd lpr necf lpf *.o 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 17ffe552af..b40fdb25da 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 1.2 81/09/04 */ +/* lp.local.h 1.3 82/12/02 */ /* * Possibly, local parameters to the spooling system */ @@ -30,21 +30,6 @@ #define DEFFF "\f" #define DEFDAEMON "/usr/lib/lpd" #define DEFDEVLP "/dev/lp" -#define DEFUID 1 - -/* - * The system name is normally imported from , - * change it here if you want someting special on the JOB line - * of the burst page. - */ - -#ifdef SYTEK -# define SYSTEM_NAME "Sytek VAX/UNIX" -#else -#include - -# define SYSTEM_NAME sysname -#endif /* * Some utilities used by lpd diff --git a/usr/src/usr.sbin/lpr/lpr/lpr.c b/usr/src/usr.sbin/lpr/lpr/lpr.c index 1ec6e438bf..f8e8b87a8b 100644 --- a/usr/src/usr.sbin/lpr/lpr/lpr.c +++ b/usr/src/usr.sbin/lpr/lpr/lpr.c @@ -55,7 +55,7 @@ char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n"; -/* lpr.c 4.3 81/05/19 */ +/* lpr.c 4.4 82/12/02 */ /* * lpr -- off line print * also known as print @@ -73,7 +73,7 @@ char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n"; * Multiple printer scheme using info from printer data base: * * DN who to invoke to print stuff - * SA rectory used as spool queue + * SA directory used as spool queue * * daemon identifies what printer it should use (in the case of the * same code being shared) by inspecting its argv[1]. @@ -103,7 +103,8 @@ int hdr = 1; /* 1 =>'s default header */ int user; /* user id */ int spgroup; /* daemon's group for creating spool files */ char *title; /* pr'ing title */ -char *class = SYSTEM_NAME; /* class title on header page */ +char classbuf[32]; /* class title on header page */ +char *class = classbuf; char *jobname; /* job name on header page */ char *name; /* program name */ char *printer; /* printer name */ @@ -114,9 +115,10 @@ char *malloc(); char *getenv(); char *rindex(); +/* ARGSUSED */ main(argc, argv) -int argc; -char *argv[]; + int argc; + char *argv[]; { register char *arg; int i, c, f, flag, out(); @@ -136,15 +138,16 @@ char *argv[]; * access files and printer. Users can't get to anything * w/o help of sq and dq programs. */ + gethostname(classbuf, sizeof (classbuf)); user = getuid(); spgroup = getegid(); - if(signal(SIGHUP, SIG_IGN) != SIG_IGN) + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, out); - if(signal(SIGINT, SIG_IGN) != SIG_IGN) + if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, out); - if(signal(SIGQUIT, SIG_IGN) != SIG_IGN) + if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) signal(SIGQUIT, out); - if(signal(SIGTERM, SIG_IGN) != SIG_IGN) + if (signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, out); flag = 0; if ((printer = getenv("PRINTER")) == NULL) @@ -245,30 +248,30 @@ char *argv[]; inchar = f-7; tff = nfile(tfname); if (jflag == 0) { - if(argc == 1) + if (argc == 1) jobname = &dfname[f-10]; else jobname = argv[1]; } ident(); - if(argc == 1) + if (argc == 1) copy(0, " "); - else while(--argc) { - if(test(arg = *++argv) == -1) /* file reasonable */ + else while (--argc) { + if (test(arg = *++argv) == -1) /* file reasonable */ continue; if (flag == '+') /* force copy flag */ goto cf; if (stat(arg, &sbuf) < 0) { - printf("lpr:"); + printf("%s:", name); perror(arg); continue; } - if((sbuf.st_mode&04) == 0) + if ((sbuf.st_mode&04) == 0) goto cf; - if(*arg == '/' && flag != '-') { - for(i=0;i 0) { + while ((i = read(f, buf, BUFSIZ)) > 0) { if (write(ff, buf, i) != i) { printf("%s: %s: temp file write error\n", name, n); break; } nc += i; - if(nc >= BUFSIZ) { + if (nc >= BUFSIZ) { nc -= BUFSIZ; - if(nr++ > MX) { + if (nr++ > MX) { printf("%s: %s: copy file is too large\n", name, n); break; } @@ -370,14 +373,14 @@ char n[]; } card(c, p2) -register char c, *p2; + register char c, *p2; { char buf[BUFSIZ]; register char *p1 = buf; int col = 0; *p1++ = c; - while((c = *p2++) != '\0') { + while ((c = *p2++) != '\0') { *p1++ = c; col++; } @@ -411,11 +414,14 @@ ident() } nfile(n) -char *n; + char *n; { register f; + int oldumask = umask(022); /* should block signals */ - if((f = creat(n, FILMOD)) < 0) { + f = creat(n, FILMOD); + (void) umask(oldumask); + if (f < 0) { printf("%s: cannot create %s\n", name, n); out(); } @@ -425,7 +431,7 @@ char *n; out(); } n[inchar]++; - return(f); + return (f); } out() @@ -438,22 +444,22 @@ out() signal(SIGTERM, SIG_IGN); i = inchar; if (tfname) - while(tfname[i] != 'A') { + while (tfname[i] != 'A') { tfname[i]--; unlink(tfname); } if (cfname) - while(cfname[i] != 'A') { + while (cfname[i] != 'A') { cfname[i]--; unlink(cfname); } if (lfname) - while(lfname[i] != 'A') { + while (lfname[i] != 'A') { lfname[i]--; unlink(lfname); } if (dfname) - while(dfname[i] != 'A') { + while (dfname[i] != 'A') { dfname[i]--; unlink(dfname); } @@ -461,7 +467,7 @@ out() } test(file) -char *file; + char *file; { struct exec buf; struct stat mbuf; @@ -469,20 +475,20 @@ char *file; if (access(file, 4) < 0) { printf("%s: cannot access %s\n", name, file); - return(-1); + return (-1); } - if(stat(file, &mbuf) < 0) { + if (stat(file, &mbuf) < 0) { printf("%s: cannot stat %s\n", name, file); return (-1); } if ((mbuf.st_mode&S_IFMT) == S_IFDIR) { printf("%s: %s is a directory\n", name, file); - return(-1); + return (-1); } - if((fd = open(file, 0)) < 0) { + if ((fd = open(file, 0)) < 0) { printf("%s: cannot open %s\n", name, file); - return(-1); + return (-1); } if (read(fd, &buf, sizeof(buf)) == sizeof(buf)) switch(buf.a_magic) { @@ -501,11 +507,11 @@ char *file; } close(fd); - return(0); + return (0); error1: printf(" and is unprintable\n"); close(fd); - return(-1); + return (-1); } /* @@ -513,7 +519,7 @@ error1: */ char * itoa(i) -register int i; + register int i; { static char b[10] = "########"; register char *p; @@ -522,7 +528,7 @@ register int i; do *p-- = i%10 + '0'; while (i /= 10); - return(++p); + return (++p); } /* @@ -530,7 +536,7 @@ register int i; * return pointer to daemon structure */ chkprinter(s) -register char *s; + register char *s; { static char buf[BUFSIZ/2]; char b[BUFSIZ]; @@ -541,7 +547,7 @@ register char *s; fprintf(stderr, "%s: can't open printer description file\n", name); exit(3); } else if (stat == 0) - return(NULL); + return (NULL); if ((DN = pgetstr("dn", &bp)) == NULL) DN = DEFDAEMON; if ((LP = pgetstr("lp", &bp)) == NULL) @@ -550,7 +556,7 @@ register char *s; SA = DEFSPOOL; if ((MX = pgetnum("mx")) < 0) MX = DEFMX; - return(1); + return (1); } /* @@ -558,7 +564,7 @@ register char *s; */ char * mktmp(id, pid, n) -char *id; + char *id; { register char *s; @@ -567,5 +573,5 @@ char *id; exit(1); } sprintf(s, "%s/%sA%05d", SA, id, pid); - return(s); + return (s); } -- 2.20.1