BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / kern_acct.c
CommitLineData
da7c5cc6 1/*
c4ec2128 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
af359dea 3 * All rights reserved.
da7c5cc6 4 *
af359dea
C
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
da7c5cc6 34 */
06138e31 35
94368568
JB
36#include "param.h"
37#include "systm.h"
3789a403
MK
38#include "namei.h"
39#include "resourcevar.h"
556dc220 40#include "proc.h"
8c7d0e2a
KM
41#include "ioctl.h"
42#include "termios.h"
43#include "tty.h"
c4ec2128
KM
44#include "vnode.h"
45#include "mount.h"
94368568 46#include "kernel.h"
46e4c6f8 47#include "file.h"
94368568 48#include "acct.h"
c4ec2128
KM
49#include "syslog.h"
50
51/*
52 * Values associated with enabling and disabling accounting
53 */
54int acctsuspend = 2; /* stop accounting when < 2% free space left */
55int acctresume = 4; /* resume when free space risen to > 4% */
56struct timeval chk = { 15, 0 };/* frequency to check space for accounting */
af359dea
C
57struct vnode *acctp; /* file to which to do accounting */
58struct vnode *savacctp; /* file to which to do accounting when space */
06138e31
SL
59
60/*
af359dea
C
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.
06138e31 70 */
8c7d0e2a
KM
71/* ARGSUSED */
72sysacct(p, uap, retval)
73 struct proc *p;
74 struct args {
75 char *fname;
76 } *uap;
77 int *retval;
06138e31 78{
06138e31 79
af359dea
C
80 /*
81 * Body deleted.
82 */
83 return (ENOSYS);
06138e31
SL
84}
85
06138e31 86/*
c4ec2128
KM
87 * Periodically check the file system to see if accounting
88 * should be turned on or off.
06138e31 89 */
c4ec2128
KM
90acctwatch(resettime)
91 struct timeval *resettime;
06138e31 92{
c4ec2128 93 struct statfs sb;
06138e31
SL
94
95 if (savacctp) {
6bcdc4f3 96 (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
c4ec2128 97 if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
06138e31
SL
98 acctp = savacctp;
99 savacctp = NULL;
c4ec2128
KM
100 log(LOG_NOTICE, "Accounting resumed\n");
101 return;
06138e31
SL
102 }
103 }
c4ec2128 104 if (acctp == NULL)
06138e31 105 return;
6bcdc4f3 106 (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
c4ec2128 107 if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
06138e31
SL
108 savacctp = acctp;
109 acctp = NULL;
c4ec2128 110 log(LOG_NOTICE, "Accounting suspended\n");
06138e31 111 }
c4ec2128
KM
112 timeout(acctwatch, (caddr_t)resettime, hzto(resettime));
113}
114
115/*
af359dea
C
116 * This routine calculates an accounting record for a process and,
117 * if accounting is enabled, writes it to the accounting file.
c4ec2128 118 */
8c7d0e2a
KM
119acct(p)
120 register struct proc *p;
c4ec2128 121{
06138e31 122
af359dea
C
123 /*
124 * Body deleted.
125 */
126 return;
06138e31 127}