From owner-freebsd-current Fri Jul 13 11: 0:18 2001 Delivered-To: freebsd-current@freebsd.org Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by hub.freebsd.org (Postfix) with ESMTP id A829837B406 for ; Fri, 13 Jul 2001 11:00:12 -0700 (PDT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.acs.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.11.3/8.11.3) with ESMTP id f6DI08x151602; Fri, 13 Jul 2001 14:00:08 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: <20010712121823.A10960@heechee.tobez.org> References: <873d83pquy.wl@wilhelm.noname> <20010711214311.C2855@heechee.tobez.org> <20010712121823.A10960@heechee.tobez.org> Date: Fri, 13 Jul 2001 14:00:03 -0400 To: Anton Berezin From: Garance A Drosihn Subject: Re: cannot print to remote printer Cc: freebsd-print@bostonradio.org Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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