changed \&ps to ps in man page
[unix-history] / sys / kern / kern_acct.c
CommitLineData
15637ed4
RG
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 */
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 */
57struct vnode *acctp; /* file to which to do accounting */
58struct 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 */
3c7eb27c
DG
71
72struct sysacct_args {
73 char *fname;
74};
75
15637ed4
RG
76/* ARGSUSED */
77sysacct(p, uap, retval)
78 struct proc *p;
3c7eb27c 79 struct sysacct_args *uap;
15637ed4
RG
80 int *retval;
81{
82
83 /*
84 * Body deleted.
85 */
86 return (ENOSYS);
87}
88
89/*
90 * Periodically check the file system to see if accounting
91 * should be turned on or off.
92 */
93acctwatch(resettime)
94 struct timeval *resettime;
95{
96 struct statfs sb;
97
98 if (savacctp) {
99 (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
100 if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
101 acctp = savacctp;
102 savacctp = NULL;
103 log(LOG_NOTICE, "Accounting resumed\n");
104 return;
105 }
106 }
107 if (acctp == NULL)
108 return;
109 (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
110 if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
111 savacctp = acctp;
112 acctp = NULL;
113 log(LOG_NOTICE, "Accounting suspended\n");
114 }
115 timeout(acctwatch, (caddr_t)resettime, hzto(resettime));
116}
117
118/*
119 * This routine calculates an accounting record for a process and,
120 * if accounting is enabled, writes it to the accounting file.
121 */
122acct(p)
123 register struct proc *p;
124{
125
126 /*
127 * Body deleted.
128 */
129 return;
130}