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 32 /* 33 * Enable or disable process accounting. 34 * 35 * If a non-null filename is given, that file is used to store accounting 36 * records on process exit. If a null filename is given process accounting 37 * is suspended. If accounting is enabled, the system checks the amount 38 * of freespace on the filesystem at timeval intervals. If the amount of 39 * freespace is below acctsuspend percent, accounting is suspended. If 40 * accounting has been suspended, and freespace rises above acctresume, 41 * accounting is resumed. 42 */ 43 /* ARGSUSED */ 44 sysacct(p, uap, retval) 45 struct proc *p; 46 struct args { 47 char *fname; 48 } *uap; 49 int *retval; 50 { 51 52 /* 53 * Body deleted. 54 */ 55 return (ENOSYS); 56 } 57 58 /* 59 * Periodically check the file system to see if accounting 60 * should be turned on or off. 61 */ 62 acctwatch(resettime) 63 struct timeval *resettime; 64 { 65 struct statfs sb; 66 67 if (savacctp) { 68 (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0); 69 if (sb.f_bavail > acctresume * sb.f_blocks / 100) { 70 acctp = savacctp; 71 savacctp = NULL; 72 log(LOG_NOTICE, "Accounting resumed\n"); 73 return; 74 } 75 } 76 if (acctp == NULL) 77 return; 78 (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0); 79 if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) { 80 savacctp = acctp; 81 acctp = NULL; 82 log(LOG_NOTICE, "Accounting suspended\n"); 83 } 84 timeout(acctwatch, (caddr_t)resettime, hzto(resettime)); 85 } 86 87 /* 88 * This routine calculates an accounting record for a process and, 89 * if accounting is enabled, writes it to the accounting file. 90 */ 91 acct(p) 92 register struct proc *p; 93 { 94 95 /* 96 * Body deleted. 97 */ 98 return; 99 } 100