NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/56779: RAW mode on the TTY always returns EOF (-1)
The following reply was made to PR kern/56779; it has been noted by GNATS.
From: Michael Cheponis <michael.cheponis%gmail.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: kern-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost,
mac%culver.net@localhost
Subject: Re: kern/56779: RAW mode on the TTY always returns EOF (-1)
Date: Tue, 5 Apr 2022 09:27:46 -0700
--000000000000c6c87705dbeabb18
Content-Type: text/plain; charset="UTF-8"
Thanks, you know, I read :
"the correct method is for
an application to snapshot the current terminal state using the
function
tcgetattr, setting raw mode with cfmakeraw and the subsequent
tcsetattr,
and then using another tcsetattr with the saved state to revert to the
previous terminal state."
This English is less-clear than a code example:
*tcgetattr(STDIN_FILENO, &tty_opts_backup);*
*tty_opts_raw = tty_opts_backup;*
*cfmakeraw(&tty_opts_raw);*
*tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);*
*<later in code, to revert RAW>*
*tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_backup);*
I think what threw me off is: the code, as-was (w/o assignment of structs)
works fine on WSL under Windows; and also linux/arm.
Maybe it'd be better to call "cfmakeraw()" something like
"cf-sort-of-makeraw()" ? ;-) since it doesn't actually *make* things raw.
Or, of course, simply 'fix' makeraw() to be compliant w/linux?
Thanks for the super-prompt reply.
My suggestions:
1) Add a Code Example to the TCSETATTR (3) page
2) Change behavior of cfmakeraw() to be consistent w/linux
3) I'm only kidding about changing the name.
-Mike
On Tue, Apr 5, 2022 at 1:20 AM RVP <rvp%sdf.org@localhost> wrote:
> The following reply was made to PR kern/56779; it has been noted by GNATS.
>
> From: RVP <rvp%SDF.ORG@localhost>
> To: gnats-bugs%netbsd.org@localhost
> Cc:
> Subject: Re: kern/56779: RAW mode on the TTY always returns EOF (-1)
> Date: Tue, 5 Apr 2022 08:17:19 +0000 (UTC)
>
> On Tue, 5 Apr 2022, Michael van Elst wrote:
>
> > cfmakeraw changes the configuration in a termios structure,
> > but it doesn't magically initialize values. Your code
> > just uses random stack content with unpredictable results.
> >
>
> c_cc[VMIN] = 1;
> c_cc[VTIME] = 0;
>
> can also be done in src/lib/libc/termios/cfmakeraw.c, I think.
>
> -RVP
>
>
--000000000000c6c87705dbeabb18
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,helvetica,sans-serif;font-size:small">Thanks, you know, I re=
ad :</div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica=
,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" style=
=3D"font-family:arial,helvetica,sans-serif;font-size:small">"<span sty=
le=3D"font-family:Arial,Helvetica,sans-serif">the correct method is for</sp=
an></div>=C2=A0 =C2=A0 =C2=A0an application to snapshot the current termina=
l state using the function<br>=C2=A0 =C2=A0 =C2=A0tcgetattr, setting raw mo=
de with cfmakeraw and the subsequent tcsetattr,<br>=C2=A0 =C2=A0 =C2=A0and =
then using another tcsetattr with the saved state to revert to the<br>=C2=
=A0 =C2=A0 =C2=A0previous terminal state.<span class=3D"gmail_default" styl=
e=3D"font-family:arial,helvetica,sans-serif;font-size:small">"</span><=
div><span class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans=
-serif;font-size:small"><br></span></div><div><span class=3D"gmail_default"=
style=3D"font-family:arial,helvetica,sans-serif;font-size:small">This Engl=
ish is less-clear than a code example:</span><br></div><div><span class=3D"=
gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-size:sm=
all"><br></span></div></div><blockquote style=3D"margin:0 0 0 40px;border:n=
one;padding:0px"><div><div><b><font size=3D"1">tcgetattr(STDIN_FILENO, &=
;tty_opts_backup);</font></b></div><div><font size=3D"1"><b style=3D"font-f=
amily:monospace">tty_opts_raw =3D tty_opts_backup;</b><br></font></div></di=
v><div><div><span class=3D"gmail_default" style=3D""><font face=3D"monospac=
e" style=3D"" size=3D"1"><b style=3D"">cfmakeraw(&tty_opts_raw);</b></f=
ont></span></div></div><div><div><span class=3D"gmail_default" style=3D""><=
font face=3D"monospace" style=3D"" size=3D"1"><b style=3D"">tcsetattr(STDIN=
_FILENO, TCSANOW, &tty_opts_raw);</b></font></span></div></div><div><di=
v><span class=3D"gmail_default" style=3D""><font face=3D"monospace" size=3D=
"1"><b><br></b></font></span></div></div><div><div><div class=3D"gmail_defa=
ult" style=3D""><font face=3D"monospace" size=3D"1"><b><later in code, t=
o revert RAW></b></font></div></div></div></blockquote><div><div><font s=
ize=3D"1"><span class=3D"gmail_default" style=3D""></span></font></div></di=
v><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div dir=
=3D"ltr"><div class=3D"gmail_default" style=3D""><font face=3D"monospace" s=
tyle=3D"" size=3D"1"><b style=3D"">tcsetattr(STDIN_FILENO, TCSANOW, &tt=
y_opts_backup);</b></font></div></div></blockquote><div dir=3D"ltr"><div><b=
r class=3D"gmail-Apple-interchange-newline"></div><div class=3D"gmail_defau=
lt" style=3D"font-family:arial,helvetica,sans-serif;font-size:small">I thin=
k what threw me off is:=C2=A0 the code, as-was (w/o assignment of structs) =
works fine on WSL under Windows; and also linux/arm.</div><div class=3D"gma=
il_default" style=3D"font-family:arial,helvetica,sans-serif;font-size:small=
"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,helveti=
ca,sans-serif;font-size:small">Maybe it'd be better to call "cfmak=
eraw()" something like "cf-sort-of-makeraw()" ?=C2=A0 =C2=A0=
;-)=C2=A0 since it doesn't actually *make* things raw.</div><div class=
=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-siz=
e:small"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,=
helvetica,sans-serif;font-size:small">Or, of course, simply 'fix' m=
akeraw() to be compliant w/linux?</div><br></div><div class=3D"gmail_defaul=
t" style=3D"font-family:arial,helvetica,sans-serif;font-size:small"></div><=
div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif=
;font-size:small">Thanks for the super-prompt reply.</div><div class=3D"gma=
il_default" style=3D"font-family:arial,helvetica,sans-serif;font-size:small=
"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,helveti=
ca,sans-serif;font-size:small">My suggestions:</div><div class=3D"gmail_def=
ault" style=3D"font-family:arial,helvetica,sans-serif;font-size:small"><br>=
</div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div =
class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;fon=
t-size:small">1) Add a Code Example to the=C2=A0 TCSETATTR=C2=A0(3) page</d=
iv><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-s=
erif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"font-=
family:arial,helvetica,sans-serif;font-size:small">2) Change behavior of cf=
makeraw() to be consistent w/linux</div><div class=3D"gmail_default" style=
=3D"font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div =
class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;fon=
t-size:small">3) I'm only kidding about changing the name.</div></block=
quote><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,san=
s-serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"fo=
nt-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class=
=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-siz=
e:small">-Mike</div><div class=3D"gmail_default" style=3D"font-family:arial=
,helvetica,sans-serif;font-size:small"><br></div><div><br></div><br><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Apr 5, 20=
22 at 1:20 AM RVP <<a href=3D"mailto:rvp%sdf.org@localhost">rvp%sdf.org@localhost</a>> wr=
ote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The followi=
ng reply was made to PR kern/56779; it has been noted by GNATS.<br>
<br>
From: RVP <<a href=3D"mailto:rvp%SDF.ORG@localhost" target=3D"_blank">rvp%SDF.ORG@localhost<=
/a>><br>
To: <a href=3D"mailto:gnats-bugs%netbsd.org@localhost" target=3D"_blank">gnats-bugs@n=
etbsd.org</a><br>
Cc: <br>
Subject: Re: kern/56779: RAW mode on the TTY always returns EOF (-1)<br>
Date: Tue, 5 Apr 2022 08:17:19 +0000 (UTC)<br>
<br>
=C2=A0On Tue, 5 Apr 2022, Michael van Elst wrote:<br>
<br>
=C2=A0> cfmakeraw changes the configuration in a termios structure,<br>
=C2=A0> but it doesn't magically initialize values. Your code<br>
=C2=A0> just uses random stack content with unpredictable results.<br>
=C2=A0><br>
<br>
=C2=A0c_cc[VMIN] =3D 1;<br>
=C2=A0c_cc[VTIME] =3D 0;<br>
<br>
=C2=A0can also be done in=C2=A0 src/lib/libc/termios/cfmakeraw.c, I think.<=
br>
<br>
=C2=A0-RVP<br>
<br>
</blockquote></div></div>
--000000000000c6c87705dbeabb18--
Home |
Main Index |
Thread Index |
Old Index