Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Apr 1995 14:50:02 -0700
From:      pritc003@maroon.tc.umn.edu
To:        freebsd-bugs
Subject:   bin/368: Lpd doesn't log errors after failed exec
Message-ID:  <199504262150.OAA27724@freefall.cdrom.com>
In-Reply-To: Your message of Wed, 26 Apr 1995 16:42:22 -0500 <199504262142.QAA01815@mpp.com>

next in thread | previous in thread | raw e-mail | index | archive | help

>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:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 26 14:50:01 1995
>Originator:     Mike Pritchard
>Organization:
>Release:        FreeBSD 2.1.0-Development i386
>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);
  		}
>Audit-Trail:
>Unformatted:





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199504262150.OAA27724>