xref: /original-bsd/sys/kern/PROTO/44Lite/kern_acct.c (revision 77c909bc)
1 /*-
2  * Copyright (c) 1982, 1986, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	from: @(#)kern_acct.c 8.8 (Berkeley) 5/14/95
13  */
14 
15 #include <sys/param.h>
16 #include <sys/proc.h>
17 #include <sys/mount.h>
18 #include <sys/vnode.h>
19 #include <sys/file.h>
20 #include <sys/syslog.h>
21 #include <sys/kernel.h>
22 
23 acct(a1, a2, a3)
24 	struct proc *a1;
25 	struct acct_args /* {
26 		syscallarg(char *) path;
27 	} */ *a2;
28 	int *a3;
29 {
30 	/*
31 	 * Body deleted.
32 	 */
33 	return (ENOSYS);
34 }
35 
36 acct_process(a1)
37 	struct proc *a1;
38 {
39 
40 	/*
41 	 * Body deleted.
42 	 */
43 	return;
44 }
45 
46 /*
47  * Periodically check the file system to see if accounting
48  * should be turned on or off. Beware the case where the vnode
49  * has been vgone()'d out from underneath us, e.g. when the file
50  * system containing the accounting file has been forcibly unmounted.
51  */
52 
53 /*
54  * Values associated with enabling and disabling accounting
55  */
56 int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
57 int	acctresume = 4;		/* resume when free space risen to > 4% */
58 int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
59 
60 /*
61  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
62  */
63 struct	vnode *acctp;
64 struct	vnode *savacctp;
65 
66 /* ARGSUSED */
67 void
68 acctwatch(a)
69 	void *a;
70 {
71 	struct statfs sb;
72 
73 	if (savacctp) {
74 		if (savacctp->v_type == VBAD) {
75 			(void) vn_close(savacctp, FWRITE, NOCRED, NULL);
76 			savacctp = NULL;
77 			return;
78 		}
79 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
80 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
81 			acctp = savacctp;
82 			savacctp = NULL;
83 			log(LOG_NOTICE, "Accounting resumed\n");
84 		}
85 	} else {
86 		if (acctp == NULL)
87 			return;
88 		if (acctp->v_type == VBAD) {
89 			(void) vn_close(acctp, FWRITE, NOCRED, NULL);
90 			acctp = NULL;
91 			return;
92 		}
93 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
94 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
95 			savacctp = acctp;
96 			acctp = NULL;
97 			log(LOG_NOTICE, "Accounting suspended\n");
98 		}
99 	}
100 	timeout(acctwatch, NULL, acctchkfreq * hz);
101 }
102