Date: Tue, 2 Jul 2002 16:13:27 +0200 From: Johan Karlsson <johan@FreeBSD.ORG> To: Bruce Evans <bde@zeta.org.au> Cc: freebsd-audit@FreeBSD.ORG, sheldonh@FreeBSD.ORG Subject: Re: accounting to appen only file Message-ID: <20020702161327.A90890@numeri.campus.luth.se> In-Reply-To: <20020702224153.U12090-100000@gamplex.bde.org>; from bde@zeta.org.au on Tue, Jul 02, 2002 at 11:23:48PM %2B1000 References: <20020701204140.A49191@numeri.campus.luth.se> <20020702224153.U12090-100000@gamplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 02, 2002 at 23:23 (+1000) +0000, Bruce Evans wrote: > Note that the flags variable was only used to discard some changes made > by vn_open(). At least in the direct descendant of vn_open(), these changes > are limited to clearing O_CREAT and O_TRUNC, but we really shouldn't assume > this. Strictly, we should record returned flags for use late like the `file' > layer would do. I have implemented a variant of this, please see the attached patch. take care /Johan K -- Johan Karlsson mailto:johan@FreeBSD.org --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="acct.diff2" Index: kern_acct.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_acct.c,v retrieving revision 1.44 diff -u -r1.44 kern_acct.c --- kern_acct.c 16 May 2002 21:28:11 -0000 1.44 +++ kern_acct.c 2 Jul 2002 14:04:12 -0000 @@ -83,10 +83,11 @@ static struct callout acctwatch_callout; /* - * Accounting vnode pointer, and saved vnode pointer. + * Accounting vnode pointer, saved vnode pointer, and its flags. */ static struct vnode *acctp; static struct vnode *savacctp; +static int acctflags, saveacctflags; /* * Values associated with enabling and disabling accounting @@ -127,19 +128,19 @@ mtx_lock(&Giant); /* * If accounting is to be started to a file, open that file for - * writing and make sure it's a 'normal'. + * appending and make sure it's a 'normal'. */ if (SCARG(uap, path) != NULL) { NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), td); - flags = FWRITE; + flags = FWRITE | O_APPEND; error = vn_open(&nd, &flags, 0); if (error) goto done2; NDFREE(&nd, NDF_ONLY_PNBUF); VOP_UNLOCK(nd.ni_vp, 0, td); if (nd.ni_vp->v_type != VREG) { - vn_close(nd.ni_vp, FWRITE, td->td_ucred, td); + vn_close(nd.ni_vp, flags, td->td_ucred, td); error = EACCES; goto done2; } @@ -151,7 +152,8 @@ */ if (acctp != NULLVP || savacctp != NULLVP) { callout_stop(&acctwatch_callout); - error = vn_close((acctp != NULLVP ? acctp : savacctp), FWRITE, + error = vn_close((acctp != NULLVP ? acctp : savacctp), + (acctp != NULLVP ? acctflags : saveacctflags), td->td_ucred, td); acctp = savacctp = NULLVP; } @@ -163,6 +165,7 @@ * free space watcher. */ acctp = nd.ni_vp; + acctflags = flags; callout_init(&acctwatch_callout, 0); acctwatch(NULL); done2: @@ -316,13 +319,14 @@ if (savacctp != NULLVP) { if (savacctp->v_type == VBAD) { - (void) vn_close(savacctp, FWRITE, NOCRED, NULL); + (void) vn_close(savacctp, saveacctflags, NOCRED, NULL); savacctp = NULLVP; return; } (void)VFS_STATFS(savacctp->v_mount, &sb, (struct thread *)0); if (sb.f_bavail > acctresume * sb.f_blocks / 100) { acctp = savacctp; + acctflags = savacctflags; savacctp = NULLVP; log(LOG_NOTICE, "Accounting resumed\n"); } @@ -330,13 +334,14 @@ if (acctp == NULLVP) return; if (acctp->v_type == VBAD) { - (void) vn_close(acctp, FWRITE, NOCRED, NULL); + (void) vn_close(acctp, acctflags, NOCRED, NULL); acctp = NULLVP; return; } (void)VFS_STATFS(acctp->v_mount, &sb, (struct thread *)0); if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) { savacctp = acctp; + savacctflags = acctflags; acctp = NULLVP; log(LOG_NOTICE, "Accounting suspended\n"); } --azLHFNyN32YCQGCU-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020702161327.A90890>