[Openmcl-devel] Raw-mode terminal weirdness redux

Ron Garret ron at flownet.com
Tue Mar 27 12:35:11 PDT 2018


On Mar 27, 2018, at 12:03 PM, R. Matthew Emerson <rme at acm.org> wrote:

> 
> 
>> On Mar 27, 2018, at 10:05 AM, David Brown <lisp at davidb.org> wrote:
>> 
>> On Tue, Mar 27, 2018 at 09:32:54AM -0700, Ron Garret wrote:
>>> Found a reliable workaround!
>>> 
>>> ...
>>> This version is broken.  If you comment out the line that says “This
>>> breaks it” it will start working properly.  Both working and
>>> non-working versions are 100% reliable.  Using a single RLET to
>>> allocate both termios structures also works.  It’s only when there is
>>> a call to tcgetattr in between the allocations that it breaks.  (Note
>>> that the “broken” version works in 1.8.  But for the fact that C code
>>> can reproduce this problem intermittently I would call this slam-dunk
>>> evidence that this is a bug in the CCL compiler, most likely in RLET.
>>> But since the C code does what it does, I’m not willing to go quite
>>> that far.)
>> 
>> The common thread in all of these, is that "raw" is only partially
>> initialized (cfmakeraw only initializes c_iflag).  Subtle changes in
>> stack positioning will make the initial values different, which
>> explains both the inconsistent behavior with the C program, and the
>> behavior of the lisp programs (and why it matters how you declare it).
>> 
>> You need to either tcgetattr again to fill in the 'raw' with the
>> current values, or copy the data from the 'normal' before calling
>> cfmakeraw on it.
>> 
>> My guess is that, with c_oflag being set to an uninitialized value, it
>> has flags set such that it generates no output.
> 
> I was under the faulty impression that #_cfmakeraw would fully initialize the termios structure.

Same here.  The man page certainly does nothing to indicate otherwise.

> Nice catch.

Indeed.

> So, we'd want something like
> 
> (defun set-tty-raw (tty)
>  (rlet ((attr :termios))
>    (#_tcgetattr tty attr)
>    (#_cfmakeraw attr)
>    (eql 0 (#_tcsetattr tty #$TCSAFLUSH attr))))

Exactly.  If you tweak the C code in this way it works.

rg




More information about the Openmcl-devel mailing list