git: ff1993be35d6 - stable/13 - snp(4): implement detach
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 02 Oct 2022 00:52:14 UTC
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=ff1993be35d643a55c00d301628bfe1bfaeeffc4 commit ff1993be35d643a55c00d301628bfe1bfaeeffc4 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2022-09-25 11:34:17 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2022-10-02 00:51:47 +0000 snp(4): implement detach PR: 257964 (cherry picked from commit 550e01c552474babae468011191ecc5130cc153e) --- share/man/man4/snp.4 | 6 ------ sys/dev/snp/snp.c | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/share/man/man4/snp.4 b/share/man/man4/snp.4 index 524e779ce081..3422b9ca5d6f 100644 --- a/share/man/man4/snp.4 +++ b/share/man/man4/snp.4 @@ -87,9 +87,3 @@ Previous versions of .Nm were based on code written by .An Ugen J.S. Antsilevich Aq Mt ugen@NetVision.net.il . -.Sh BUGS -This version of -.Nm -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 3bcd2263809b..37c1c075a76e 100644 --- a/sys/dev/snp/snp.c +++ b/sys/dev/snp/snp.c @@ -125,6 +125,7 @@ snp_dtor(void *data) tty_lock(tp); ttyoutq_free(&ss->snp_outq); ttyhook_unregister(tp); + ss->snp_tty = NULL; } cv_destroy(&ss->snp_outwait); @@ -252,9 +253,19 @@ snp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, case SNPSTTY: /* Bind TTY to snoop instance. */ SNP_LOCK(); - if (ss->snp_tty != NULL) { + tp = ss->snp_tty; + if (tp != NULL) { + if (*(int *)data == -1) { + tty_lock(tp); + ss->snp_tty = NULL; + ttyoutq_free(&ss->snp_outq); + ttyhook_unregister(tp); + error = 0; + } else { + error = EBUSY; + } SNP_UNLOCK(); - return (EBUSY); + return (error); } /* * XXXRW / XXXJA: no capability check here.