1 /* 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * from: @(#)kern_acct.c 7.18 (Berkeley) 5/11/91 8 */ 9 10 #include "param.h" 11 #include "systm.h" 12 #include "namei.h" 13 #include "resourcevar.h" 14 #include "proc.h" 15 #include "ioctl.h" 16 #include "termios.h" 17 #include "tty.h" 18 #include "vnode.h" 19 #include "mount.h" 20 #include "kernel.h" 21 #include "file.h" 22 #include "acct.h" 23 #include "syslog.h" 24 25 /* 26 * Values associated with enabling and disabling accounting 27 */ 28 int acctsuspend = 2; /* stop accounting when < 2% free space left */ 29 int acctresume = 4; /* resume when free space risen to > 4% */ 30 struct timeval chk = { 15, 0 };/* frequency to check space for accounting */ 31 struct vnode *acctp; /* file to which to do accounting */ 32 struct vnode *savacctp; /* file to which to do accounting when space */ 33 34 /* 35 * Enable or disable process accounting. 36 * 37 * If a non-null filename is given, that file is used to store accounting 38 * records on process exit. If a null filename is given process accounting 39 * is suspended. If accounting is enabled, the system checks the amount 40 * of freespace on the filesystem at timeval intervals. If the amount of 41 * freespace is below acctsuspend percent, accounting is suspended. If 42 * accounting has been suspended, and freespace rises above acctresume, 43 * accounting is resumed. 44 */ 45 /* ARGSUSED */ 46 sysacct(p, uap, retval) 47 struct proc *p; 48 struct args { 49 char *fname; 50 } *uap; 51 int *retval; 52 { 53 54 /* 55 * Body deleted. 56 */ 57 return (ENOSYS); 58 } 59 60 /* 61 * Periodically check the file system to see if accounting 62 * should be turned on or off. 63 */ 64 acctwatch(resettime) 65 struct timeval *resettime; 66 { 67 struct statfs sb; 68 69 if (savacctp) { 70 (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0); 71 if (sb.f_bavail > acctresume * sb.f_blocks / 100) { 72 acctp = savacctp; 73 savacctp = NULL; 74 log(LOG_NOTICE, "Accounting resumed\n"); 75 return; 76 } 77 } 78 if (acctp == NULL) 79 return; 80 (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0); 81 if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) { 82 savacctp = acctp; 83 acctp = NULL; 84 log(LOG_NOTICE, "Accounting suspended\n"); 85 } 86 timeout(acctwatch, (caddr_t)resettime, hzto(resettime)); 87 } 88 89 /* 90 * This routine calculates an accounting record for a process and, 91 * if accounting is enabled, writes it to the accounting file. 92 */ 93 acct(p) 94 register struct proc *p; 95 { 96 97 /* 98 * Body deleted. 99 */ 100 return; 101 } 102