Date: Fri, 13 Jul 2001 14:00:03 -0400 From: Garance A Drosihn <drosih@rpi.edu> To: Anton Berezin <tobez@tobez.org> Cc: freebsd-print@bostonradio.org Subject: Re: cannot print to remote printer Message-ID: <p05101010b774e5526aad@[128.113.24.47]> In-Reply-To: <20010712121823.A10960@heechee.tobez.org> References: <lth8zikptx0.wl@hunter.munich.sgi.com> <p05101003b759266483c2@> <p05101003b759266483c2@[128.113.24.47]> <873d83pquy.wl@wilhelm.noname> <20010711214311.C2855@heechee.tobez.org> <p05101002b7729a5cd5fb@[128.113.24.47]> <p05101004b772a955584d@[128.113.24.47]> <20010712121823.A10960@heechee.tobez.org>
next in thread | previous in thread | raw e-mail | index | archive | help
At 12:18 PM +0200 7/12/01, Anton Berezin wrote:
>I would also propose to guard printjob.c wait calls from this sort of
>error in the future; after all, it *was* an action at a distance, and
>it was not strictly easy to find the culprit.
Here's a patch which I think covers all the bases mentioned so far.
I added Anton's suggested changes, and then looked at the code to
watch out for places which were checking the &status info returned
from wait. I want to do some testing of this on -current before I'll
commit it (I've already tested on -stable), and I'll probably switch
to using %m in syslog instead of %s+strerror[errno], but I think
this should be pretty close to the right fix to commit.
[warning: if this patch doesn't seem to apply, it'll be because my
email client added an extra blank on the front of some lines which
already start with a blank]
Index: lpd/lpd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/lpr/lpd/lpd.c,v
retrieving revision 1.26
diff -u -r1.26 lpd.c
--- lpd/lpd.c 2001/06/25 01:45:25 1.26
+++ lpd/lpd.c 2001/07/13 17:52:20
@@ -367,7 +367,12 @@
continue;
}
if (fork() == 0) {
- signal(SIGCHLD, SIG_IGN);
+ /*
+ * Note that printjob() also plays around with
+ * signal-handling routines, and may need to be
+ * changed when making changes to signal-handling.
+ */
+ signal(SIGCHLD, SIG_DFL);
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
Index: lpd/printjob.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/lpr/lpd/printjob.c,v
retrieving revision 1.38
diff -u -r1.38 printjob.c
--- lpd/printjob.c 2001/07/09 09:24:00 1.38
+++ lpd/printjob.c 2001/07/13 17:52:20
@@ -165,6 +165,14 @@
setgid(getegid());
pid = getpid(); /* for use with lprm */
setpgrp(0, pid);
+
+ /*
+ * At initial lpd startup, printjob may be called with various
+ * signal handlers in effect. After that initial startup, any
+ * calls to printjob will have a *different* set of signal-handlers
+ * in effect. Make sure all handlers are the ones we want.
+ */
+ signal(SIGCHLD, SIG_DFL);
signal(SIGHUP, abortpr);
signal(SIGINT, abortpr);
signal(SIGQUIT, abortpr);
@@ -284,6 +292,9 @@
(void) close(ofd);
while ((i = wait(NULL)) > 0 && i != ofilter)
;
+ if (i < 0)
+ syslog(LOG_WARNING, "%s:
unexpected wait() failure: %s",
+ pp->printer, strerror(errno));
ofilter = 0;
}
(void) close(pfd); /* close printer */
@@ -755,7 +766,10 @@
while ((pid =
wait3((int *)&status, WUNTRACED, 0)) > 0 && pid != ofilter)
;
- if (status.w_stopval != WSTOPPED) {
+ if (pid < 0)
+ syslog(LOG_WARNING, "%s: unexpected wait3()
failure: %s",
+ pp->printer, strerror(errno));
+ else if (status.w_stopval != WSTOPPED) {
(void) close(fi);
syslog(LOG_WARNING,
"%s: output filter died "
@@ -784,9 +798,15 @@
(void) close(fi);
if (child < 0)
status.w_retcode = 100;
- else
+ else {
while ((pid = wait((int *)&status)) > 0 && pid != child)
;
+ if (pid < 0) {
+ status.w_retcode = 100;
+ syslog(LOG_WARNING, "%s: wait() failure after
execv(%s): %s",
+ pp->printer, prog, strerror(errno));
+ }
+ }
child = 0;
prchild = 0;
if (stopped) { /* restart output filter */
@@ -1024,10 +1044,16 @@
(void) close(f);
if (ifilter < 0)
status.w_retcode = 100;
- else
+ else {
while ((pid = wait((int *)&status)) > 0 &&
pid != ifilter)
;
+ if (pid < 0) {
+ status.w_retcode = 100;
+ syslog(LOG_WARNING, "%s:
wait() failure after execv(%s): %s",
+ pp->printer,
pp->filters[LPF_INPUT], strerror(errno));
+ }
+ }
/* Copy the filter's output to "lf" logfile */
if ((fp = fopen(tempstderr, "r"))) {
while (fgets(buf, sizeof(buf), fp))
@@ -1083,6 +1109,9 @@
close(f);
while ((i = wait(NULL)) > 0 && i != ofilter)
;
+ if (i < 0)
+ syslog(LOG_WARNING, "%s: unexpected
wait() failure: %s",
+ pp->printer, strerror(errno));
ofilter = 0;
statrc = fstat(tfd, &stb); /* to find size
of tfile */
if (statrc < 0) {
--
Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu
Senior Systems Programmer or gad@freebsd.org
Rensselaer Polytechnic Institute or drosih@rpi.edu
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05101010b774e5526aad>
