snp(4): properly report detached/revoked ttys

PR:	257964
Reported by:	Bertrand Petit <bsdpr@phoe.frmug.org>
Reviewed by:	imp, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D36690
This commit is contained in:
Konstantin Belousov 2022-09-24 23:23:31 +03:00
parent d1a351be19
commit bb4be76cf3
2 changed files with 7 additions and 8 deletions

View File

@ -1,7 +1,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd November 5, 2008
.Dd September 24, 2022
.Dt SNP 4
.Os
.Sh NAME
@ -58,8 +58,6 @@ ioctl returns a positive value equal to the number of characters
in a read buffer.
Special values defined are:
.Bl -tag -width ".Dv SNP_TTYCLOSE"
.It Dv SNP_OFLOW
device overflow occurred, device detached.
.It Dv SNP_TTYCLOSE
tty not attached.
.It Dv SNP_DETACH
@ -92,8 +90,6 @@ were based on code written by
.Sh BUGS
This version of
.Nm
does not return proper error codes when calling
.Dv FIONREAD .
It also does not allow
does not allow
.Dv SNPSTTY
to detach itself from the TTY.

View File

@ -289,10 +289,13 @@ snp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
tp = ss->snp_tty;
if (tp != NULL) {
tty_lock(tp);
*(int *)data = ttyoutq_bytesused(&ss->snp_outq);
if (tty_gone(tp))
*(int *)data = SNP_TTYCLOSE;
else
*(int *)data = ttyoutq_bytesused(&ss->snp_outq);
tty_unlock(tp);
} else {
*(int *)data = 0;
*(int *)data = SNP_DETACH;
}
return (0);
default: