summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_prf.c
diff options
context:
space:
mode:
authortanimura <tanimura@FreeBSD.org>2002-02-23 11:12:57 +0000
committertanimura <tanimura@FreeBSD.org>2002-02-23 11:12:57 +0000
commita09da298590e8c11ebafa37f79e0046814665237 (patch)
tree2289c653c0f7aa23498f82b603c33107952652ec /sys/kern/subr_prf.c
parent33e8ee5265ca2838260ab581a9cebdedb1e1e29b (diff)
downloadFreeBSD-src-a09da298590e8c11ebafa37f79e0046814665237.zip
FreeBSD-src-a09da298590e8c11ebafa37f79e0046814665237.tar.gz
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)
Diffstat (limited to 'sys/kern/subr_prf.c')
-rw-r--r--sys/kern/subr_prf.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index daa38e4..034a63c 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -41,6 +41,9 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/sx.h>
#include <sys/kernel.h>
#include <sys/msgbuf.h>
#include <sys/malloc.h>
@@ -113,16 +116,28 @@ uprintf(const char *fmt, ...)
struct proc *p = td->td_proc;
va_list ap;
struct putchar_arg pca;
- int retval = 0;
+ int retval;
+
+ if (td == NULL || td == PCPU_GET(idlethread))
+ return (0);
- if (td && td != PCPU_GET(idlethread) && p->p_flag & P_CONTROLT &&
- p->p_session->s_ttyvp) {
- va_start(ap, fmt);
- pca.tty = p->p_session->s_ttyp;
- pca.flags = TOTTY;
- retval = kvprintf(fmt, putchar, &pca, 10, ap);
- va_end(ap);
+ p = td->td_proc;
+ PROC_LOCK(p);
+ if ((p->p_flag & P_CONTROLT) == 0) {
+ PROC_UNLOCK(p);
+ return (0);
}
+ SESS_LOCK(p->p_session);
+ pca.tty = p->p_session->s_ttyp;
+ SESS_UNLOCK(p->p_session);
+ PROC_UNLOCK(p);
+ if (pca.tty == NULL)
+ return (0);
+ pca.flags = TOTTY;
+ va_start(ap, fmt);
+ retval = kvprintf(fmt, putchar, &pca, 10, ap);
+ va_end(ap);
+
return (retval);
}
@@ -141,13 +156,23 @@ tprintf(struct proc *p, int pri, const char *fmt, ...)
if (pri != -1)
flags |= TOLOG;
- if (p && p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
- SESSHOLD(p->p_session);
- shld++;
- if (ttycheckoutq(p->p_session->s_ttyp, 0)) {
- flags |= TOTTY;
+ if (p != NULL) {
+ PGRPSESS_XLOCK();
+ PROC_LOCK(p);
+ if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
+ SESS_LOCK(p->p_session);
+ SESSHOLD(p->p_session);
tp = p->p_session->s_ttyp;
- }
+ SESS_UNLOCK(p->p_session);
+ PROC_UNLOCK(p);
+ shld++;
+ if (ttycheckoutq(tp, 0))
+ flags |= TOTTY;
+ else
+ tp = NULL;
+ } else
+ PROC_UNLOCK(p);
+ PGRPSESS_XUNLOCK();
}
pca.pri = pri;
pca.tty = tp;
@@ -155,8 +180,13 @@ tprintf(struct proc *p, int pri, const char *fmt, ...)
va_start(ap, fmt);
retval = kvprintf(fmt, putchar, &pca, 10, ap);
va_end(ap);
- if (shld)
+ if (shld) {
+ PGRPSESS_XLOCK();
+ SESS_LOCK(p->p_session);
SESSRELE(p->p_session);
+ SESS_UNLOCK(p->p_session);
+ PGRPSESS_XUNLOCK();
+ }
msgbuftrigger = 1;
}
OpenPOWER on IntegriCloud