Restructure the tty_drain loop so that device-busy is checked one more time

after tty_timedwait() returns an error only if the error is EWOULDBLOCK;
other errors cause an immediate return.  This fixes the case of the tty
disappearing while in tty_drain().

Reported by:	pho
This commit is contained in:
Ian Lepore 2017-01-12 21:18:43 +00:00
parent 4f56243aad
commit e046e8e680

View File

@ -166,11 +166,9 @@ tty_drain(struct tty *tp, int leaving)
return (error);
ttydevsw_outwakeup(tp);
error = tty_timedwait(tp, &tp->t_outwait, hz / 10);
if (timeout_at == 0 && error == EWOULDBLOCK)
error = 0;
if (error != EWOULDBLOCK)
continue;
if (getsbinuptime() < timeout_at)
if (error != 0 && error != EWOULDBLOCK)
return (error);
else if (timeout_at == 0 || getsbinuptime() < timeout_at)
error = 0;
else if (leaving && ttyoutq_bytesused(&tp->t_outq) < bytes) {
/* In close, making progress, grant an extra second. */