X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/5f84f8f0e528cb7ec97122857c815fde73eccf85..90ede91282b3691d44d066225db5290cd3f236cc:/usr/src/usr.sbin/lpr/lpd/printjob.c diff --git a/usr/src/usr.sbin/lpr/lpd/printjob.c b/usr/src/usr.sbin/lpr/lpd/printjob.c index 0cded7bce5..314e36dc42 100644 --- a/usr/src/usr.sbin/lpr/lpd/printjob.c +++ b/usr/src/usr.sbin/lpr/lpd/printjob.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)printjob.c 4.11 (Berkeley) %G%"; +static char sccsid[] = "@(#)printjob.c 4.15 (Berkeley) %G%"; #endif /* @@ -24,10 +24,12 @@ static int prchild; /* id of pr process */ static int child; /* id of any filters */ static int ofilter; /* id of output filter, if any */ static int tof; /* true if at top of form */ +static int count; /* Number of files actually printed */ static int remote; /* true if sending files to remote */ +static char fromhost[32]; /* user's host machine */ static char logname[32]; /* user's login name */ -static char jobname[32]; /* job or file name */ +static char jobname[100]; /* job or file name */ static char class[32]; /* classification field */ static char width[10] = "-w"; /* page width in characters */ static char length[10] = "-l"; /* page length in lines */ @@ -53,7 +55,10 @@ printjob() dup(1); pid = getpid(); /* for use with lprm */ setpgrp(0, pid); + signal(SIGHUP, onintr); signal(SIGINT, onintr); + signal(SIGQUIT, onintr); + signal(SIGTERM, onintr); /* * uses short form file names @@ -64,7 +69,7 @@ printjob() } if (stat(LO, &stb) == 0 && (stb.st_mode & 0100)) exit(0); /* printing disabled */ - lfd = open(LO, O_WRONLY|O_CREAT|O_TRUNC, 0644); + lfd = open(LO, O_WRONLY|O_CREAT, 0644); if (lfd < 0) { log("cannot create %s", LO); exit(1); @@ -134,10 +139,9 @@ again: break; } } - /* - * Check to see if we should try reprinting the job. - */ - if (i > 0) { + if (i == 0) /* file ok and printed */ + count++; + else if (i > 0) { /* try reprinting the job */ log("restarting"); if (ofilter > 0) { kill(ofilter, SIGCONT); /* to be sure */ @@ -164,10 +168,12 @@ again: } if (nitems == 0) { /* no more work to do */ done: - if (!SF && !tof) - (void) write(ofd, FF, strlen(FF)); - if (TR != NULL) /* output trailer */ - (void) write(ofd, TR, strlen(TR)); + if (count > 0) { /* Files actually printed */ + if (!SF && !tof) + (void) write(ofd, FF, strlen(FF)); + if (TR != NULL) /* output trailer */ + (void) write(ofd, TR, strlen(TR)); + } exit(0); } goto again; @@ -248,13 +254,13 @@ printit(file) while (getline(cfp)) switch (line[0]) { case 'H': - strcpy(host, line+1); + strcpy(fromhost, line+1); if (class[0] == '\0') - strcpy(class, line+1); + strncpy(class, line+1, sizeof(class)-1); continue; case 'P': - strcpy(logname, line+1); + strncpy(logname, line+1, sizeof(logname)-1); if (RS) { /* restricted */ if (getpwnam(logname) == (struct passwd *)0) { bombed = 2; @@ -266,20 +272,20 @@ printit(file) case 'J': if (line[1] != '\0') - strcpy(jobname, line+1); + strncpy(jobname, line+1, sizeof(jobname)-1); else strcpy(jobname, " "); continue; case 'C': if (line[1] != '\0') - strcpy(class, line+1); + strncpy(class, line+1, sizeof(class)-1); else if (class[0] == '\0') gethostname(class, sizeof (class)); continue; case 'T': /* header title for pr */ - strcpy(title, line+1); + strncpy(title, line+1, sizeof(title)-1); continue; case 'L': /* identification line */ @@ -296,11 +302,11 @@ printit(file) continue; case 'W': /* page width */ - strcpy(width+2, line+1); + strncpy(width+2, line+1, sizeof(width)-3); continue; case 'I': /* indent amount */ - strcpy(indent+2, line+1); + strncpy(indent+2, line+1, sizeof(indent)-3); continue; default: /* some file to print */ @@ -337,7 +343,7 @@ pass2: */ (void) fclose(cfp); (void) unlink(file); - return(0); + return(bombed ? -1 : 0); } /* @@ -417,7 +423,7 @@ print(format, file) break; case 'l': /* like 'f' but pass control characters */ prog = IF; - av[1] = "-l"; + av[1] = "-c"; av[2] = width; av[3] = length; av[4] = indent; @@ -480,7 +486,7 @@ print(format, file) av[n++] = "-n"; av[n++] = logname; av[n++] = "-h"; - av[n++] = host; + av[n++] = fromhost; av[n++] = AF; av[n] = 0; fo = pfd; @@ -806,12 +812,12 @@ sendmail(bombed) cp++; else cp = MAIL; - sprintf(buf, "%s@%s", line+1, host); + sprintf(buf, "%s@%s", line+1, fromhost); execl(MAIL, cp, buf, 0); exit(0); } else if (stat > 0) { /* parent */ dup2(p[1], 1); - printf("To: %s\n", line+1); + printf("To: %s@%s\n", line+1, fromhost); printf("Subject: printer job\n\n"); printf("Your printer job "); if (*jobname) @@ -872,7 +878,7 @@ dofork(action) } /* - * Cleanup child processes when a SIGINT is caught. + * Cleanup child processes when a signal is caught. */ static onintr()