Only set use tcsetattr() on TTYs for KISS TNCs

Fix patty_kiss_tnc_new_fd() to only attempt tcgetattr()/tcsetattr() on
file descriptors for whom isatty() is true, allowing files and sockets
to once again be used
This commit is contained in:
XANTRONIX Development 2020-07-30 01:34:43 -04:00 committed by XANTRONIX Industrial
parent e10ce6b8e1
commit 09df948871

View file

@ -52,16 +52,18 @@ patty_kiss_tnc *patty_kiss_tnc_new_fd(int fd) {
goto error_malloc_buf;
}
if (tcgetattr(fd, &tnc->attrs) < 0) {
goto error_tcgetattr;
}
if (isatty(fd)) {
if (tcgetattr(fd, &tnc->attrs) < 0) {
goto error_tcgetattr;
}
memcpy(&tnc->attrs_old, &tnc->attrs, sizeof(tnc->attrs_old));
memcpy(&tnc->attrs_old, &tnc->attrs, sizeof(tnc->attrs_old));
cfmakeraw(&tnc->attrs);
cfmakeraw(&tnc->attrs);
if (tcsetattr(fd, TCSANOW, &tnc->attrs) < 0) {
goto error_tcsetattr;
if (tcsetattr(fd, TCSANOW, &tnc->attrs) < 0) {
goto error_tcsetattr;
}
}
tnc->fd = fd;