Re: accounting to appen only file

Johan Karlsson <[email protected]>
Newsgroups gmane.os.freebsd.devel.audit
Message-ID <[email protected]>
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:[email protected]
acct.diff2 (text/plain, 2.7 KB)
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");
 		}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.