summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_prf.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2005-09-26 08:02:24 +0000
committerrwatson <rwatson@FreeBSD.org>2005-09-26 08:02:24 +0000
commit0106e151c3c4cbbe01b965a029f455618053512b (patch)
tree1e2342e36c143f3ce124a74aae5fa0bf47adafef /sys/kern/subr_prf.c
parent88a1a84601b5e9e9e80cf61d084471228d38bd5e (diff)
downloadFreeBSD-src-0106e151c3c4cbbe01b965a029f455618053512b.zip
FreeBSD-src-0106e151c3c4cbbe01b965a029f455618053512b.tar.gz
Acquire Giant in uprintf() and tprintf() rather than asserting it. In
the vast majority of cases, these functions are called without mutexes held, meaning that in all but two cases, there will be no ordering issues with doing this, and it will eliminate the need for changes in the caller. In two cases, mutexes are held, so Giant must be acquired before those mutexes such that uprintf() and tprintf() recurse Giant rather than generating a lock order reversal. Suggested by: bde
Diffstat (limited to 'sys/kern/subr_prf.c')
-rw-r--r--sys/kern/subr_prf.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 04bdb6d..8184c01 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -127,27 +127,31 @@ uprintf(const char *fmt, ...)
struct putchar_arg pca;
int retval;
- GIANT_REQUIRED;
if (td == NULL || td == PCPU_GET(idlethread))
return (0);
+ mtx_lock(&Giant);
p = td->td_proc;
PROC_LOCK(p);
if ((p->p_flag & P_CONTROLT) == 0) {
PROC_UNLOCK(p);
- return (0);
+ retval = 0;
+ goto out;
}
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);
+ if (pca.tty == NULL) {
+ retval = 0;
+ goto out;
+ }
pca.flags = TOTTY;
va_start(ap, fmt);
retval = kvprintf(fmt, putchar, &pca, 10, ap);
va_end(ap);
-
+out:
+ mtx_unlock(&Giant);
return (retval);
}
@@ -164,7 +168,7 @@ tprintf(struct proc *p, int pri, const char *fmt, ...)
struct putchar_arg pca;
struct session *sess = NULL;
- GIANT_REQUIRED;
+ mtx_lock(&Giant);
if (pri != -1)
flags |= TOLOG;
if (p != NULL) {
@@ -192,6 +196,7 @@ tprintf(struct proc *p, int pri, const char *fmt, ...)
if (sess != NULL)
SESSRELE(sess);
msgbuftrigger = 1;
+ mtx_unlock(&Giant);
}
/*
OpenPOWER on IntegriCloud