The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=bb4be76cf358246ef04ea8a67f38ff2a25b6c580

commit bb4be76cf358246ef04ea8a67f38ff2a25b6c580
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2022-09-24 20:23:31 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2022-09-25 20:36:16 +0000

    snp(4): properly report detached/revoked ttys
    
    PR:     257964
    Reported by:    Bertrand Petit <[email protected]>
    Reviewed by:    imp, markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D36690
---
 share/man/man4/snp.4 | 8 ++------
 sys/dev/snp/snp.c    | 7 +++++--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/share/man/man4/snp.4 b/share/man/man4/snp.4
index ce0ef66c5721..524e779ce081 100644
--- a/share/man/man4/snp.4
+++ b/share/man/man4/snp.4
@@ -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.
diff --git a/sys/dev/snp/snp.c b/sys/dev/snp/snp.c
index 64e2d0f64537..3bcd2263809b 100644
--- a/sys/dev/snp/snp.c
+++ b/sys/dev/snp/snp.c
@@ -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:

Reply via email to