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)



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



Home | Main Index | Thread Index | Old Index