|
|
1.1 ! root 1: /* acct.c 4.4 81/03/08 */ ! 2: ! 3: #include "sys/param.h" ! 4: #include "sys/systm.h" ! 5: #include "sys/acct.h" ! 6: #include "sys/user.h" ! 7: #include "sys/inode.h" ! 8: ! 9: struct inode *acctp; ! 10: ! 11: /* ! 12: * Perform process accounting functions. ! 13: */ ! 14: sysacct() ! 15: { ! 16: register struct inode *ip; ! 17: register struct a { ! 18: char *fname; ! 19: } *uap; ! 20: ! 21: uap = (struct a *)u.u_ap; ! 22: if (suser() == 0) ! 23: return; ! 24: if (uap->fname==NULL) { ! 25: if (ip = acctp) { ! 26: plock(ip); ! 27: iput(ip); ! 28: acctp = NULL; ! 29: } ! 30: return; ! 31: } ! 32: if (acctp) { ! 33: u.u_error = EBUSY; ! 34: return; ! 35: } ! 36: ip = namei(uap->fname, SEGUDATA, &nilargnamei, 1); ! 37: if(ip == NULL) ! 38: return; ! 39: if((ip->i_mode & IFMT) != IFREG) { ! 40: u.u_error = EACCES; ! 41: iput(ip); ! 42: return; ! 43: } ! 44: if (access(ip, IWRITE)) { ! 45: iput(ip); ! 46: return; ! 47: } ! 48: acctp = ip; ! 49: prele(ip); ! 50: } ! 51: ! 52: struct acct acctbuf; ! 53: /* ! 54: * On exit, write a record on the accounting file. ! 55: */ ! 56: acct() ! 57: { ! 58: register i; ! 59: register struct inode *ip; ! 60: off_t siz; ! 61: register struct acct *ap = &acctbuf; ! 62: ! 63: if ((ip=acctp)==NULL) ! 64: return; ! 65: plock(ip); ! 66: for (i=0; i<sizeof(ap->ac_comm); i++) ! 67: ap->ac_comm[i] = u.u_comm[i]; ! 68: ap->ac_utime = compress((long)u.u_vm.vm_utime); ! 69: ap->ac_stime = compress((long)u.u_vm.vm_stime); ! 70: ap->ac_etime = compress((long)(time - u.u_start)); ! 71: ap->ac_btime = u.u_start; ! 72: ap->ac_uid = u.u_ruid; ! 73: ap->ac_gid = u.u_rgid; ! 74: ap->ac_mem = 0; ! 75: if (i = u.u_vm.vm_utime + u.u_vm.vm_stime) ! 76: ap->ac_mem = (u.u_vm.vm_ixrss + u.u_vm.vm_idsrss) / i; ! 77: ap->ac_io = compress((long)(u.u_vm.vm_inblk + u.u_vm.vm_oublk)); ! 78: ap->ac_tty = u.u_ttyino; ! 79: ap->ac_flag = u.u_acflag; ! 80: siz = ip->i_size; ! 81: u.u_offset = ltoL(siz); ! 82: u.u_base = (caddr_t)ap; ! 83: u.u_count = sizeof(acctbuf); ! 84: u.u_segflg = SEGSYS; ! 85: u.u_error = 0; ! 86: writei(ip); ! 87: if(u.u_error) ! 88: ip->i_size = siz; ! 89: prele(ip); ! 90: } ! 91: ! 92: /* ! 93: * Produce a pseudo-floating point representation ! 94: * with 3 bits base-8 exponent, 13 bits fraction. ! 95: */ ! 96: compress(t) ! 97: register long t; ! 98: { ! 99: register exp = 0, round = 0; ! 100: ! 101: while (t >= 8192) { ! 102: exp++; ! 103: round = t&04; ! 104: t >>= 3; ! 105: } ! 106: if (round) { ! 107: t++; ! 108: if (t >= 8192) { ! 109: t >>= 3; ! 110: exp++; ! 111: } ! 112: } ! 113: return((exp<<13) + t); ! 114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.