NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/48720: POSIX tcsetattr() fails B0



>Number:         48720
>Category:       bin
>Synopsis:       POSIX tcsetattr() fails B0
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 06 17:05:00 +0000 2014
>Originator:     John Kelly
>Release:        6.1.3
>Organization:
none
>Environment:
NetBSD ... 6.1.3 NetBSD 6.1.3 (GENERIC) i386

>Description:
POSIX says:

If the output baud rate stored in the termios structure pointed to by termios_p 
is the zero baud rate, B0, the modem control lines shall no longer be asserted. 
Normally, this shall disconnect the line.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html

NetBSD tcsetattr() rejects B0 as invalid argument.

>How-To-Repeat:
# include <errno.h>
# include <fcntl.h>
# include <termios.h>
# include <unistd.h>
# include <stdio.h>
# include <string.h>

int fd, rv;
struct termios term;

int
main (void)
{

    fd = open ("/dev/tty00", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fd == -1) {
        printf ("failure opening tty: %s\n", strerror (errno));
        return 1;
    }

    rv = tcgetattr (fd, &term);
    if (rv == -1) {
        printf ("failure getting tty termios: %s\n", strerror (errno));
        return 1;
    }

    rv = cfsetspeed (&term, B0);
    if (rv == -1) {
        printf ("failure setting tty baud: %s\n", strerror (errno));
        return 1;
    }

    rv = tcsetattr (fd, TCSANOW, &term);
    if (rv == -1) {
        printf ("failure setting tty termios: %s\n", strerror (errno));
        return 1;
    }

    return 0;
}

>Fix:
I browsed some of the source, but didn't see the problem. Looks like the fix 
could get messy though. DTR must stay down as long as the baud rate remains 0.

POSIX does not specify that RTS should be down too, and there are good reasons 
for leaving it untouched. DTR down, is all you need to disconnect the line.



Home | Main Index | Thread Index | Old Index