From owner-freebsd-audit Tue Jul 2 7:13:46 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A5DFA37B400; Tue, 2 Jul 2002 07:13:39 -0700 (PDT) Received: from numeri.campus.luth.se (numeri.campus.luth.se [130.240.197.103]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E4FF43E2F; Tue, 2 Jul 2002 07:13:34 -0700 (PDT) (envelope-from k@numeri.campus.luth.se) Received: (from k@localhost) by numeri.campus.luth.se (8.11.6/8.11.6) id g62EDSQ92570; Tue, 2 Jul 2002 16:13:28 +0200 (CEST) (envelope-from k) Date: Tue, 2 Jul 2002 16:13:27 +0200 From: Johan Karlsson To: Bruce Evans Cc: freebsd-audit@FreeBSD.ORG, sheldonh@FreeBSD.ORG Subject: Re: accounting to appen only file Message-ID: <20020702161327.A90890@numeri.campus.luth.se> References: <20020701204140.A49191@numeri.campus.luth.se> <20020702224153.U12090-100000@gamplex.bde.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020702224153.U12090-100000@gamplex.bde.org>; from bde@zeta.org.au on Tue, Jul 02, 2002 at 11:23:48PM +1000 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --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