165791Smckusick /*-
265791Smckusick  * Copyright (c) 1982, 1986, 1989, 1993
365791Smckusick  *	The Regents of the University of California.  All rights reserved.
465791Smckusick  * (c) UNIX System Laboratories, Inc.
565791Smckusick  * All or some portions of this file are derived from material licensed
665791Smckusick  * to the University of California by American Telephone and Telegraph
765791Smckusick  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
865791Smckusick  * the permission of UNIX System Laboratories, Inc.
949676Smckusick  *
1049676Smckusick  * %sccs.include.redist.c%
1149676Smckusick  *
12*69695Smckusick  *	from: @(#)kern_acct.c 8.8 (Berkeley) 5/14/95
1349676Smckusick  */
1449676Smckusick 
1565791Smckusick #include <sys/param.h>
1665791Smckusick #include <sys/proc.h>
1765791Smckusick #include <sys/mount.h>
1865791Smckusick #include <sys/vnode.h>
1965791Smckusick #include <sys/file.h>
2065791Smckusick #include <sys/syslog.h>
2165791Smckusick #include <sys/kernel.h>
2249676Smckusick 
2365791Smckusick acct(a1, a2, a3)
2465791Smckusick 	struct proc *a1;
25*69695Smckusick 	struct acct_args /* {
26*69695Smckusick 		syscallarg(char *) path;
27*69695Smckusick 	} */ *a2;
2865791Smckusick 	int *a3;
2965791Smckusick {
3065791Smckusick 	/*
3165791Smckusick 	 * Body deleted.
3265791Smckusick 	 */
3365791Smckusick 	return (ENOSYS);
3465791Smckusick }
3549676Smckusick 
3665791Smckusick acct_process(a1)
3765791Smckusick 	struct proc *a1;
3849676Smckusick {
3949676Smckusick 
4049676Smckusick 	/*
4149676Smckusick 	 * Body deleted.
4249676Smckusick 	 */
4365791Smckusick 	return;
4449676Smckusick }
4549676Smckusick 
4649676Smckusick /*
4749676Smckusick  * Periodically check the file system to see if accounting
4867360Smckusick  * should be turned on or off. Beware the case where the vnode
4967360Smckusick  * has been vgone()'d out from underneath us, e.g. when the file
5067360Smckusick  * system containing the accounting file has been forcibly unmounted.
5149676Smckusick  */
5265791Smckusick 
5365791Smckusick /*
5465791Smckusick  * Values associated with enabling and disabling accounting
5565791Smckusick  */
5665791Smckusick int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
5765791Smckusick int	acctresume = 4;		/* resume when free space risen to > 4% */
5865791Smckusick int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
5965791Smckusick 
6065791Smckusick /*
6165791Smckusick  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
6265791Smckusick  */
6365791Smckusick struct	vnode *acctp;
6465791Smckusick struct	vnode *savacctp;
6565791Smckusick 
6665791Smckusick /* ARGSUSED */
6765791Smckusick void
acctwatch(a)6865791Smckusick acctwatch(a)
6965791Smckusick 	void *a;
7049676Smckusick {
7149676Smckusick 	struct statfs sb;
7249676Smckusick 
7349676Smckusick 	if (savacctp) {
7467360Smckusick 		if (savacctp->v_type == VBAD) {
7567360Smckusick 			(void) vn_close(savacctp, FWRITE, NOCRED, NULL);
7667360Smckusick 			savacctp = NULL;
7767360Smckusick 			return;
7867360Smckusick 		}
7949676Smckusick 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
8049676Smckusick 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
8149676Smckusick 			acctp = savacctp;
8249676Smckusick 			savacctp = NULL;
8349676Smckusick 			log(LOG_NOTICE, "Accounting resumed\n");
8465791Smckusick 		}
8565791Smckusick 	} else {
8665791Smckusick 		if (acctp == NULL)
8749676Smckusick 			return;
8867360Smckusick 		if (acctp->v_type == VBAD) {
8967360Smckusick 			(void) vn_close(acctp, FWRITE, NOCRED, NULL);
9067360Smckusick 			acctp = NULL;
9167360Smckusick 			return;
9267360Smckusick 		}
9365791Smckusick 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
9465791Smckusick 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
9565791Smckusick 			savacctp = acctp;
9665791Smckusick 			acctp = NULL;
9765791Smckusick 			log(LOG_NOTICE, "Accounting suspended\n");
9849676Smckusick 		}
9949676Smckusick 	}
10065791Smckusick 	timeout(acctwatch, NULL, acctchkfreq * hz);
10149676Smckusick }
102