From a09da298590e8c11ebafa37f79e0046814665237 Mon Sep 17 00:00:00 2001 From: tanimura Date: Sat, 23 Feb 2002 11:12:57 +0000 Subject: Lock struct pgrp, session and sigio. New locks are: - pgrpsess_lock which locks the whole pgrps and sessions, - pg_mtx which protects the pgrp members, and - s_mtx which protects the session members. Please refer to sys/proc.h for the coverage of these locks. Changes on the pgrp/session interface: - pgfind() needs the pgrpsess_lock held. - The caller of enterpgrp() is responsible to allocate a new pgrp and session. - Call enterthispgrp() in order to enter an existing pgrp. - pgsignal() requires a pgrp lock held. Reviewed by: jhb, alfred Tested on: cvsup.jp.FreeBSD.org (which is a quad-CPU machine running -current) --- sys/kern/tty_pty.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'sys/kern/tty_pty.c') diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 6f1c0db..b3fcc8d 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -41,6 +41,9 @@ #include "opt_compat.h" #include #include +#include +#include +#include #if defined(COMPAT_43) || defined(COMPAT_SUNOS) #include #endif @@ -237,11 +240,19 @@ ptsread(dev, uio, flag) again: if (pti->pt_flags & PF_REMOTE) { while (isbackground(p, tp)) { + PGRPSESS_SLOCK(); + PROC_LOCK(p); if (SIGISMEMBER(p->p_sigignore, SIGTTIN) || SIGISMEMBER(p->p_sigmask, SIGTTIN) || - p->p_pgrp->pg_jobc == 0 || p->p_flag & P_PPWAIT) + p->p_pgrp->pg_jobc == 0 || p->p_flag & P_PPWAIT) { + PROC_UNLOCK(p); return (EIO); + } + PROC_UNLOCK(p); + PGRP_LOCK(p->p_pgrp); + PGRPSESS_SUNLOCK(); pgsignal(p->p_pgrp, SIGTTIN, 1); + PGRP_UNLOCK(p->p_pgrp); error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, "ptsbg", 0); if (error) @@ -715,7 +726,11 @@ ptyioctl(dev, cmd, data, flag, td) return(EINVAL); if ((tp->t_lflag&NOFLSH) == 0) ttyflush(tp, FREAD|FWRITE); - pgsignal(tp->t_pgrp, *(unsigned int *)data, 1); + if (tp->t_pgrp != NULL) { + PGRP_LOCK(tp->t_pgrp); + pgsignal(tp->t_pgrp, *(unsigned int *)data, 1); + PGRP_UNLOCK(tp->t_pgrp); + } if ((*(unsigned int *)data == SIGINFO) && ((tp->t_lflag&NOKERNINFO) == 0)) ttyinfo(tp); -- cgit v1.1