|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
33: * from: @(#)kern_acct.c 7.18 (Berkeley) 5/11/91
34: */
35:
36: #include "param.h"
37: #include "systm.h"
38: #include "namei.h"
39: #include "resourcevar.h"
40: #include "proc.h"
41: #include "ioctl.h"
42: #include "termios.h"
43: #include "tty.h"
44: #include "vnode.h"
45: #include "mount.h"
46: #include "kernel.h"
47: #include "file.h"
48: #include "acct.h"
49: #include "syslog.h"
50:
51: /*
52: * Values associated with enabling and disabling accounting
53: */
54: int acctsuspend = 2; /* stop accounting when < 2% free space left */
55: int acctresume = 4; /* resume when free space risen to > 4% */
56: struct timeval chk = { 15, 0 };/* frequency to check space for accounting */
57: struct vnode *acctp; /* file to which to do accounting */
58: struct vnode *savacctp; /* file to which to do accounting when space */
59:
60: /*
61: * Enable or disable process accounting.
62: *
63: * If a non-null filename is given, that file is used to store accounting
64: * records on process exit. If a null filename is given process accounting
65: * is suspended. If accounting is enabled, the system checks the amount
66: * of freespace on the filesystem at timeval intervals. If the amount of
67: * freespace is below acctsuspend percent, accounting is suspended. If
68: * accounting has been suspended, and freespace rises above acctresume,
69: * accounting is resumed.
70: */
71: /* ARGSUSED */
72: sysacct(p, uap, retval)
73: struct proc *p;
74: struct args {
75: char *fname;
76: } *uap;
77: int *retval;
78: {
79:
80: /*
81: * Body deleted.
82: */
83: return (ENOSYS);
84: }
85:
86: /*
87: * Periodically check the file system to see if accounting
88: * should be turned on or off.
89: */
90: acctwatch(resettime)
91: struct timeval *resettime;
92: {
93: struct statfs sb;
94:
95: if (savacctp) {
96: (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
97: if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
98: acctp = savacctp;
99: savacctp = NULL;
100: log(LOG_NOTICE, "Accounting resumed\n");
101: return;
102: }
103: }
104: if (acctp == NULL)
105: return;
106: (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
107: if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
108: savacctp = acctp;
109: acctp = NULL;
110: log(LOG_NOTICE, "Accounting suspended\n");
111: }
112: timeout(acctwatch, (caddr_t)resettime, hzto(resettime));
113: }
114:
115: /*
116: * This routine calculates an accounting record for a process and,
117: * if accounting is enabled, writes it to the accounting file.
118: */
119: acct(p)
120: register struct proc *p;
121: {
122:
123: /*
124: * Body deleted.
125: */
126: return;
127: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.