xref: /original-bsd/sys/kern/PROTO/44Lite/kern_acct.c (revision f4a18198)
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.4 (Berkeley) 6/2/94
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 struct acct_args {
24 	char	*fname;
25 };
26 acct(a1, a2, a3)
27 	struct proc *a1;
28 	struct acct_args *a2;
29 	int *a3;
30 {
31 	/*
32 	 * Body deleted.
33 	 */
34 	return (ENOSYS);
35 }
36 
37 acct_process(a1)
38 	struct proc *a1;
39 {
40 
41 	/*
42 	 * Body deleted.
43 	 */
44 	return;
45 }
46 
47 /*
48  * Periodically check the file system to see if accounting
49  * should be turned on or off. Beware the case where the vnode
50  * has been vgone()'d out from underneath us, e.g. when the file
51  * system containing the accounting file has been forcibly unmounted.
52  */
53 
54 /*
55  * Values associated with enabling and disabling accounting
56  */
57 int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
58 int	acctresume = 4;		/* resume when free space risen to > 4% */
59 int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
60 
61 /*
62  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
63  */
64 struct	vnode *acctp;
65 struct	vnode *savacctp;
66 
67 /* ARGSUSED */
68 void
69 acctwatch(a)
70 	void *a;
71 {
72 	struct statfs sb;
73 
74 	if (savacctp) {
75 		if (savacctp->v_type == VBAD) {
76 			(void) vn_close(savacctp, FWRITE, NOCRED, NULL);
77 			savacctp = NULL;
78 			return;
79 		}
80 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
81 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
82 			acctp = savacctp;
83 			savacctp = NULL;
84 			log(LOG_NOTICE, "Accounting resumed\n");
85 		}
86 	} else {
87 		if (acctp == NULL)
88 			return;
89 		if (acctp->v_type == VBAD) {
90 			(void) vn_close(acctp, FWRITE, NOCRED, NULL);
91 			acctp = NULL;
92 			return;
93 		}
94 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
95 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
96 			savacctp = acctp;
97 			acctp = NULL;
98 			log(LOG_NOTICE, "Accounting suspended\n");
99 		}
100 	}
101 	timeout(acctwatch, NULL, acctchkfreq * hz);
102 }
103