diff --git a/lib/libc/sys/revoke.2 b/lib/libc/sys/revoke.2 index 482cbf661ba..3d7ad00bfe3 100644 --- a/lib/libc/sys/revoke.2 +++ b/lib/libc/sys/revoke.2 @@ -31,7 +31,7 @@ .\" @(#)revoke.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd Jan 25, 2016 .Dt REVOKE 2 .Os .Sh NAME @@ -59,7 +59,8 @@ and a system call will succeed. If the file is a special file for a device which is open, the device close function -is called as if all open references to the file had been closed. +is called as if all open references to the file had been closed +using a special close method which does not block. .Pp Access to a file may be revoked only by its owner or the super user. The @@ -104,3 +105,6 @@ The .Fn revoke system call first appeared in .Bx 4.3 Reno . +.Sh BUGS +The non-blocking close method is only correctly implemented for +terminal devices. diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 2d233270dea..04a10b38075 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -126,7 +126,7 @@ static int tty_drain(struct tty *tp, int leaving) { size_t bytesused; - int error, revokecnt; + int error; if (ttyhook_hashook(tp, getc_inject)) /* buffer is inaccessible */ @@ -141,18 +141,10 @@ tty_drain(struct tty *tp, int leaving) /* Wait for data to be drained. */ if (leaving) { - revokecnt = tp->t_revokecnt; error = tty_timedwait(tp, &tp->t_outwait, hz); - switch (error) { - case ERESTART: - if (revokecnt != tp->t_revokecnt) - error = 0; - break; - case EWOULDBLOCK: - if (ttyoutq_bytesused(&tp->t_outq) < bytesused) - error = 0; - break; - } + if (error == EWOULDBLOCK && + ttyoutq_bytesused(&tp->t_outq) < bytesused) + error = 0; } else error = tty_wait(tp, &tp->t_outwait); @@ -356,6 +348,10 @@ ttydev_close(struct cdev *dev, int fflag, int devtype __unused, return (0); } + /* If revoking, flush output now to avoid draining it later. */ + if (fflag & FREVOKE) + tty_flush(tp, FWRITE); + /* * This can only be called once. The callin and the callout * devices cannot be opened at the same time. @@ -1460,13 +1456,16 @@ tty_flush(struct tty *tp, int flags) tp->t_flags &= ~TF_HIWAT_OUT; ttyoutq_flush(&tp->t_outq); tty_wakeup(tp, FWRITE); - ttydevsw_pktnotify(tp, TIOCPKT_FLUSHWRITE); + if (!tty_gone(tp)) + ttydevsw_pktnotify(tp, TIOCPKT_FLUSHWRITE); } if (flags & FREAD) { tty_hiwat_in_unblock(tp); ttyinq_flush(&tp->t_inq); - ttydevsw_inwakeup(tp); - ttydevsw_pktnotify(tp, TIOCPKT_FLUSHREAD); + if (!tty_gone(tp)) { + ttydevsw_inwakeup(tp); + ttydevsw_pktnotify(tp, TIOCPKT_FLUSHREAD); + } } }