Home | History | Annotate | Line # | Download | only in kern
kern_acct.c revision 1.1.1.2
      1  1.1.1.2  fvdl /*-
      2  1.1.1.2  fvdl  * Copyright (c) 1982, 1986, 1989, 1993
      3  1.1.1.2  fvdl  *	The Regents of the University of California.  All rights reserved.
      4  1.1.1.2  fvdl  * (c) UNIX System Laboratories, Inc.
      5  1.1.1.2  fvdl  * All or some portions of this file are derived from material licensed
      6  1.1.1.2  fvdl  * to the University of California by American Telephone and Telegraph
      7  1.1.1.2  fvdl  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
      8  1.1.1.2  fvdl  * the permission of UNIX System Laboratories, Inc.
      9  1.1.1.2  fvdl  *
     10  1.1.1.2  fvdl  * Redistribution and use in source and binary forms, with or without
     11  1.1.1.2  fvdl  * modification, are permitted provided that the following conditions
     12  1.1.1.2  fvdl  * are met:
     13  1.1.1.2  fvdl  * 1. Redistributions of source code must retain the above copyright
     14  1.1.1.2  fvdl  *    notice, this list of conditions and the following disclaimer.
     15  1.1.1.2  fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.1.2  fvdl  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.1.2  fvdl  *    documentation and/or other materials provided with the distribution.
     18  1.1.1.2  fvdl  * 3. All advertising materials mentioning features or use of this software
     19  1.1.1.2  fvdl  *    must display the following acknowledgement:
     20  1.1.1.2  fvdl  *	This product includes software developed by the University of
     21  1.1.1.2  fvdl  *	California, Berkeley and its contributors.
     22  1.1.1.2  fvdl  * 4. Neither the name of the University nor the names of its contributors
     23  1.1.1.2  fvdl  *    may be used to endorse or promote products derived from this software
     24  1.1.1.2  fvdl  *    without specific prior written permission.
     25  1.1.1.2  fvdl  *
     26  1.1.1.2  fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1.1.2  fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1.1.2  fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1.1.2  fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1.1.2  fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1.1.2  fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1.1.2  fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1.1.2  fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1.1.2  fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1.1.2  fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1.1.2  fvdl  * SUCH DAMAGE.
     37  1.1.1.2  fvdl  *
     38  1.1.1.2  fvdl  *	from: @(#)kern_acct.c	8.1 (Berkeley) 6/14/93
     39  1.1.1.2  fvdl  */
     40  1.1.1.2  fvdl 
     41  1.1.1.2  fvdl #include <sys/param.h>
     42  1.1.1.2  fvdl #include <sys/proc.h>
     43  1.1.1.2  fvdl #include <sys/mount.h>
     44  1.1.1.2  fvdl #include <sys/vnode.h>
     45  1.1.1.2  fvdl #include <sys/file.h>
     46  1.1.1.2  fvdl #include <sys/syslog.h>
     47  1.1.1.2  fvdl #include <sys/kernel.h>
     48  1.1.1.2  fvdl 
     49  1.1.1.2  fvdl struct acct_args {
     50  1.1.1.2  fvdl 	char	*fname;
     51  1.1.1.2  fvdl };
     52  1.1.1.2  fvdl acct(a1, a2, a3)
     53  1.1.1.2  fvdl 	struct proc *a1;
     54  1.1.1.2  fvdl 	struct acct_args *a2;
     55  1.1.1.2  fvdl 	int *a3;
     56  1.1.1.2  fvdl {
     57  1.1.1.2  fvdl 	/*
     58  1.1.1.2  fvdl 	 * Body deleted.
     59  1.1.1.2  fvdl 	 */
     60  1.1.1.2  fvdl 	return (ENOSYS);
     61  1.1.1.2  fvdl }
     62  1.1.1.2  fvdl 
     63  1.1.1.2  fvdl acct_process(a1)
     64  1.1.1.2  fvdl 	struct proc *a1;
     65  1.1.1.2  fvdl {
     66  1.1.1.2  fvdl 
     67  1.1.1.2  fvdl 	/*
     68  1.1.1.2  fvdl 	 * Body deleted.
     69  1.1.1.2  fvdl 	 */
     70  1.1.1.2  fvdl 	return;
     71  1.1.1.2  fvdl }
     72  1.1.1.2  fvdl 
     73  1.1.1.2  fvdl /*
     74  1.1.1.2  fvdl  * Periodically check the file system to see if accounting
     75  1.1.1.2  fvdl  * should be turned on or off.
     76  1.1.1.2  fvdl  */
     77  1.1.1.2  fvdl 
     78  1.1.1.2  fvdl /*
     79  1.1.1.2  fvdl  * Values associated with enabling and disabling accounting
     80  1.1.1.2  fvdl  */
     81  1.1.1.2  fvdl int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
     82  1.1.1.2  fvdl int	acctresume = 4;		/* resume when free space risen to > 4% */
     83  1.1.1.2  fvdl int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
     84  1.1.1.2  fvdl 
     85  1.1.1.2  fvdl /*
     86  1.1.1.2  fvdl  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
     87  1.1.1.2  fvdl  */
     88  1.1.1.2  fvdl struct	vnode *acctp;
     89  1.1.1.2  fvdl struct	vnode *savacctp;
     90  1.1.1.2  fvdl 
     91  1.1.1.2  fvdl /* ARGSUSED */
     92  1.1.1.2  fvdl void
     93  1.1.1.2  fvdl acctwatch(a)
     94  1.1.1.2  fvdl 	void *a;
     95  1.1.1.2  fvdl {
     96  1.1.1.2  fvdl 	struct statfs sb;
     97  1.1.1.2  fvdl 
     98  1.1.1.2  fvdl 	if (savacctp) {
     99  1.1.1.2  fvdl 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
    100  1.1.1.2  fvdl 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
    101  1.1.1.2  fvdl 			acctp = savacctp;
    102  1.1.1.2  fvdl 			savacctp = NULL;
    103  1.1.1.2  fvdl 			log(LOG_NOTICE, "Accounting resumed\n");
    104  1.1.1.2  fvdl 		}
    105  1.1.1.2  fvdl 	} else {
    106  1.1.1.2  fvdl 		if (acctp == NULL)
    107  1.1.1.2  fvdl 			return;
    108  1.1.1.2  fvdl 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
    109  1.1.1.2  fvdl 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
    110  1.1.1.2  fvdl 			savacctp = acctp;
    111  1.1.1.2  fvdl 			acctp = NULL;
    112  1.1.1.2  fvdl 			log(LOG_NOTICE, "Accounting suspended\n");
    113  1.1.1.2  fvdl 		}
    114  1.1.1.2  fvdl 	}
    115  1.1.1.2  fvdl 	timeout(acctwatch, NULL, acctchkfreq * hz);
    116  1.1.1.2  fvdl }
    117