printjob.c (117587) | printjob.c (118881) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 31 unchanged lines hidden (view full) --- 40 41#if 0 42#ifndef lint 43static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95"; 44#endif /* not lint */ 45#endif 46 47#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 31 unchanged lines hidden (view full) --- 40 41#if 0 42#ifndef lint 43static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95"; 44#endif /* not lint */ 45#endif 46 47#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ |
48__FBSDID("$FreeBSD: head/usr.sbin/lpr/lpd/printjob.c 117587 2003-07-14 19:59:33Z gad $"); | 48__FBSDID("$FreeBSD: head/usr.sbin/lpr/lpd/printjob.c 118881 2003-08-13 20:31:33Z gad $"); |
49 50/* 51 * printjob -- print jobs in the queue. 52 * 53 * NOTE: the lock file is used to pass information to lpq and lprm. 54 * it does not need to be removed because file locks are dynamic. 55 */ 56 --- 101 unchanged lines hidden (view full) --- 158 struct jobqueue **queue; 159 register int i, nitems; 160 off_t pidoff; 161 pid_t printpid; 162 int errcnt, jobcount, tempfd; 163 164 jobcount = 0; 165 init(pp); /* set up capabilities */ | 49 50/* 51 * printjob -- print jobs in the queue. 52 * 53 * NOTE: the lock file is used to pass information to lpq and lprm. 54 * it does not need to be removed because file locks are dynamic. 55 */ 56 --- 101 unchanged lines hidden (view full) --- 158 struct jobqueue **queue; 159 register int i, nitems; 160 off_t pidoff; 161 pid_t printpid; 162 int errcnt, jobcount, tempfd; 163 164 jobcount = 0; 165 init(pp); /* set up capabilities */ |
166 (void) write(1, "", 1); /* ack that daemon is started */ 167 (void) close(2); /* set up log file */ | 166 (void) write(STDOUT_FILENO, "", 1); /* ack that daemon is started */ 167 (void) close(STDERR_FILENO); /* set up log file */ |
168 if (open(pp->log_file, O_WRONLY|O_APPEND, LOG_FILE_MODE) < 0) { 169 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer, 170 pp->log_file); 171 (void) open(_PATH_DEVNULL, O_WRONLY); 172 } 173 setgid(getegid()); 174 printpid = getpid(); /* for use with lprm */ 175 setpgrp(0, printpid); --- 483 unchanged lines hidden (view full) --- 659 av[i++] = *locale ? locale : "C"; 660 av[i++] = "-F"; 661 av[i] = 0; 662 fo = ofd; 663 goto start; 664 } 665 pipe(p); 666 if ((prchild = dofork(pp, DORETURN)) == 0) { /* child */ | 168 if (open(pp->log_file, O_WRONLY|O_APPEND, LOG_FILE_MODE) < 0) { 169 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer, 170 pp->log_file); 171 (void) open(_PATH_DEVNULL, O_WRONLY); 172 } 173 setgid(getegid()); 174 printpid = getpid(); /* for use with lprm */ 175 setpgrp(0, printpid); --- 483 unchanged lines hidden (view full) --- 659 av[i++] = *locale ? locale : "C"; 660 av[i++] = "-F"; 661 av[i] = 0; 662 fo = ofd; 663 goto start; 664 } 665 pipe(p); 666 if ((prchild = dofork(pp, DORETURN)) == 0) { /* child */ |
667 dup2(fi, 0); /* file is stdin */ 668 dup2(p[1], 1); /* pipe is stdout */ | 667 dup2(fi, STDIN_FILENO); /* file is stdin */ 668 dup2(p[1], STDOUT_FILENO); /* pipe is stdout */ |
669 closelog(); 670 closeallfds(3); 671 execl(_PATH_PR, "pr", width, length, 672 "-h", *title ? title : " ", 673 "-L", *locale ? locale : "C", 674 "-F", (char *)0); 675 syslog(LOG_ERR, "cannot execl %s", _PATH_PR); 676 exit(2); --- 121 unchanged lines hidden (view full) --- 798 pp->printer, of_pid, WEXITSTATUS(wstatus), 799 WTERMSIG(wstatus)); 800 return (REPRINT); 801 } 802 stopped++; 803 } 804start: 805 if ((child = dofork(pp, DORETURN)) == 0) { /* child */ | 669 closelog(); 670 closeallfds(3); 671 execl(_PATH_PR, "pr", width, length, 672 "-h", *title ? title : " ", 673 "-L", *locale ? locale : "C", 674 "-F", (char *)0); 675 syslog(LOG_ERR, "cannot execl %s", _PATH_PR); 676 exit(2); --- 121 unchanged lines hidden (view full) --- 798 pp->printer, of_pid, WEXITSTATUS(wstatus), 799 WTERMSIG(wstatus)); 800 return (REPRINT); 801 } 802 stopped++; 803 } 804start: 805 if ((child = dofork(pp, DORETURN)) == 0) { /* child */ |
806 dup2(fi, 0); 807 dup2(fo, 1); | 806 dup2(fi, STDIN_FILENO); 807 dup2(fo, STDOUT_FILENO); |
808 /* setup stderr for the filter (child process) 809 * so it goes to our temporary errors file */ 810 n = open(tempstderr, O_WRONLY|O_TRUNC, 0664); 811 if (n >= 0) | 808 /* setup stderr for the filter (child process) 809 * so it goes to our temporary errors file */ 810 n = open(tempstderr, O_WRONLY|O_TRUNC, 0664); 811 if (n >= 0) |
812 dup2(n, 2); | 812 dup2(n, STDERR_FILENO); |
813 closelog(); 814 closeallfds(3); 815 execv(prog, av); 816 syslog(LOG_ERR, "%s: cannot execv(%s): %m", pp->printer, 817 prog); 818 exit(2); 819 } 820 (void) close(fi); --- 459 unchanged lines hidden (view full) --- 1280 */ 1281 1282 /* 1283 * Setup stdin, stdout, and stderr as we want them when the filter 1284 * is running. Stderr is setup so it points to a temporary errors 1285 * file, and the parent process will copy that temporary file to 1286 * the real logfile after the filter completes. 1287 */ | 813 closelog(); 814 closeallfds(3); 815 execv(prog, av); 816 syslog(LOG_ERR, "%s: cannot execv(%s): %m", pp->printer, 817 prog); 818 exit(2); 819 } 820 (void) close(fi); --- 459 unchanged lines hidden (view full) --- 1280 */ 1281 1282 /* 1283 * Setup stdin, stdout, and stderr as we want them when the filter 1284 * is running. Stderr is setup so it points to a temporary errors 1285 * file, and the parent process will copy that temporary file to 1286 * the real logfile after the filter completes. 1287 */ |
1288 dup2(infd, 0); 1289 dup2(outfd, 1); | 1288 dup2(infd, STDIN_FILENO); 1289 dup2(outfd, STDOUT_FILENO); |
1290 errfd = open(tempstderr, O_WRONLY|O_TRUNC, 0664); 1291 if (errfd >= 0) | 1290 errfd = open(tempstderr, O_WRONLY|O_TRUNC, 0664); 1291 if (errfd >= 0) |
1292 dup2(errfd, 2); | 1292 dup2(errfd, STDERR_FILENO); |
1293 closelog(); 1294 closeallfds(3); 1295 execv(f_cmd, f_av); 1296 syslog(LOG_ERR, "%s: cannot execv(%s): %m", pp->printer, f_cmd); 1297 exit(2); 1298 /* NOTREACHED */ 1299} 1300 --- 132 unchanged lines hidden (view full) --- 1433 register int i; 1434 int p[2], s; 1435 register const char *cp; 1436 struct stat stb; 1437 FILE *fp; 1438 1439 pipe(p); 1440 if ((s = dofork(pp, DORETURN)) == 0) { /* child */ | 1293 closelog(); 1294 closeallfds(3); 1295 execv(f_cmd, f_av); 1296 syslog(LOG_ERR, "%s: cannot execv(%s): %m", pp->printer, f_cmd); 1297 exit(2); 1298 /* NOTREACHED */ 1299} 1300 --- 132 unchanged lines hidden (view full) --- 1433 register int i; 1434 int p[2], s; 1435 register const char *cp; 1436 struct stat stb; 1437 FILE *fp; 1438 1439 pipe(p); 1440 if ((s = dofork(pp, DORETURN)) == 0) { /* child */ |
1441 dup2(p[0], 0); | 1441 dup2(p[0], STDIN_FILENO); |
1442 closelog(); 1443 closeallfds(3); 1444 if ((cp = strrchr(_PATH_SENDMAIL, '/')) != NULL) 1445 cp++; 1446 else 1447 cp = _PATH_SENDMAIL; 1448 execl(_PATH_SENDMAIL, cp, "-t", (char *)0); 1449 _exit(0); 1450 } else if (s > 0) { /* parent */ | 1442 closelog(); 1443 closeallfds(3); 1444 if ((cp = strrchr(_PATH_SENDMAIL, '/')) != NULL) 1445 cp++; 1446 else 1447 cp = _PATH_SENDMAIL; 1448 execl(_PATH_SENDMAIL, cp, "-t", (char *)0); 1449 _exit(0); 1450 } else if (s > 0) { /* parent */ |
1451 dup2(p[1], 1); | 1451 dup2(p[1], STDOUT_FILENO); |
1452 printf("To: %s@%s\n", userid, origin_host); 1453 printf("Subject: %s printer job \"%s\"\n", pp->printer, 1454 *jobname ? jobname : "<unknown>"); 1455 printf("Reply-To: root@%s\n\n", local_host); 1456 printf("Your printer job "); 1457 if (*jobname) 1458 printf("(%s) ", jobname); 1459 --- 24 unchanged lines hidden (view full) --- 1484 putchar(i); 1485 (void) fclose(fp); 1486 break; 1487 case ACCESS: 1488 cp = "ACCESS"; 1489 printf("\nwas not printed because it was not linked to the original file\n"); 1490 } 1491 fflush(stdout); | 1452 printf("To: %s@%s\n", userid, origin_host); 1453 printf("Subject: %s printer job \"%s\"\n", pp->printer, 1454 *jobname ? jobname : "<unknown>"); 1455 printf("Reply-To: root@%s\n\n", local_host); 1456 printf("Your printer job "); 1457 if (*jobname) 1458 printf("(%s) ", jobname); 1459 --- 24 unchanged lines hidden (view full) --- 1484 putchar(i); 1485 (void) fclose(fp); 1486 break; 1487 case ACCESS: 1488 cp = "ACCESS"; 1489 printf("\nwas not printed because it was not linked to the original file\n"); 1490 } 1491 fflush(stdout); |
1492 (void) close(1); | 1492 (void) close(STDOUT_FILENO); |
1493 } else { 1494 syslog(LOG_WARNING, "unable to send mail to %s: %m", userid); 1495 return; 1496 } 1497 (void) close(p[0]); 1498 (void) close(p[1]); 1499 wait(NULL); 1500 syslog(LOG_INFO, "mail sent to user %s about job %s on printer %s (%s)", --- 175 unchanged lines hidden (view full) --- 1676 */ 1677 if (pp->filters[LPF_OUTPUT] && !pp->filters[LPF_INPUT] && !of_pid) { 1678 pipe(p); 1679 if (pp->remote) { 1680 strcpy(tfile, TFILENAME); 1681 tfd = mkstemp(tfile); 1682 } 1683 if ((of_pid = dofork(pp, DOABORT)) == 0) { /* child */ | 1493 } else { 1494 syslog(LOG_WARNING, "unable to send mail to %s: %m", userid); 1495 return; 1496 } 1497 (void) close(p[0]); 1498 (void) close(p[1]); 1499 wait(NULL); 1500 syslog(LOG_INFO, "mail sent to user %s about job %s on printer %s (%s)", --- 175 unchanged lines hidden (view full) --- 1676 */ 1677 if (pp->filters[LPF_OUTPUT] && !pp->filters[LPF_INPUT] && !of_pid) { 1678 pipe(p); 1679 if (pp->remote) { 1680 strcpy(tfile, TFILENAME); 1681 tfd = mkstemp(tfile); 1682 } 1683 if ((of_pid = dofork(pp, DOABORT)) == 0) { /* child */ |
1684 dup2(p[0], 0); /* pipe is std in */ | 1684 dup2(p[0], STDIN_FILENO); /* pipe is std in */ |
1685 /* tfile/printer is stdout */ | 1685 /* tfile/printer is stdout */ |
1686 dup2(pp->remote ? tfd : pfd, 1); | 1686 dup2(pp->remote ? tfd : pfd, STDOUT_FILENO); |
1687 closelog(); 1688 closeallfds(3); 1689 if ((cp = strrchr(pp->filters[LPF_OUTPUT], '/')) == NULL) 1690 cp = pp->filters[LPF_OUTPUT]; 1691 else 1692 cp++; 1693 execl(pp->filters[LPF_OUTPUT], cp, width, length, 1694 (char *)0); --- 198 unchanged lines hidden --- | 1687 closelog(); 1688 closeallfds(3); 1689 if ((cp = strrchr(pp->filters[LPF_OUTPUT], '/')) == NULL) 1690 cp = pp->filters[LPF_OUTPUT]; 1691 else 1692 cp++; 1693 execl(pp->filters[LPF_OUTPUT], cp, width, length, 1694 (char *)0); --- 198 unchanged lines hidden --- |