The branch main has been updated by kib:

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

commit 9bd3fe5712217ef8ae4cebba8be82c45be0c72e6
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-08-25 08:19:32 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-29 09:42:52 +0000

    tty: add tty_wait_proctree(9)
    
    Reviewed by:    markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D59132
---
 sys/kern/tty.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 6871853de0be..ae624227bc3a 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -74,6 +74,8 @@
 static MALLOC_DEFINE(M_TTY, "tty", "tty device");
 
 static void tty_rel_free(struct tty *tp, bool inttydevclose);
+static int tty_wait_proctree(struct tty *tp, struct cv *cv,
+    int proctree_lock_mode);
 
 static TAILQ_HEAD(, tty) tty_list = TAILQ_HEAD_INITIALIZER(tty_list);
 static struct sx tty_list_sx;
@@ -1610,6 +1612,43 @@ tty_wait(struct tty *tp, struct cv *cv)
        return (error);
 }
 
+static int
+tty_wait_proctree(struct tty *tp, struct cv *cv, int proctree_lock_mode)
+{
+       int error;
+       int revokecnt = tp->t_revokecnt;
+
+       tty_lock_assert(tp, MA_OWNED | MA_NOTRECURSED);
+       MPASS(!tty_gone(tp));
+       MPASS(proctree_lock_mode == LA_UNLOCKED ||
+           proctree_lock_mode == LA_SLOCKED ||
+           proctree_lock_mode == LA_XLOCKED);
+
+       if (proctree_lock_mode != LA_UNLOCKED)
+               sx_unlock(&proctree_lock);
+
+       error = cv_wait_sig_unlock(cv, tp->t_mtx);
+       switch (proctree_lock_mode) {
+       case LA_SLOCKED:
+               sx_slock(&proctree_lock);
+               break;
+       case LA_XLOCKED:
+               sx_xlock(&proctree_lock);
+               break;
+       }
+       tty_lock(tp);
+
+       /* Bail out when the device slipped away. */
+       if (tty_gone(tp))
+               return (EXTERROR(ENXIO, "tty_wait_proctree: device is gone"));
+
+       /* Restart the system call when we may have been revoked. */
+       if (tp->t_revokecnt != revokecnt)
+               return (ERESTART);
+
+       return (error);
+}
+
 int
 tty_timedwait(struct tty *tp, struct cv *cv, int hz)
 {

Reply via email to