Can now specify both lp= and rm=/rp= in same printcap entry; lpd
authorThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Tue, 12 Nov 1985 07:34:05 +0000 (23:34 -0800)
committerThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Tue, 12 Nov 1985 07:34:05 +0000 (23:34 -0800)
will figure out if printer is on local machine or not and do the right thing.

SCCS-vsn: usr.sbin/lpr/common_source/displayq.c 5.2
SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 5.3

usr/src/usr.sbin/lpr/common_source/displayq.c
usr/src/usr.sbin/lpr/lpd/printjob.c

index 6ba25a2..b7d3ad0 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)displayq.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)displayq.c 5.1 (Berkeley) 6/6/85";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -71,6 +71,38 @@ displayq(format)
                ST = DEFSTAT;
        RM = pgetstr("rm", &bp);
 
                ST = DEFSTAT;
        RM = pgetstr("rm", &bp);
 
+       /*
+        * Figure out whether the local machine is the same as the remote 
+        * machine entry (if it exists).  If not, then ignore the local
+        * queue information.
+        */
+        if (RM != (char *) NULL) {
+               char name[256];
+               struct hostent *hp;
+
+               /* get the standard network name of the local host */
+               gethostname(name, sizeof(name));
+               name[sizeof(name)-1] = '\0';
+               hp = gethostbyname(name);
+               if (hp == (struct hostent *) NULL) {
+                   printf("unable to get network name for local machine %s\n",
+                       name);
+                   goto localcheck_done;
+               } else strcpy(name, hp->h_name);
+
+               /* get the network standard name of RM */
+               hp = gethostbyname(RM);
+               if (hp == (struct hostent *) NULL) {
+                   printf("unable to get hostname for remote machine %s\n",
+                       RM);
+                   goto localcheck_done;
+               }
+
+               /* if printer is not on local machine, ignore LP */
+               if (strcmp(name, hp->h_name) != 0) *LP = '\0';
+       }
+localcheck_done:
+
        /*
         * If there is no local printer, then print the queue on
         * the remote machine and then what's in the queue here.
        /*
         * If there is no local printer, then print the queue on
         * the remote machine and then what's in the queue here.
index c96073f..4defb30 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)printjob.c 5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)printjob.c 5.2 (Berkeley) 9/17/85";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -1004,10 +1004,13 @@ init()
 {
        int status;
 
 {
        int status;
 
-       if ((status = pgetent(line, printer)) < 0)
-               fatal("can't open printer description file");
-       else if (status == 0)
-               fatal("unknown printer");
+       if ((status = pgetent(line, printer)) < 0) {
+               syslog(LOG_ERR, "can't open printer description file");
+               exit(1);
+       } else if (status == 0) {
+               syslog(LOG_ERR, "unknown printer: %s", printer);
+               exit(1);
+       }
        if ((LP = pgetstr("lp", &bp)) == NULL)
                LP = DEFDEVLP;
        if ((RP = pgetstr("rp", &bp)) == NULL)
        if ((LP = pgetstr("lp", &bp)) == NULL)
                LP = DEFDEVLP;
        if ((RP = pgetstr("rp", &bp)) == NULL)
@@ -1037,6 +1040,39 @@ init()
                PY = 0;
        sprintf(&pxlength[2], "%d", PY);
        RM = pgetstr("rm", &bp);
                PY = 0;
        sprintf(&pxlength[2], "%d", PY);
        RM = pgetstr("rm", &bp);
+       /*
+        * Figure out whether the local machine is the same as the remote 
+        * machine entry (if it exists).  If not, then ignore the local
+        * queue information.
+        */
+        if (RM != (char *) NULL) {
+               char name[256];
+               struct hostent *hp;
+
+               /* get the standard network name of the local host */
+               gethostname(name, sizeof(name));
+               name[sizeof(name)-1] = '\0';
+               hp = gethostbyname(name);
+               if (hp == (struct hostent *) NULL) {
+                   syslog(LOG_ERR,
+                       "unable to get network name for local machine %s",
+                       name);
+                   goto localcheck_done;
+               } else strcpy(name, hp->h_name);
+
+               /* get the standard network name of RM */
+               hp = gethostbyname(RM);
+               if (hp == (struct hostent *) NULL) {
+                   syslog(LOG_ERR,
+                       "unable to get hostname for remote machine %s", RM);
+                   goto localcheck_done;
+               }
+
+               /* if printer is not on local machine, ignore LP */
+               if (strcmp(name, hp->h_name) != 0) *LP = '\0';
+       }
+localcheck_done:
+
        AF = pgetstr("af", &bp);
        OF = pgetstr("of", &bp);
        IF = pgetstr("if", &bp);
        AF = pgetstr("af", &bp);
        OF = pgetstr("of", &bp);
        IF = pgetstr("if", &bp);