summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_acct.c
diff options
context:
space:
mode:
authorarr <arr@FreeBSD.org>2002-09-11 04:10:41 +0000
committerarr <arr@FreeBSD.org>2002-09-11 04:10:41 +0000
commit1edd1ad4f200bcf3c1ecd2498c4f44e87820151a (patch)
tree7b2439b58f19152f1f84d6a635e7f21ac910d575 /sys/kern/kern_acct.c
parent82394dd4ea1440281b9e776631db9ced9d9ae027 (diff)
downloadFreeBSD-src-1edd1ad4f200bcf3c1ecd2498c4f44e87820151a.zip
FreeBSD-src-1edd1ad4f200bcf3c1ecd2498c4f44e87820151a.tar.gz
- Lock down the accounting code globals with a subsystem mutex.
Reviewed by: jhb, mdodd
Diffstat (limited to 'sys/kern/kern_acct.c')
-rw-r--r--sys/kern/kern_acct.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 6bbf368..3f07881 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -92,6 +92,9 @@ static struct vnode *savacctp;
static struct ucred *savacctcred;
static int savacctflags;
+static struct mtx acct_mtx;
+MTX_SYSINIT(acct, &acct_mtx, "accounting", MTX_DEF);
+
/*
* Values associated with enabling and disabling accounting
*/
@@ -153,6 +156,8 @@ acct(td, uap)
* If accounting was previously enabled, kill the old space-watcher,
* close the file, and (if no new file was specified, leave).
*/
+
+ mtx_lock(&acct_mtx);
if (acctp != NULLVP || savacctp != NULLVP) {
callout_stop(&acctwatch_callout);
error = vn_close((acctp != NULLVP ? acctp : savacctp),
@@ -175,6 +180,7 @@ acct(td, uap)
callout_init(&acctwatch_callout, 0);
acctwatch(NULL);
done2:
+ mtx_unlock(&acct_mtx);
mtx_unlock(&Giant);
return (error);
}
@@ -194,13 +200,18 @@ acct_process(td)
struct acct acct;
struct rusage *r;
struct timeval ut, st, tmp;
- int t;
+ int t, ret;
struct vnode *vp;
+ struct ucred *uc;
+
+ mtx_lock(&acct_mtx);
/* If accounting isn't enabled, don't bother */
vp = acctp;
- if (vp == NULLVP)
+ if (vp == NULLVP) {
+ mtx_unlock(&acct_mtx);
return (0);
+ }
/*
* Get process accounting information.
@@ -266,9 +277,15 @@ acct_process(td)
* Write the accounting information to the file.
*/
VOP_LEASE(vp, td, acctcred, LEASE_WRITE);
- return (vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct),
- (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, acctcred, NOCRED,
- (int *)0, td));
+ uc = crhold(acctcred);
+ vref(vp);
+ mtx_unlock(&acct_mtx);
+ ret = vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct),
+ (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, uc, NOCRED,
+ (int *)0, td);
+ vrele(vp);
+ crfree(uc);
+ return (ret);
}
/*
@@ -323,12 +340,15 @@ acctwatch(a)
{
struct statfs sb;
+ mtx_lock(&acct_mtx);
+
if (savacctp != NULLVP) {
if (savacctp->v_type == VBAD) {
(void) vn_close(savacctp, savacctflags, savacctcred,
NULL);
savacctp = NULLVP;
savacctcred = NOCRED;
+ mtx_unlock(&acct_mtx);
return;
}
(void)VFS_STATFS(savacctp->v_mount, &sb, (struct thread *)0);
@@ -348,6 +368,7 @@ acctwatch(a)
acctp = NULLVP;
crfree(acctcred);
acctcred = NOCRED;
+ mtx_unlock(&acct_mtx);
return;
}
(void)VFS_STATFS(acctp->v_mount, &sb, (struct thread *)0);
@@ -360,4 +381,5 @@ acctwatch(a)
}
}
callout_reset(&acctwatch_callout, acctchkfreq * hz, acctwatch, NULL);
+ mtx_unlock(&acct_mtx);
}
OpenPOWER on IntegriCloud