diff options
author | joerg <joerg@FreeBSD.org> | 1996-05-05 22:40:51 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1996-05-05 22:40:51 +0000 |
commit | 914cbcef2ca2238d808f510c1a2f084eb37952b6 (patch) | |
tree | a2c9a4d920a98c3865b5da51ea401d02253ceae3 /usr.sbin/lpr/common_source | |
parent | 8d1089fb9317c3fa275c4470e8a92463cc828758 (diff) | |
download | FreeBSD-src-914cbcef2ca2238d808f510c1a2f084eb37952b6.zip FreeBSD-src-914cbcef2ca2238d808f510c1a2f084eb37952b6.tar.gz |
Pull a bunch of fixes from the 4.4BSD-Lite2 branch. It's really
surprising how many trivial errors there have been... :-)
Some more cleanup is needed, but i'd like to separate the Lite2 changes
from other work, that's why this goes into a different commit.
People with serial printers should see whether i have broken the stty-
style printcap options (i hope not).
Inspired by: Sergey Shkonda <serg@bcs1.bcs.zaporizhzhe.ua>
Diffstat (limited to 'usr.sbin/lpr/common_source')
-rw-r--r-- | usr.sbin/lpr/common_source/common.c | 63 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/displayq.c | 25 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/lp.h | 7 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/recvjob.c | 4 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/rmjob.c | 6 |
5 files changed, 66 insertions, 39 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index a5c6ee5..9b9244e 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -37,11 +37,12 @@ */ #ifndef lint -static char sccsid[] = "@(#)common.c 8.2 (Berkeley) 1/21/94"; +static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> @@ -105,18 +106,20 @@ char *printer; /* printer name */ /* host machine name */ char host[MAXHOSTNAMELEN]; char *from = host; /* client's machine name */ -int sendtorem; /* are we sending to a remote? */ +int remote; /* true if sending files to a remote host */ char *printcapdb[2] = { _PATH_PRINTCAP, 0 }; static int compar __P((const void *, const void *)); /* - * Create a connection to the remote printer server. + * Create a TCP connection to host "rhost" at port "rport". + * If rport == 0, then use the printer service port. * Most of this code comes from rcmd.c. */ int -getport(rhost) +getport(rhost, rport) char *rhost; + int rport; { struct hostent *hp; struct servent *sp; @@ -129,16 +132,24 @@ getport(rhost) */ if (rhost == NULL) fatal("no remote host to connect to"); - hp = gethostbyname(rhost); - if (hp == NULL) - fatal("unknown host %s", rhost); - sp = getservbyname("printer", "tcp"); - if (sp == NULL) - fatal("printer/tcp: unknown service"); bzero((char *)&sin, sizeof(sin)); - bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = sp->s_port; + sin.sin_addr.s_addr = inet_addr(rhost); + if (sin.sin_addr.s_addr != INADDR_NONE) + sin.sin_family = AF_INET; + else { + hp = gethostbyname(rhost); + if (hp == NULL) + fatal("unknown host %s", rhost); + bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } + if (rport == 0) { + sp = getservbyname("printer", "tcp"); + if (sp == NULL) + fatal("printer/tcp: unknown service"); + sin.sin_port = sp->s_port; + } else + sin.sin_port = htons(rport); /* * Try connecting to the server. @@ -241,8 +252,9 @@ getq(namelist) * realloc the maximum size. */ if (++nitems > arraysz) { + arraysz *= 2; queue = (struct queue **)realloc((char *)queue, - (stbuf.st_size/12) * sizeof(struct queue *)); + arraysz * sizeof(struct queue *)); if (queue == NULL) goto errdone; } @@ -284,8 +296,8 @@ checkremote() register struct hostent *hp; static char errbuf[128]; - sendtorem = 0; /* assume printer is local */ - if (RM != (char *)NULL) { + remote = 0; /* assume printer is local */ + if (RM != NULL) { /* get the official name of the local host */ gethostname(name, sizeof(name)); name[sizeof(name)-1] = '\0'; @@ -310,10 +322,23 @@ checkremote() * if the two hosts are not the same, * then the printer must be remote. */ - if (strcmp(name, hp->h_name) != 0) - sendtorem = 1; + if (strcasecmp(name, hp->h_name) != 0) + remote = 1; } - return (char *)0; + return NULL; +} + +/* sleep n milliseconds */ +void +delay(n) +{ + struct timeval tdelay; + + if (n <= 0 || n > 10000) + fatal("unreasonable delay period (%d)", n); + tdelay.tv_sec = n / 1000; + tdelay.tv_usec = n * 1000 % 1000000; + (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay); } #if __STDC__ diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c index 59d3cc9..e0b6728 100644 --- a/usr.sbin/lpr/common_source/displayq.c +++ b/usr.sbin/lpr/common_source/displayq.c @@ -32,11 +32,12 @@ */ #ifndef lint -static char sccsid[] = "@(#)displayq.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <sys/file.h> #include <signal.h> #include <fcntl.h> @@ -124,7 +125,7 @@ displayq(format) fatal("cannot examine spooling area\n"); if (stat(LO, &statb) >= 0) { if (statb.st_mode & 0100) { - if (sendtorem) + if (remote) printf("%s: ", host); printf("Warning: %s is down: ", printer); fd = open(ST, O_RDONLY); @@ -137,7 +138,7 @@ displayq(format) putchar('\n'); } if (statb.st_mode & 010) { - if (sendtorem) + if (remote) printf("%s: ", host); printf("Warning: %s queue is turned off\n", printer); } @@ -150,8 +151,8 @@ displayq(format) else { /* get daemon pid */ cp = current; - while ((*cp = getc(fp)) != EOF && *cp != '\n') - cp++; + while ((i = getc(fp)) != EOF && i != '\n') + *cp++ = i; *cp = '\0'; i = atoi(current); if (i <= 0 || kill(i, 0) < 0) @@ -159,13 +160,13 @@ displayq(format) else { /* read current file name */ cp = current; - while ((*cp = getc(fp)) != EOF && *cp != '\n') - cp++; + while ((i = getc(fp)) != EOF && i != '\n') + *cp++ = i; *cp = '\0'; /* * Print the status file. */ - if (sendtorem) + if (remote) printf("%s: ", host); fd = open(ST, O_RDONLY); if (fd >= 0) { @@ -191,7 +192,7 @@ displayq(format) } free(queue); } - if (!sendtorem) { + if (!remote) { if (nitems == 0) puts("no entries"); return; @@ -215,7 +216,7 @@ displayq(format) (void) strcpy(cp, user[i]); } strcat(line, "\n"); - fd = getport(RM); + fd = getport(RM, 0); if (fd < 0) { if (from != host) printf("%s: ", host); @@ -237,7 +238,7 @@ displayq(format) void warn() { - if (sendtorem) + if (remote) printf("\n%s: ", host); puts("Warning: no daemon present"); current[0] = '\0'; @@ -271,7 +272,7 @@ inform(cf) if (rank < 0) rank = 0; - if (sendtorem || garbage || strcmp(cf, current)) + if (remote || garbage || strcmp(cf, current)) rank++; j = 0; while (getline(cfp)) { diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index 4e3827d..b8f956f 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)lp.h 8.1 (Berkeley) 6/6/93 + * @(#)lp.h 8.2 (Berkeley) 4/28/95 */ @@ -82,7 +82,7 @@ extern char *printer; /* printer name */ /* host machine name */ extern char host[MAXHOSTNAMELEN]; extern char *from; /* client's machine name */ -extern int sendtorem; /* are we sending to a remote? */ +extern int remote; /* true if sending files to a remote host */ extern char *printcapdb[]; /* printcap database array */ /* * Structure used for building a sorted list of control files. @@ -104,7 +104,7 @@ void displayq __P((int)); void dump __P((char *, char *, int)); void fatal __P((const char *, ...)); int getline __P((FILE *)); -int getport __P((char *)); +int getport __P((char *, int)); int getq __P((struct queue *(*[]))); void header __P((void)); void inform __P((char *)); @@ -120,4 +120,5 @@ void rmremote __P((void)); void show __P((char *, char *, int)); int startdaemon __P((char *)); void warn __P((void)); +void delay __P((int)); __END_DECLS diff --git a/usr.sbin/lpr/common_source/recvjob.c b/usr.sbin/lpr/common_source/recvjob.c index e199af1..35f946f 100644 --- a/usr.sbin/lpr/common_source/recvjob.c +++ b/usr.sbin/lpr/common_source/recvjob.c @@ -39,7 +39,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)recvjob.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95"; #endif /* not lint */ /* @@ -342,7 +342,7 @@ frecverr(msg, va_alist) va_dcl #endif { - extern char *fromb; + extern char fromb[]; va_list ap; #if __STDC__ va_start(ap, msg); diff --git a/usr.sbin/lpr/common_source/rmjob.c b/usr.sbin/lpr/common_source/rmjob.c index 74a94d8..bdfe853 100644 --- a/usr.sbin/lpr/common_source/rmjob.c +++ b/usr.sbin/lpr/common_source/rmjob.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)rmjob.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)rmjob.c 8.2 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> @@ -292,7 +292,7 @@ rmremote() register int i, rem; char buf[BUFSIZ]; - if (!sendtorem) + if (!remote) return; /* not sending to a remote machine */ /* @@ -313,7 +313,7 @@ rmremote() (void) sprintf(cp, " %d", requ[i]); } strcat(cp, "\n"); - rem = getport(RM); + rem = getport(RM, 0); if (rem < 0) { if (from != host) printf("%s: ", host); |