Use struct termios in ttynvt_t and drop static one.

Also set termios on pty slave on init.
This commit is contained in:
Kim Woelders
2018-10-15 13:25:03 +02:00
parent af3c3d4162
commit 2fe0428d92
+23 -20
View File
@@ -487,6 +487,11 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
if ((fd = open(slave_name, O_RDWR | O_NOCTTY)) < 0) /* open slave */ if ((fd = open(slave_name, O_RDWR | O_NOCTTY)) < 0) /* open slave */
goto open_err; goto open_err;
ioctl(fd, TCGETS, &tty->tio);
tty->tio.c_cflag &= ~(CSIZE | PARENB);
tty->tio.c_cflag |= B115200 | CS8 | CREAD | CLOCAL;
ioctl(fd, TCSETS, &tty->tio);
tty->fds[FD_SLAVE].fd = fd; tty->fds[FD_SLAVE].fd = fd;
tty->fds[FD_SLAVE].events = POLLIN; tty->fds[FD_SLAVE].events = POLLIN;
@@ -683,12 +688,10 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
const void *in_buf, size_t in_bufsz, size_t out_bufsz) const void *in_buf, size_t in_bufsz, size_t out_bufsz)
{ {
ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh; ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh;
struct termios *tio = &tty->tio;
struct winsize ws; struct winsize ws;
unsigned int tiocm = 0; unsigned int tiocm = 0;
int mcr; int mcr;
static struct termios tio = {
.c_cflag = B115200 | CS8 | PARODD | CREAD | CLOCAL,
};
int val; int val;
int res; int res;
@@ -706,46 +709,46 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
speed_t speed; speed_t speed;
int csize, par, sb; int csize, par, sb;
memcpy(&tio, in_buf, in_bufsz); memcpy(tio, in_buf, in_bufsz);
speed = tio.c_cflag & (CBAUD | CBAUDEX); speed = tio->c_cflag & (CBAUD | CBAUDEX);
val = htonl(baudrate(speed)); val = htonl(baudrate(speed));
telnet_rfc2217_cfg(tty->tn, TNS_SET_BAUDRATE, &val, 4); telnet_rfc2217_cfg(tty->tn, TNS_SET_BAUDRATE, &val, 4);
if ((tio.c_cflag & CSIZE) == CS5) if ((tio->c_cflag & CSIZE) == CS5)
csize = 5; csize = 5;
else if ((tio.c_cflag & CSIZE) == CS6) else if ((tio->c_cflag & CSIZE) == CS6)
csize = 6; csize = 6;
else if ((tio.c_cflag & CSIZE) == CS7) else if ((tio->c_cflag & CSIZE) == CS7)
csize = 7; csize = 7;
else else
csize = 8; csize = 8;
telnet_rfc2217_cfg(tty->tn, TNS_SET_DATASIZE, &csize, 1); telnet_rfc2217_cfg(tty->tn, TNS_SET_DATASIZE, &csize, 1);
if (tio.c_cflag & PARENB && tio.c_iflag & IGNPAR) if (tio->c_cflag & PARENB && tio->c_iflag & IGNPAR)
par = 1; par = 1;
#ifdef CMSPAR #ifdef CMSPAR
else if (tio.c_cflag & PARENB && tio.c_iflag & CMSPAR) else if (tio->c_cflag & PARENB && tio->c_iflag & CMSPAR)
{ {
if (tio.c_cflag & PARODD) if (tio->c_cflag & PARODD)
par = 4; par = 4;
else else
par = 5; par = 5;
} }
#endif #endif
else if (tio.c_cflag & PARENB) else if (tio->c_cflag & PARENB)
par = 3; par = 3;
else else
par = 1; par = 1;
telnet_rfc2217_cfg(tty->tn, TNS_SET_PARITY, &par, 1); telnet_rfc2217_cfg(tty->tn, TNS_SET_PARITY, &par, 1);
if (tio.c_cflag & CSTOPB) if (tio->c_cflag & CSTOPB)
sb = 2; sb = 2;
else else
sb = 1; sb = 1;
telnet_rfc2217_cfg(tty->tn, TNS_SET_STOPSIZE, &sb, 1); telnet_rfc2217_cfg(tty->tn, TNS_SET_STOPSIZE, &sb, 1);
if (tio.c_cflag & CRTSCTS) if (tio->c_cflag & CRTSCTS)
telnet_rfc2217_ctl(tty->tn, TNS_CTL_CTSRTS); telnet_rfc2217_ctl(tty->tn, TNS_CTL_CTSRTS);
if (!(tty->cmcr & TIOCM_DTR) && speed != B0) if (!(tty->cmcr & TIOCM_DTR) && speed != B0)
@@ -756,19 +759,19 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
DBG("termios: %u%c%u%u %cCTSRTS %cCREAD %cHUPCL %cCLOCAL\n", DBG("termios: %u%c%u%u %cCTSRTS %cCREAD %cHUPCL %cCLOCAL\n",
baudrate(speed), pstr[par], csize, sb, baudrate(speed), pstr[par], csize, sb,
tio.c_cflag & CRTSCTS ? '+' : '-', tio->c_cflag & CRTSCTS ? '+' : '-',
tio.c_cflag & CREAD ? '+' : '-', tio->c_cflag & CREAD ? '+' : '-',
tio.c_cflag & HUPCL ? '+' : '-', tio->c_cflag & HUPCL ? '+' : '-',
tio.c_cflag & CLOCAL ? '+' : '-'); tio->c_cflag & CLOCAL ? '+' : '-');
ioctl(tty->fds[FD_SLAVE].fd, cmd, &tio); ioctl(tty->fds[FD_SLAVE].fd, cmd, tio);
fuse_reply_ioctl(req, 0, 0, 0); fuse_reply_ioctl(req, 0, 0, 0);
} }
break; break;
case TCGETS: case TCGETS:
CHECK_BUF_OUT(sizeof(struct termios)); CHECK_BUF_OUT(sizeof(struct termios));
fuse_reply_ioctl(req, 0, &tio, sizeof(struct termios)); fuse_reply_ioctl(req, 0, tio, sizeof(struct termios));
break; break;
case TIOCINQ: /* Get the number of bytes in the input case TIOCINQ: /* Get the number of bytes in the input
* buffer */ * buffer */