smk (12/30/82)
I found another bug in lpd.c. There is an exit that doesn't first remove the LOCK file. Here is my diff to lpd.c that I have so far. Any other fixes you may have as far as the printer locking up? I'd like to hear of them. I'll post these to the net later if they aren't complete rewrites of lpr/lpd/lpf/... *** lpd.c.orig Thu Jul 2 06:18:02 1981 --- lpd.c Wed Dec 29 18:04:40 1982 *************** *** 82,87 ptr = top; top->next = top; if ( (fp = fopen(SPOOL_DIR,"r")) == NULL ) exit(1); while (fread(&dbuf, sizeof dbuf, 1, fp) == 1) { --- 82,91 ----- ptr = top; top->next = top; if ( (fp = fopen(SPOOL_DIR,"r")) == NULL ) + #ifdef MITRE + { + /* Don't forget to remove LOCK any time we exit. */ + unlink (LOCK); exit(1); } #else *************** *** 83,88 top->next = top; if ( (fp = fopen(SPOOL_DIR,"r")) == NULL ) exit(1); while (fread(&dbuf, sizeof dbuf, 1, fp) == 1) { if (dbuf.d_ino==0 || dbuf.d_name[0]!='d' || dbuf.d_name[1]!='f') --- 87,96 ----- /* Don't forget to remove LOCK any time we exit. */ unlink (LOCK); exit(1); + } + #else + exit(1); + #endif while (fread(&dbuf, sizeof dbuf, 1, fp) == 1) { if (dbuf.d_ino==0 || dbuf.d_name[0]!='d' || dbuf.d_name[1]!='f') *************** *** 111,116 ptr = top; top = top->next; cfree(ptr); return(sp); } --- 119,128 ----- ptr = top; top = top->next; cfree(ptr); + #ifdef MITRE + /* Forgot to close the spool directory. */ + (void) fclose (fp); + #endif return(sp); } *************** *** 159,164 continue; case 'F': if (send()) return(1); continue; --- 171,186 ----- continue; case 'F': + #ifdef MITRE + /* We must close the open file when the printer + goes off-line, or pretty soon (after 15 attempts + to retry) the file limit is exceeded and the + lock doesn't go away. */ + if (send()) { + (void) fclose(dfb); + return(1); + } + #else if (send()) return(1); #endif *************** *** 161,166 case 'F': if (send()) return(1); continue; case 'U': --- 183,189 ----- #else if (send()) return(1); + #endif continue; case 'U':
jim (12/30/82)
While we are on the subject of line printers ... A lot of people seem to be using Printronix printers, and the standard lpf doesn't handle underlining or plot mode correctly for a Printronix. Here is my diff listing to lpf.c to make them work. *** lpf.c_o Tue Sep 15 08:02:34 1981 --- lpf.c Tue Sep 7 16:44:43 1982 *************** *** 1,6 static char *sccsid = "@(#)lpf.c 4.5 (Berkeley) 81/06/10"; /* * lpf -- Line printer filter */ #include <stdio.h> --- 1,11 ----- static char *sccsid = "@(#)lpf.c 4.5 (Berkeley) 81/06/10"; /* * lpf -- Line printer filter + * + * Jim Rees Added baud rate to ttyb + * 8 July 82 Jim Rees Fixed underlining for Printronix + * 23 Aug 82 Jim Rees Fixed plot mode for Printronix + * 7 Sept 82 Joe Kelsey Fixed formfeed for Printronix */ #include <stdio.h> *************** *** 7,12 #include <sgtty.h> #include <signal.h> #define LINELN 132 #define EJLINE 66 #define SKPLINE 0 --- 12,19 ----- #include <sgtty.h> #include <signal.h> + #define PRINTRONIX /* Special modes for Printronix */ + #define LINELN 132 #define EJLINE 66 #define SKPLINE 0 *************** *** 14,19 int anydone; char linebuf[LINELN+2]; int ov; char ovbuf[LINELN]; FILE *in = {stdin}; FILE *out; --- 21,27 ----- int anydone; char linebuf[LINELN+2]; int ov; + int plotmode; char ovbuf[LINELN]; FILE *in = {stdin}; FILE *out; *************** *** 122,127 register int col, maxcol, c; ov = 0; for (col=0; col<LINELN; col++) { linebuf[col] = ' '; ovbuf[col] = 0; --- 130,136 ----- register int col, maxcol, c; ov = 0; + plotmode = 0; for (col=0; col<LINELN; col++) { linebuf[col] = ' '; ovbuf[col] = 0; *************** *** 147,152 } continue; case '\f': lineno = EJLINE; continue; --- 156,168 ----- } continue; + #ifdef PRINTRONIX + case '\05': + plotmode = 1; + lineno = 1; /* To prevent SKPLINE, EJLINE */ + continue; + #endif PRINTRONIX + case '\f': lineno = EJLINE; #ifdef PRINTRONIX *************** *** 149,154 case '\f': lineno = EJLINE; continue; case ' ': --- 165,176 ----- case '\f': lineno = EJLINE; + #ifdef PRINTRONIX + if (maxcol >= LINELN) + maxcol = LINELN; + linebuf[maxcol] = 0; + return 1; + #else continue; #endif PRINTRONIX case ' ': *************** *** 150,156 case '\f': lineno = EJLINE; continue; ! case ' ': col++; continue; --- 172,178 ----- return 1; #else continue; ! #endif PRINTRONIX case ' ': col++; continue; *************** *** 201,215 int i, j; errno = 0; ! /* ! if (ov) do { ! for (ep= &ovbuf[LINELN-1]; *ep == 0; ep--) ! continue; ! for (lp=ovbuf; lp <= ep; lp++) ! output(*lp ? *lp : ' ', out); ! }; ! */ ! again: if (ff >= 0) { lp = linebuf; while (c = *lp++) --- 223,229 ----- int i, j; errno = 0; ! if (ff >= 0) { lp = linebuf; #ifdef PRINTRONIX *************** *** 212,217 again: if (ff >= 0) { lp = linebuf; while (c = *lp++) output(c,out); } --- 226,235 ----- if (ff >= 0) { lp = linebuf; + #ifdef PRINTRONIX + if (plotmode) + output('\05', out); + #endif PRINTRONIX while (c = *lp++) output(c,out); } *************** *** 215,220 while (c = *lp++) output(c,out); } if (ff > 0) { putc('\014', out); putc('\r', out); --- 233,249 ----- while (c = *lp++) output(c,out); } + + #ifdef PRINTRONIX + if (ov) { + output('\r', out); + for (ep= &ovbuf[LINELN-1]; *ep == 0; ep--) + continue; + for (lp=ovbuf; lp <= ep; lp++) + output(*lp ? *lp : ' ', out); + } + #endif PRINTRONIX + if (ff > 0) { putc('\014', out); putc('\r', out); *************** *** 298,304 if (c == -1) return; c &= 0177; ! if (c == 0177) putc('^',fp), c = '?'; if (c == 033) c = '$'; --- 327,333 ----- if (c == -1) return; c &= 0177; ! if (c == 0177 && !plotmode) putc('^',fp), c = '?'; if (c == 033) c = '$'; *************** *** 311,316 case '\b': case '\t': case '\r': break; default: --- 340,348 ----- case '\b': case '\t': case '\r': + #ifdef PRINTRONIX + case '\05': + #endif PRINTRONIX break; default:
DEAN@USC-ECL (02/28/83)
From: Jeff Dean <DEAN@USC-ECL> Date: 7 Jan 1983 0011-PST After months of not knowing why the line printer daemon died when the line printer was off line for a while, I eagerly snatched up the first fix I saw on unix-wizards. However, after I installed the change, I noticed that the daemon died even faster -- so I reinstalled the old code and threw the changes away (since a message to the author in uucp-land never got a response). Recently, someone has posted a list of fixes to lpd, including the one that didn't work for me. Hasn't anyone else noticed that the advertised fixes don't work? [ Or do I just have a version of lpd that's different than all the rest? Could have sworn we were running vanilla 4.1 ] Since I finally got tired of unwedging the line printer, I tracked down the bug, which turned out to be a bug in the bug fix. For those of you who are interested: the suggested changes included the addition of the line: fclose(fp); near the end of get_file However, the file is never open if the "if" at the top of the routine is false, thus causing lpd to crash even faster. Try moving the fclose into the scope where the file is opened. Let's keep those bug fixes coming, but let's try to keep them debugged! --JD -------