X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/9d85c8615be940cbc0a42ed48a6dc33360194cd9..ca554fddefe71541fe082da0872a8c8658231bbf:/usr/src/usr.sbin/lpr/lpd/printjob.c?ds=sidebyside diff --git a/usr/src/usr.sbin/lpr/lpd/printjob.c b/usr/src/usr.sbin/lpr/lpd/printjob.c index 9eb5dda95e..347c2eb26a 100644 --- a/usr/src/usr.sbin/lpr/lpd/printjob.c +++ b/usr/src/usr.sbin/lpr/lpd/printjob.c @@ -3,15 +3,20 @@ * All rights reserved. * * Redistribution and use in source and binary forms are permitted - * provided that this notice is preserved and that due credit is given - * to the University of California at Berkeley. The name of the University - * may not be used to endorse or promote products derived from this - * software without specific prior written permission. This software - * is provided ``as is'' without express or implied warranty. + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint -static char sccsid[] = "@(#)printjob.c 5.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)printjob.c 5.11 (Berkeley) %G%"; #endif /* not lint */ /* @@ -22,6 +27,7 @@ static char sccsid[] = "@(#)printjob.c 5.5 (Berkeley) %G%"; */ #include "lp.h" +#include "pathnames.h" #define DORETURN 0 /* absorb fork error */ #define DOABORT 1 /* abort if dofork fails */ @@ -60,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 tmpfile[] = "errsXXXXXX"; /* file name for filter output */ +char tempfile[] = "errsXXXXXX"; /* file name for filter output */ printjob() { @@ -77,7 +83,7 @@ printjob() (void) close(2); /* set up log file */ if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) { syslog(LOG_ERR, "%s: %m", LF); - (void) open("/dev/null", O_WRONLY); + (void) open(_PATH_DEVNULL, O_WRONLY); } setgid(getegid()); pid = getpid(); /* for use with lprm */ @@ -87,7 +93,7 @@ printjob() signal(SIGQUIT, abortpr); signal(SIGTERM, abortpr); - (void) mktemp(tmpfile); + (void) mktemp(tempfile); /* * uses short form file names @@ -205,7 +211,7 @@ again: if (TR != NULL) /* output trailer */ (void) write(ofd, TR, strlen(TR)); } - (void) unlink(tmpfile); + (void) unlink(tempfile); exit(0); } goto again; @@ -213,11 +219,11 @@ again: char fonts[4][50]; /* fonts for troff */ -char ifonts[4][18] = { - "/usr/lib/vfont/R", - "/usr/lib/vfont/I", - "/usr/lib/vfont/B", - "/usr/lib/vfont/S" +char ifonts[4][40] = { + _PATH_VFONTR, + _PATH_VFONTI, + _PATH_VFONTB, + _PATH_VFONTS, }; /* @@ -422,6 +428,7 @@ print(format, file) 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; @@ -454,7 +461,7 @@ print(format, file) switch (format) { case 'p': /* print file using 'pr' */ if (IF == NULL) { /* use output filter */ - prog = PR; + prog = _PATH_PR; av[0] = "pr"; av[1] = width; av[2] = length; @@ -470,8 +477,9 @@ print(format, file) dup2(p[1], 1); /* pipe is stdout */ for (n = 3; n < NOFILE; n++) (void) close(n); - execl(PR, "pr", width, length, "-h", *title ? title : " ", 0); - syslog(LOG_ERR, "cannot execl %s", PR); + execl(_PATH_PR, "pr", width, length, + "-h", *title ? title : " ", 0); + syslog(LOG_ERR, "cannot execl %s", _PATH_PR); exit(2); } (void) close(p[1]); /* close output side */ @@ -513,7 +521,7 @@ print(format, file) } else { for (n = 0; n < 4; n++) { if (fonts[n][0] != '/') - (void) write(fo, "/usr/lib/vfont/", 15); + (void) write(fo, _PATH_VFONT, 15); (void) write(fo, fonts[n], strlen(fonts[n])); (void) write(fo, "\n", 1); } @@ -575,7 +583,7 @@ start: 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++) @@ -599,6 +607,16 @@ start: } } 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); @@ -916,12 +934,12 @@ sendmail(user, bombed) dup2(p[0], 0); for (i = 3; i < NOFILE; i++) (void) close(i); - if ((cp = rindex(MAIL, '/')) != NULL) + if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL) cp++; else - cp = MAIL; + cp = _PATH_SENDMAIL; sprintf(buf, "%s@%s", user, fromhost); - execl(MAIL, cp, buf, 0); + execl(_PATH_SENDMAIL, cp, buf, 0); exit(0); } else if (s > 0) { /* parent */ dup2(p[1], 1); @@ -942,8 +960,8 @@ sendmail(user, bombed) 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; } @@ -1002,7 +1020,7 @@ dofork(action) */ abortpr() { - (void) unlink(tmpfile); + (void) unlink(tempfile); kill(0, SIGINT); if (ofilter > 0) kill(ofilter, SIGCONT); @@ -1014,6 +1032,7 @@ abortpr() init() { int status; + char *s; if ((status = pgetent(line, printer)) < 0) { syslog(LOG_ERR, "can't open printer description file"); @@ -1023,7 +1042,7 @@ init() exit(1); } if ((LP = pgetstr("lp", &bp)) == NULL) - LP = DEFDEVLP; + LP = _PATH_DEFDEVLP; if ((RP = pgetstr("rp", &bp)) == NULL) RP = DEFLP; if ((LO = pgetstr("lo", &bp)) == NULL) @@ -1031,9 +1050,9 @@ init() if ((ST = pgetstr("st", &bp)) == NULL) ST = DEFSTAT; if ((LF = pgetstr("lf", &bp)) == NULL) - LF = DEFLOGF; + LF = _PATH_CONSOLE; if ((SD = pgetstr("sd", &bp)) == NULL) - SD = DEFSPOOL; + SD = _PATH_DEFSPOOL; if ((DU = pgetnum("du")) < 0) DU = DEFUID; if ((FF = pgetstr("ff", &bp)) == NULL) @@ -1051,38 +1070,8 @@ init() 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); @@ -1121,7 +1110,7 @@ openpr() 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) @@ -1169,7 +1158,7 @@ openpr() /* * Start up an output filter, if needed. */ - if (OF) { + if (!remote && OF) { int p[2]; char *cp; @@ -1249,14 +1238,6 @@ setty() syslog(LOG_ERR, "%s: ioctl(TIOCSETP): %m", printer); exit(1); } - if (XC || XS) { - int ldisc = NTTYDISC; - - if (ioctl(pfd, TIOCSETD, &ldisc) < 0) { - syslog(LOG_ERR, "%s: ioctl(TIOCSETD): %m", printer); - exit(1); - } - } if (XC) { if (ioctl(pfd, TIOCLBIC, &XC) < 0) { syslog(LOG_ERR, "%s: ioctl(TIOCLBIC): %m", printer);