From mpp@mpp.com  Wed Apr 26 14:43:26 1995
Received: from mpp.com (dialup-5-134.gw.umn.edu [128.101.96.134])
          by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id OAA27580
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Apr 1995 14:43:19 -0700
Received: (from mpp@localhost) by mpp.com (8.6.11/8.6.9) id QAA01815; Wed, 26 Apr 1995 16:42:22 -0500
Message-Id: <199504262142.QAA01815@mpp.com>
Date: Wed, 26 Apr 1995 16:42:22 -0500
From: pritc003@maroon.tc.umn.edu
Reply-To: pritc003@maroon.tc.umn.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: Lpd doesn't log errors after failed exec
X-Send-Pr-Version: 3.2

>Number:         368
>Category:       bin
>Synopsis:       Lpd doesn't log errors after failed exec
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs (FreeBSD bugs mailing list)
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 26 14:50:01 1995
>Closed-Date:    Wed Apr 26 21:56:40 PDT 1995
>Last-Modified:
>Originator:     Mike Pritchard
>Release:        FreeBSD 2.1.0-Development i386
>Organization:
>Environment:

>Description:

If an exec done by lpd fails, nothing is sent to the system log
indicating what went wrong.  This is because lpd closes all of 
the file descriptors before doing the exec, thus closing the syslog
file descriptor in the process.

>How-To-Repeat:

If you are using an output filter (e.g. apsfilter), make it so that
the output filter can't be executed and then queue something up
with 'lpr'.  The file will go down a black hole and there will be
no trace in any of the system logs as to what happened.

You should also be able to duplicate this by making 'pr' unavailable
and running 'lpr -p /etc/motd' if you are not using an output filter.

>Fix:
	
This patch to /usr/src/usr.sbin/lpr/lpd/printjob.c fixes lpd to
properly close the system log before doing the exec, and then
re-opening it if the exec fails.  This will allow failed execs
to be properly logged.

*** orig/printjob.c	Fri Apr 14 08:27:42 1995
--- printjob.c	Wed Apr 26 16:27:20 1995
***************
*** 538,547 ****
--- 538,549 ----
  		if ((prchild = dofork(DORETURN)) == 0) {	/* child */
  			dup2(fi, 0);		/* file is stdin */
  			dup2(p[1], 1);		/* pipe is stdout */
+ 			closelog();
  			for (n = 3; n < NOFILE; n++)
  				(void) close(n);
  			execl(_PATH_PR, "pr", width, length,
  			    "-h", *title ? title : " ", "-F", 0);
+ 			openlog("lpd", LOG_PID, LOG_LPR);
  			syslog(LOG_ERR, "cannot execl %s", _PATH_PR);
  			exit(2);
  		}
***************
*** 651,659 ****
--- 653,663 ----
  		n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0664);
  		if (n >= 0)
  			dup2(n, 2);
+ 		closelog();
  		for (n = 3; n < NOFILE; n++)
  			(void) close(n);
  		execv(prog, av);
+ 		openlog("lpd", LOG_PID, LOG_LPR);
  		syslog(LOG_ERR, "cannot execv %s", prog);
  		exit(2);
  	}
***************
*** 1008,1013 ****
--- 1012,1018 ----
  	pipe(p);
  	if ((s = dofork(DORETURN)) == 0) {		/* child */
  		dup2(p[0], 0);
+ 		closelog();
  		for (i = 3; i < NOFILE; i++)
  			(void) close(i);
  		if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL)
***************
*** 1016,1021 ****
--- 1021,1028 ----
  			cp = _PATH_SENDMAIL;
  		sprintf(buf, "%s@%s", user, fromhost);
  		execl(_PATH_SENDMAIL, cp, buf, 0);
+ 		openlog("lpd", LOG_PID, LOG_LPR);
+ 		syslog(LOG_ERR, "cannot execl %s", _PATH_SENDMAIL);
  		exit(0);
  	} else if (s > 0) {				/* parent */
  		dup2(p[1], 1);
***************
*** 1252,1257 ****
--- 1259,1265 ----
  		if ((ofilter = dofork(DOABORT)) == 0) {	/* child */
  			dup2(p[0], 0);		/* pipe is std in */
  			dup2(pfd, 1);		/* printer is std out */
+ 			closelog();
  			for (i = 3; i < NOFILE; i++)
  				(void) close(i);
  			if ((cp = rindex(OF, '/')) == NULL)
***************
*** 1259,1264 ****
--- 1267,1273 ----
  			else
  				cp++;
  			execl(OF, cp, width, length, 0);
+ 			openlog("lpd", LOG_PID, LOG_LPR);
  			syslog(LOG_ERR, "%s: %s: %m", printer, OF);
  			exit(1);
  		}
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jkh 
State-Changed-When: Wed Apr 26 21:56:40 PDT 1995 
State-Changed-Why:  
The fix was applied to -current 
>Unformatted:



