[comp.sys.ibm.pc.rt] Line Printer Problem LONG, with examples

gn@yamnet.UUCP (The Remittance Man @ Delphi Information Sys.) (03/17/89)

I'm currently having a hell of a problem, when opening the
system printer I always get a FID back, no failure, no matter
what state printer is in. I could ship the printer to North 
Dakota and *STILL* get a file identifier. Try the following 
program,

---

#include <fcntl.h>

main()
{
	printf("%d\n",open("/dev/lp0",O_WRONLY));
}

and as mentioned, ship your printer to North Dakota....
you should get a positive value, if you don't please talk to 
me. The open always returns successfully. 


Further Problems.....

So, how about the following write's?  Well they hang, never to
return. 

---

#include <fcntl.h>
char *test_buf="xxxxxxxxxxxxxxx";

main()
{
	int printer_fid;

	printer_fid=open("/dev/lp0",O_WRONLY);

	printf("%d\n",write(printer_fid,test_buf,strlen(test_buf)));

}

This will hang forever......or until the printer is put back on line.

Some of you I'm sure are saying, well sure it will hang, you haven't
set O_NDELAY. Ok, try it....NO DIFFERENCE, the printer will still 
hang.

Ok, Ok, you shrug, how about the ioctl flags from <sys/lprio.h>?
Certainly that will allow fuller control. First let us set LPRALLERR
flag (documented in v2.5 (5-112,2.2) as ALLERR (Liars!)), this flag
changes the default from "Wait Until Error Correction", to "Report
All Errors".

---

#include <fcntl.h>
#include <sys/lprio.h>

char *test_buf="xxxxxxxxxxxxxxxxxxxxxxx";

int main()
{
	int printer_fid,
		bytes_written;

	struct oprmode printer_mode;	/* See the Arcane sys/lprio.h */

	printer_fid=open("/dev/lp0",O_WRONLY); 	/* Write Only */

	printer_mode.flags=LPRALLERR ;		/* ALL ERROR Flag */

	if(ioctl(printer_fid,LPRSMOD,&printer_mode)==-1)
	{
		printf("Ioctl failed....");
		exit();
	}

	bytes_written=write(printer_fid,test_buf,strlen(test_buf));

	printf("The Write Returns: %d\n",bytes_written);

}

Upon running this the write will block until the printer is put
back on-line, whereupon you get the message SIGNAL 27. So lets 
bring in an even bigger hammer, the signal handler to ignore SIGIOINT.
and add a close to round out the picture.

--

26a

	printf("The Close Returns: %d\n",close(printer_fid));

.
15a
	signal(SIGIOINT,SIG_IGN);	/* Ignore, don't exit on IOINT */	

.
2a
#include <sys/signal.h>
.

Any guesses as to what happens?

The output is "The Write Returns: -1", and the program blocks on
the close (flushing the buffer?!?), until the printer is put 
back on line.  I have tried everything, including dividing by 
zero, to try to get the program to exit...all to no avail. 

Funny thing is that piobe is able to determine the state of the
printer on what appears to be the open. How?  What can be done
to get the open to fail?  Do I need to run 'splp +err' on nights of
a full moon?  Set kpoe in /etc/ddi/opprinter to 'maybe' ? 
What's the deal?

I have the printer configured as an 'opp', and have tryed this on
two different RT 6150s with no luck.

Any help would be greatly appreciated....

(If by the way you want to here an the equally horrible saga of the
 single bay portafile 6156, just let me know )

--
Greg Noel [Gn] Delphi Information Systems, Westlake Vlg, Ca. 
The food is bad, and the portions are small.  -W Allen