xref: /original-bsd/sys/kern/PROTO/44Lite/kern_acct.c (revision ddd31891)
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.1 (Berkeley) 6/14/93
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.
50  */
51 
52 /*
53  * Values associated with enabling and disabling accounting
54  */
55 int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
56 int	acctresume = 4;		/* resume when free space risen to > 4% */
57 int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
58 
59 /*
60  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
61  */
62 struct	vnode *acctp;
63 struct	vnode *savacctp;
64 
65 /* ARGSUSED */
66 void
67 acctwatch(a)
68 	void *a;
69 {
70 	struct statfs sb;
71 
72 	if (savacctp) {
73 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
74 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
75 			acctp = savacctp;
76 			savacctp = NULL;
77 			log(LOG_NOTICE, "Accounting resumed\n");
78 		}
79 	} else {
80 		if (acctp == NULL)
81 			return;
82 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
83 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
84 			savacctp = acctp;
85 			acctp = NULL;
86 			log(LOG_NOTICE, "Accounting suspended\n");
87 		}
88 	}
89 	timeout(acctwatch, NULL, acctchkfreq * hz);
90 }
91