jeff@tc.fluke.COM (Jeff Stearns) (04/11/89)
While installing the new CAP version 5.00 release, I noticed a few bugs in the "papif" program: - Papif doesn't work when its input comes from a pipe, tty, or socket. - Some log messages are written twice to the logfile. - The map_cr_to_lf option doesn't work. - The "idle bug" recovery code contains some inappropriate wired-in-pathnames. Here are patches to fix all four bugs. Your line numbers may vary; my version has undergone other stylistic changes which aren't shown here. With these fixes in place, papif runs quite reliably under 4.3BSD. Jeff Stearns jeff@tc.fluke.COM John Fluke Mfg. Co, Inc. (206) 356-5064 --------------------------------------------------------------------------- *** /tmp/,RCSt1a01173 Mon Apr 10 11:18:32 1989 --- /tmp/papif.c Mon Apr 10 11:17:31 1989 *************** *** 715,721 exit(lpd_ERRORS); if (precnt < wantcnt) exit(lpd_OK); ! while ((cnt = read(fileno(stdin), buf, sizeof(buf))) > 0) /* dangerous */ if (map_crtolf) { for (i = 0, p = buf; i < cnt; i++) --- 702,712 ----- exit(lpd_ERRORS); if (precnt < wantcnt) exit(lpd_OK); ! /* ! * The distributed code contained TWO separate bugs in this while loop. ! * Check carefully; there might be more! jeff@tc.fluke.com 7-Apr-89. ! */ ! while ((cnt = read(fileno(stdin), buf, sizeof(buf))) > 0) { /* dangerous */ if (map_crtolf) { for (i = 0, p = buf; i < cnt; i++, p++) { *************** *** 718,724 while ((cnt = read(fileno(stdin), buf, sizeof(buf))) > 0) /* dangerous */ if (map_crtolf) { ! for (i = 0, p = buf; i < cnt; i++) if (*p == '\r') *p = '\n'; } --- 709,715 ----- while ((cnt = read(fileno(stdin), buf, sizeof(buf))) > 0) { /* dangerous */ if (map_crtolf) { ! for (i = 0, p = buf; i < cnt; i++, p++) { if (*p == '\r') *p = '\n'; } *************** *** 721,726 for (i = 0, p = buf; i < cnt; i++) if (*p == '\r') *p = '\n'; } if (write(fileno(stdout), buf, cnt) < 0) exit(lpd_ERRORS); --- 712,718 ----- for (i = 0, p = buf; i < cnt; i++, p++) { if (*p == '\r') *p = '\n'; + } } if (write(fileno(stdout), buf, cnt) < 0) exit(lpd_ERRORS); *************** *** 724,729 } if (write(fileno(stdout), buf, cnt) < 0) exit(lpd_ERRORS); exit(cnt < 0 ? lpd_ERRORS : lpd_OK); } --- 716,722 ----- } if (write(fileno(stdout), buf, cnt) < 0) exit(lpd_ERRORS); + } exit(cnt < 0 ? lpd_ERRORS : lpd_OK); } *************** *** 1131,1137 unlink("/tmp/papifidletest"); for (i = 0 ; i < NSIG ; i++) signal(i, SIG_IGN); ! sprintf(retry, "(/usr/bin/sleep 2;/etc/lpc abort %s;/usr/bin/sleep 2;/etc/lpc start %s)&", printer, printer); system(retry); exit(lpd_REPRINT); --- 1124,1130 ----- unlink("/tmp/papifidletest"); for (i = 0 ; i < NSIG ; i++) signal(i, SIG_IGN); ! sprintf(retry, "(PATH=/bin:/usr/bin:/usr/ucb:/usr/etc:/usr/local:/etc; sleep 2;lpc abort %s;sleep 2;lpc start %s)&", printer, printer); system(retry); exit(lpd_REPRINT); *************** *** 1358,1363 fprintf(jobout, fmt, a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,af); fprintf(stderr, fmt, a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,af); #endif } /* --- 1392,1404 ----- fprintf(stderr, "%d ", getpid()); fprintf(stderr, fmt, a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,af); #endif + /* + * Keep stdio buffers flushed to avoid double-output after fork(): + */ + if (jobout) { + fflush(jobout); + } + fflush(stderr); } /* -- Jeff Stearns John Fluke Mfg. Co, Inc. (206) 356-5064 jeff@tc.fluke.COM {uw-beaver,microsoft,sun}!fluke!jeff PS - Calling all users of the Vitalink TransLAN IV Ethernet bridge! Please drop me a line.
Bowman@SCIENCE.UTAH.EDU (Pieter) (04/12/89)
Jeff, After seeing your message about bugs being fixed I checked my own papif source and found that those bugs had already been fixed. You might want to get the following files from cunixc.cc.columbia.edu or some other source (I can send them if you would like [they are small]). -rw-r--r-- 1 126 6058 May 25 1988 cpr.0001 -rw-r--r-- 1 126 7575 Jun 5 1988 cpr.0002 -rw-r--r-- 1 126 6089 Jul 27 1988 cpr.0003 -r--r--r-- 1 126 2328 Sep 9 1988 cpr.0004 -rw-r--r-- 1 126 965 Oct 12 1988 cpr.0005 These are the known bugs reported by Charlie Kim and the folks at columbia. However, you do have a couple of fixes they don't. Thanks for the patches. Pieter bowman@science.utah.edu -------