On Sun, Nov 24, 2019 at 11:01 PM Philip Guenther <guent...@gmail.com> wrote:
>
> On Sun, Nov 24, 2019 at 7:53 PM Jeffrey Walton <noloa...@gmail.com> wrote:
>>
>> On Sun, Nov 24, 2019 at 10:10 PM Philip Guenther <guent...@gmail.com> wrote:
>> >
>> > On Sun, Nov 24, 2019 at 3:11 AM Jeffrey Walton <noloa...@gmail.com> wrote:
>> >>
>> >> I am struggling to get a USB modem and terminal configured properly
>> >> under OpenBSD. The same code on Linux is fine. The symptom I am seeing
>> >> is a hung read() after issuing ATZ\r to the modem.
>> >>
>> >> I'm guessing there's an uninitialized field in my struct termios tty.
>> >
>> > I'm not sure what you mean by that.  Do you mean you're concerned that 
>> > you're you making a tcsetattr(3) call on an incompletely initialized 
>> > structure?  Or do you mean you're concerned that the initial configuration 
>> > of the tty provided by the kernel is in a "not good" state?
>>
>> I think cfmakeraw is not initializing the structure properly. It is an
>> intermittent failure.
>
> This code is misusing cfmakeraw(3): it needs to call tcgetattr(3) on the tty 
> fd and only call cfmakeraw() on the termios structure that tcgetattr() has 
> filled in.

Ack, thanks.

> (There may be other problems; I only reviewed enough to see that it was 
> violating the rule I mentioned in my previous post.  The _only_ portable way 
> to initialize a struct termios is to use tcgetattr()!)

Ack, thanks.

At the risk of sounding argumentative, the OpenBSD man page on
cfmakeraw [0] does not detail the requirement of using cfmakeraw on a
struct termios obtained from tcgetattr. In fact I specifically avoid
it because Valgrind produced so many findings due to the unmapped
ioctl's.

The Linux man page does not detail the limitation either. But things
"just work" on Linux and it was not a problem.

I suggest adding text similar to the following to the man page (the
first sentence is existing):

    The cfmakeraw() function sets the flags stored in the termios
    structure to a state disabling all input and output processing,
    giving a “raw I/O path”. cfmakeraw() must use a termios
    structure obtained from tcgetattr().
    (remaining text from man page)

Thanks for the help.

Jeff

[0] https://man.openbsd.org/tcsetattr.3

Reply via email to