Set raw TTY attributes on patty_kiss_tnc_new_fd()
Changes: * Use cfmakeraw() to set raw TTY attributes in KISS TNC constructor patty_kiss_tnc_new_fd() * Restore previous TTY attributes in patty_kiss_tnc_destroy()
This commit is contained in:
parent
0aea65487a
commit
10745bbabf
2 changed files with 20 additions and 17 deletions
|
@ -55,7 +55,6 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (isatty(info.fd) && grantpt(info.fd) == 0 && unlockpt(info.fd) == 0) {
|
||||
char name[256];
|
||||
struct termios t;
|
||||
|
||||
if (ptsname_r(info.fd, name, sizeof(name)) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
|
@ -64,22 +63,6 @@ int main(int argc, char **argv) {
|
|||
goto error_open;
|
||||
}
|
||||
|
||||
if (tcgetattr(info.fd, &t) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], argv[1], "tcgetattr()", strerror(errno));
|
||||
|
||||
goto error_open;
|
||||
}
|
||||
|
||||
cfmakeraw(&t);
|
||||
|
||||
if (tcsetattr(info.fd, TCSANOW, &t) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], argv[1], "tcsetattr()", strerror(errno));
|
||||
|
||||
goto error_open;
|
||||
}
|
||||
|
||||
fprintf(stderr, "pts %s\n", name);
|
||||
}
|
||||
|
||||
|
|
20
src/kiss.c
20
src/kiss.c
|
@ -3,6 +3,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -24,6 +25,9 @@ enum tnc_opts {
|
|||
};
|
||||
|
||||
struct _patty_kiss_tnc {
|
||||
struct termios attrs,
|
||||
attrs_old;
|
||||
|
||||
int fd,
|
||||
opts;
|
||||
|
||||
|
@ -48,6 +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;
|
||||
}
|
||||
|
||||
memcpy(&tnc->attrs_old, &tnc->attrs, sizeof(tnc->attrs_old));
|
||||
|
||||
cfmakeraw(&tnc->attrs);
|
||||
|
||||
if (tcsetattr(fd, TCSANOW, &tnc->attrs) < 0) {
|
||||
goto error_tcsetattr;
|
||||
}
|
||||
|
||||
tnc->fd = fd;
|
||||
tnc->opts = TNC_NONE;
|
||||
tnc->bufsz = PATTY_KISS_BUFSZ;
|
||||
|
@ -57,6 +73,8 @@ patty_kiss_tnc *patty_kiss_tnc_new_fd(int fd) {
|
|||
|
||||
return tnc;
|
||||
|
||||
error_tcsetattr:
|
||||
error_tcgetattr:
|
||||
error_malloc_buf:
|
||||
free(tnc);
|
||||
|
||||
|
@ -123,6 +141,8 @@ int patty_kiss_tnc_fd(patty_kiss_tnc *tnc) {
|
|||
}
|
||||
|
||||
void patty_kiss_tnc_destroy(patty_kiss_tnc *tnc) {
|
||||
(void)tcsetattr(tnc->fd, TCSANOW, &tnc->attrs_old);
|
||||
|
||||
if (tnc->opts & TNC_CLOSE_ON_DESTROY) {
|
||||
close(tnc->fd);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue