[net.unix-wizards] ioctl

jeff@fluke.UUCP (Jeff Stearns) (04/11/84)

Anybody out there in Netville seen this one?

The 4.2BSD line printer daemon is having a bit of True Trauma trying to talk
to our NEC spinwriters (ugh).  The problem manifests itself in a wondrous way...

Lpd forks off children as needed to print a job.  The child daemon prints the
banner page, then forks again to set up a filter chain for printing the body of
the file.  In our situation, the filter process must make some minor
adjustments to the tty mode bits before printing the file.  In particular, the
filter process must disable CRMOD. [1]

Now the interesting part of this tale follows...
   - The spinwriter is slow.  It has a small input buffer.
   - Therefore, the filter gets set up and tries to disable CRMOD while banner
     characters are still dribbling into the spinwriter.
   - Now this ought not to be a problem, because the ioctl(~CRMOD) should delay
     until this pending output has drained.

Well, the ioctl causes the last character to be *obliterated*!  The formfeed
character gets transmitted in such a way that it has a framing error. [2]
(Remember that the last character in the buffer before the ioctl is a formfeed.)

Naturally, the spinwriters panic at the smell of a framing error, so they start
beeping.  Now the users get upset when the spinwriters are beeping, so they
start complaining...

I have ugly techniques for skirting the problem - a sleep(20) after printing the
banner page will cure it.  But really... it's so, uhm, crude...

I am seeking philosophical enlightenment.  Why does the formfeed character get
munged?  Excuse me, but is this a feature?

------------
[1] For the interested reader, these spinwriters use escape sequences
    which contain the LF character, and CRMOD will mung such sequences.
[2] You may not believe this.  Then again, you may not have a Dyna-Test 1100
    Serial Line Analyzer sitting on top of your terminal, either.  Or a
	Tektronix 833 line analyzer.  Or a Sony/Tek 308 Data Analyzer.  So there.
[3] We are running UNIX 4.2BSD on both vax 11/780's and on SUN's.  The problem
    manifests itself on *both* machines.  The vaxen have dz-11's.  The SUN's use
    on-board Zilog uarts.
-- 
	Jeff Stearns       (206) 356-5064
	John Fluke Mfg. Co.
	P.O. Box C9090  Everett WA  98043  
	{uw-beaver,decvax!microsof,ucbvax!lbl-csam,allegra,ssc-vax}!fluke!jeff

dmmartindale@watcgl.UUCP (Dave Martindale) (04/13/84)

What sort of device are you using to drive the serial line which talks to
the Spinwriter?  The "wait until output drains" feature of ioctl probably
just waits **until the last character has been sent to the device**.
At that point in time, the second-last character is being transmitted and
the last character is almost certainly just sitting in a holding register
somewhere.  If the driver then handles the change to CRMOD by doing
something which changes some of the device's control registers, which
may flush or clobber this buffer, you could lose the last character.
The problem may be in either the hardware itself or the driver.

mason@utcsrgv.UUCP (Dave Mason) (04/14/84)

The obvious thing to do is for the "wait for output to drain" part of ioctl
to output a (maybe 2) null characters before it starts waiting..that way you
can be sure the real data has gone by the time you mess with the UART.
-- 
Usenet:	{dalcs dciem garfield musocs qucis sask titan trigraph ubc-vision
 	 utzoo watmath allegra cornell decvax decwrl ihnp4 uw-beaver}
	!utcsrgv!mason		Dave Mason, U. Toronto CSRG
CSNET:	mason@Toronto
ARPA:	mason%Toronto@CSNet-Relay

jorgen@aahus.UUCP (Joergen Haegg) (08/16/86)

Is there anybody who knows what the following commands
to ioctl() does. I'm trying to port software to a Xenix-compatible
computer, and need to convert these into somthing my machine understands.

FIONREAD
TIOCSLTC
TIOCGLTC

In my ioctl.h are the following defined:

TCGETA TCSETA TCSETAW TCSETAF TCSBRK TCXONC TCFLSH	
Only these seven commands are documented in the manuals.
I don't know anything of the rest. Maybe some books on UNIX
describe these (please mail)?

TCDSET LDIOC LDOPEN LDCLOSE LDCHG TIOCGETD TIOCSETD TIOCHPCL TIOCGETP
TIOCSETP TIOCSETN TIOCEXCL TIOCNXCL TIOCFLUSH TIOCSETC TIOCGETC LIOCGETP
LIOCSETP LIOCGETS LIOCSETS DIOCGETC DIOCGETB DIOCSETE DIOCGETP       
DIOCSETP VPMCMD VPMERRS VPMRPT VPMTRCO

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Joergen Haegg  (No, that's not my name, in Sweden I spell it J|rgen H{gg)
Aahus Studiodata AB, Sweden                              Member of Gamers Guild
Box 140, S-29600 AAHUS                                   (LAIR) in Lund.
+46 44 241045,+46 46 127229                              jorgen@aahus.UUCP
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

zben@umd5 (Ben Cranston) (08/23/86)

In article <118@aahus.UUCP> jorgen@aahus.UUCP (Joergen Haegg) writes:

> Is there anybody who knows what the following commands
> to ioctl() does. I'm trying to port software to a Xenix-compatible
> computer, and need to convert these into somthing my machine understands.
> FIONREAD
> TIOCSLTC
> TIOCGLTC

These three are in "man 4 tty" in this Ultrix system.  There was an
updated "man 4 tty" entry circulating earlier this year, and (packrat
that I am) I saved it.  It also covers these three tags.  It is pretty
hefty (about 30 kilobytes).  Should I repost it here?
-- 
                    umd5.UUCP    <= {seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben
Ben Cranston zben @ umd2.UMD.EDU    Kingdom of Merryland Sperrows 1100/92
                    umd2.BITNET     "via HASP with RSCS"

rlk@chinet.UUCP (Richard Klappal) (08/27/86)

In article <118@aahus.UUCP> jorgen@aahus.UUCP (Joergen Haegg) writes:

> Is there anybody who knows what the following commands
> to ioctl() does. I'm trying to port software to a Xenix-compatible
> computer, and need to convert these into somthing my machine understands.
> FIONREAD
> TIOCSLTC
> TIOCGLTC


ioctl(fildes,FIONREAD,arg)
where arg is a pointer to a long,
sets arg to be the number of immediately readable characters from
fildes.  It is supposed to work for files, pipes, and ttys on
berzerkly systems.   

Sorry, can't help on the other two, my system doesn't have them
(at least in the docs.)


-- 
---
UUCP: ..!ihnp4!chinet!uklpl!rlk || MCIMail: rklappal || Compuserve: 74106,1021
      ..!ihnp4!ihu1h!rlk
---