tty: make tty_wait_background() aware of proctree_lock ownership

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
This commit is contained in:
Konstantin Belousov committed 2026-08-29 12:43:00 +03:00
1 parent 9bd3fe5712
commit 824f934bf9
3 files changed
+21 -10

No files matched your search

+11 -5
View File
@@ -434,7 +434,8 @@ tty_is_ctty(struct tty *tp, struct proc *p)
}
int
tty_wait_background(struct tty *tp, struct thread *td, int sig)
tty_wait_background(struct tty *tp, struct thread *td, int sig,
int proctree_lock_mode)
{
struct proc *p;
struct pgrp *pg;
@@ -443,6 +444,9 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig)
MPASS(sig == SIGTTIN || sig == SIGTTOU);
tty_assert_locked(tp);
MPASS(proctree_lock_mode == LA_UNLOCKED ||
proctree_lock_mode == LA_SLOCKED ||
proctree_lock_mode == LA_XLOCKED);
p = td->td_proc;
for (;;) {
@@ -507,8 +511,8 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig)
pgsignal(pg, ksi.ksi_signo, 1, &ksi);
PGRP_UNLOCK(pg);
error = tty_wait(tp, &tp->t_bgwait);
if (error)
error = tty_wait_proctree(tp, &tp->t_bgwait, proctree_lock_mode);
if (error != 0)
return (error);
}
}
@@ -545,7 +549,8 @@ ttydev_write(struct cdev *dev, struct uio *uio, int ioflag)
return (error);
if (tp->t_termios.c_lflag & TOSTOP) {
error = tty_wait_background(tp, curthread, SIGTTOU);
error = tty_wait_background(tp, curthread, SIGTTOU,
LA_UNLOCKED);
if (error)
goto done;
}
@@ -620,7 +625,8 @@ ttydev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
* If the ioctl() causes the TTY to be modified, let it
* wait in the background.
*/
error = tty_wait_background(tp, curthread, SIGTTOU);
error = tty_wait_background(tp, curthread, SIGTTOU,
LA_UNLOCKED);
if (error)
goto done;
}
+8 -4
View File
@@ -199,7 +199,8 @@ ttydisc_read_canonical(struct tty *tp, struct uio *uio, int ioflag)
ttydisc_read_break(tp, &breakc[0], sizeof(breakc));
do {
error = tty_wait_background(tp, curthread, SIGTTIN);
error = tty_wait_background(tp, curthread, SIGTTIN,
LA_UNLOCKED);
if (error)
return (error);
@@ -279,7 +280,8 @@ ttydisc_read_raw_no_timer(struct tty *tp, struct uio *uio, int ioflag)
*/
for (;;) {
error = tty_wait_background(tp, curthread, SIGTTIN);
error = tty_wait_background(tp, curthread, SIGTTIN,
LA_UNLOCKED);
if (error)
return (error);
@@ -320,7 +322,8 @@ ttydisc_read_raw_read_timer(struct tty *tp, struct uio *uio, int ioflag,
timevaladd(&end, &now);
for (;;) {
error = tty_wait_background(tp, curthread, SIGTTIN);
error = tty_wait_background(tp, curthread, SIGTTIN,
LA_UNLOCKED);
if (error)
return (error);
@@ -373,7 +376,8 @@ ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
*/
for (;;) {
error = tty_wait_background(tp, curthread, SIGTTIN);
error = tty_wait_background(tp, curthread, SIGTTIN,
LA_UNLOCKED);
if (error)
return (error);
+2 -1
View File
@@ -192,7 +192,8 @@ void tty_signal_sessleader(struct tty *tp, int signal);
void tty_signal_pgrp(struct tty *tp, int signal);
/* Waking up readers/writers. */
int tty_wait(struct tty *tp, struct cv *cv);
int tty_wait_background(struct tty *tp, struct thread *td, int sig);
int tty_wait_background(struct tty *tp, struct thread *td, int sig,
int proctree_lock_mode);
int tty_timedwait(struct tty *tp, struct cv *cv, int timo);
void tty_wakeup(struct tty *tp, int flags);