1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Refactor term_replace() to correct term_s state

Reorder state updates in term_replace() so that the changing term_s's
file descriptor is correct during calls to tcgetattr()

This is in preparation for replacing tcgetattr() with a function that
operates on the term_s structure, and not just on the fd.
This commit is contained in:
David Leonard
2018-02-09 23:21:57 +10:00
committed by Nick Patavalis
parent 2498ff1ca8
commit e9aaff2a08

11
term.c
View File

@ -602,21 +602,24 @@ term_replace (int oldfd, int newfd)
break;
}
r = tcsetattr(newfd, TCSANOW, &t->currtermios);
/* assert(t->fd == oldfd); */
t->fd = newfd;
r = tcsetattr(t->fd, TCSANOW, &t->currtermios);
if ( r < 0 ) {
term_errno = TERM_ESETATTR;
rval = -1;
t->fd = oldfd;
break;
}
r = tcgetattr(newfd, &t->currtermios);
r = tcgetattr(t->fd, &t->currtermios);
if ( r < 0 ) {
term_errno = TERM_EGETATTR;
rval = -1;
t->fd = oldfd;
break;
}
t->fd = newfd;
} while (0);
return rval;