The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a58557090670d61358b97eab285dcbde2402ad97
commit a58557090670d61358b97eab285dcbde2402ad97 Author: Konstantin Belousov <[email protected]> AuthorDate: 2026-08-25 08:19:32 +0000 Commit: Konstantin Belousov <[email protected]> CommitDate: 2026-09-05 00:33:45 +0000 tty: add tty_wait_proctree(9) (cherry picked from commit 9bd3fe5712217ef8ae4cebba8be82c45be0c72e6) --- sys/kern/tty.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index f412205a3d2b..41ce5ecdb455 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -72,6 +72,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; @@ -1608,6 +1610,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) {
