🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.protocols.appletalk
Article #5698

Bug fixes to CAP program "papif"

#5698
From: Jeff Stearns
Date: Mon, 10 Apr 1989 18:35
141 lines
4536 bytes
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.
Technical Details
Message-ID: <7651@fluke.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!jeff

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!jeff
From: jeff@tc.fluke.COM (Jeff Stearns)
Newsgroups: comp.protocols.appletalk
Subject: Bug fixes to CAP program "papif"
Keywords: CAP papif appletalk
Message-ID: <7651@fluke.COM>
Date: 10 Apr 89 18:35:38 GMT
Sender: news@tc.fluke.COM
Organization: John Fluke Mfg. Co., Inc., Everett, WA
Lines: 141