don't fork off an output filter if it won't ever be used
[unix-history] / usr / src / usr.sbin / lpr / lpd / printjob.c
index 02659ed..347c2eb 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)printjob.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)printjob.c 5.11 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -66,7 +66,7 @@ char  length[10] = "-l";      /* page length in lines */
 char   pxwidth[10] = "-x";     /* page width in pixels */
 char   pxlength[10] = "-y";    /* page length in pixels */
 char   indent[10] = "-i0";     /* indentation size in characters */
 char   pxwidth[10] = "-x";     /* page width in pixels */
 char   pxlength[10] = "-y";    /* page length in pixels */
 char   indent[10] = "-i0";     /* indentation size in characters */
-char   tmpfile[] = "errsXXXXXX"; /* file name for filter output */
+char   tempfile[] = "errsXXXXXX"; /* file name for filter output */
 
 printjob()
 {
 
 printjob()
 {
@@ -93,7 +93,7 @@ printjob()
        signal(SIGQUIT, abortpr);
        signal(SIGTERM, abortpr);
 
        signal(SIGQUIT, abortpr);
        signal(SIGTERM, abortpr);
 
-       (void) mktemp(tmpfile);
+       (void) mktemp(tempfile);
 
        /*
         * uses short form file names
 
        /*
         * uses short form file names
@@ -211,7 +211,7 @@ again:
                        if (TR != NULL)         /* output trailer */
                                (void) write(ofd, TR, strlen(TR));
                }
                        if (TR != NULL)         /* output trailer */
                                (void) write(ofd, TR, strlen(TR));
                }
-               (void) unlink(tmpfile);
+               (void) unlink(tempfile);
                exit(0);
        }
        goto again;
                exit(0);
        }
        goto again;
@@ -428,6 +428,7 @@ print(format, file)
        register int n;
        register char *prog;
        int fi, fo;
        register int n;
        register char *prog;
        int fi, fo;
+       FILE *fp;
        char *av[15], buf[BUFSIZ];
        int pid, p[2], stopped = 0;
        union wait status;
        char *av[15], buf[BUFSIZ];
        int pid, p[2], stopped = 0;
        union wait status;
@@ -582,7 +583,7 @@ start:
        if ((child = dofork(DORETURN)) == 0) {  /* child */
                dup2(fi, 0);
                dup2(fo, 1);
        if ((child = dofork(DORETURN)) == 0) {  /* child */
                dup2(fi, 0);
                dup2(fo, 1);
-               n = open(tmpfile, O_WRONLY|O_CREAT|O_TRUNC, 0664);
+               n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0664);
                if (n >= 0)
                        dup2(n, 2);
                for (n = 3; n < NOFILE; n++)
                if (n >= 0)
                        dup2(n, 2);
                for (n = 3; n < NOFILE; n++)
@@ -606,6 +607,16 @@ start:
                }
        }
        tof = 0;
                }
        }
        tof = 0;
+
+       /* Copy filter output to "lf" logfile */
+       if (fp = fopen(tempfile, "r")) {
+               char tbuf[512];
+
+               while (fgets(buf, sizeof(buf), fp))
+                       fputs(buf, stderr);
+               close(fp);
+       }
+
        if (!WIFEXITED(status)) {
                syslog(LOG_WARNING, "%s: Daemon filter '%c' terminated (%d)",
                        printer, format, status.w_termsig);
        if (!WIFEXITED(status)) {
                syslog(LOG_WARNING, "%s: Daemon filter '%c' terminated (%d)",
                        printer, format, status.w_termsig);
@@ -949,8 +960,8 @@ sendmail(user, bombed)
                        printf("\ncould not be printed without an account on %s\n", host);
                        break;
                case FILTERERR:
                        printf("\ncould not be printed without an account on %s\n", host);
                        break;
                case FILTERERR:
-                       if (stat(tmpfile, &stb) < 0 || stb.st_size == 0 ||
-                           (fp = fopen(tmpfile, "r")) == NULL) {
+                       if (stat(tempfile, &stb) < 0 || stb.st_size == 0 ||
+                           (fp = fopen(tempfile, "r")) == NULL) {
                                printf("\nwas printed but had some errors\n");
                                break;
                        }
                                printf("\nwas printed but had some errors\n");
                                break;
                        }
@@ -1009,7 +1020,7 @@ dofork(action)
  */
 abortpr()
 {
  */
 abortpr()
 {
-       (void) unlink(tmpfile);
+       (void) unlink(tempfile);
        kill(0, SIGINT);
        if (ofilter > 0)
                kill(ofilter, SIGCONT);
        kill(0, SIGINT);
        if (ofilter > 0)
                kill(ofilter, SIGCONT);
@@ -1021,6 +1032,7 @@ abortpr()
 init()
 {
        int status;
 init()
 {
        int status;
+       char *s;
 
        if ((status = pgetent(line, printer)) < 0) {
                syslog(LOG_ERR, "can't open printer description file");
 
        if ((status = pgetent(line, printer)) < 0) {
                syslog(LOG_ERR, "can't open printer description file");
@@ -1058,38 +1070,8 @@ 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:
+       if (s = checkremote())
+               syslog(LOG_WARNING, s);
 
        AF = pgetstr("af", &bp);
        OF = pgetstr("of", &bp);
 
        AF = pgetstr("af", &bp);
        OF = pgetstr("of", &bp);
@@ -1128,7 +1110,7 @@ openpr()
        register int i, n;
        int resp;
 
        register int i, n;
        int resp;
 
-       if (*LP) {
+       if (!sendtorem && *LP) {
                for (i = 1; ; i = i < 32 ? i << 1 : i) {
                        pfd = open(LP, RW ? O_RDWR : O_WRONLY);
                        if (pfd >= 0)
                for (i = 1; ; i = i < 32 ? i << 1 : i) {
                        pfd = open(LP, RW ? O_RDWR : O_WRONLY);
                        if (pfd >= 0)
@@ -1176,7 +1158,7 @@ openpr()
        /*
         * Start up an output filter, if needed.
         */
        /*
         * Start up an output filter, if needed.
         */
-       if (OF) {
+       if (!remote && OF) {
                int p[2];
                char *cp;
 
                int p[2];
                char *cp;