1: /*
   2:  *	SCCS id	@(#)acct.c	2.1 (Berkeley)	8/5/83
   3:  */
   4: 
   5: #include "param.h"
   6: #ifdef  ACCT
   7: #include <sys/systm.h>
   8: #include <sys/acct.h>
   9: #include <sys/dir.h>
  10: #include <sys/user.h>
  11: #include <sys/inode.h>
  12: #include <sys/proc.h>
  13: #include <sys/seg.h>
  14: 
  15: 
  16: /*
  17:  * Perform process accounting functions.
  18:  */
  19: 
  20: sysacct()
  21: {
  22:     register struct inode *ip;
  23:     register struct a {
  24:         char    *fname;
  25:     } *uap;
  26: 
  27:     uap = (struct a *)u.u_ap;
  28:     if (suser()) {
  29:         if (uap->fname==NULL) {
  30:             if (acctp) {
  31:                 plock(acctp);
  32:                 iput(acctp);
  33:                 acctp = NULL;
  34:             }
  35:             return;
  36:         }
  37:         if (acctp) {
  38:             u.u_error = EBUSY;
  39:             return;
  40:         }
  41: #ifndef UCB_SYMLINKS
  42:         ip = namei(uchar, LOOKUP);
  43: #else
  44:         ip = namei(uchar, LOOKUP, 1);
  45: #endif
  46:         if(ip == NULL)
  47:             return;
  48:         if((ip->i_mode & IFMT) != IFREG) {
  49:             u.u_error = EACCES;
  50:             iput(ip);
  51:             return;
  52:         }
  53:         acctp = ip;
  54:         prele(ip);
  55:     }
  56: }
  57: 
  58: /*
  59:  * On exit, write a record on the accounting file.
  60:  */
  61: acct()
  62: {
  63:     register i;
  64:     register struct inode *ip;
  65:     off_t siz;
  66: 
  67:     if ((ip=acctp)==NULL)
  68:         return;
  69:     plock(ip);
  70:     for (i=0; i<sizeof(acctbuf.ac_comm); i++)
  71:         acctbuf.ac_comm[i] = u.u_comm[i];
  72:     acctbuf.ac_utime = compress(u.u_utime);
  73:     acctbuf.ac_stime = compress(u.u_stime);
  74:     acctbuf.ac_etime = compress(time - u.u_start);
  75:     acctbuf.ac_btime = u.u_start;
  76:     acctbuf.ac_uid = u.u_ruid;
  77:     acctbuf.ac_gid = u.u_rgid;
  78:     acctbuf.ac_mem = 0;
  79:     acctbuf.ac_io = 0;
  80:     acctbuf.ac_tty = u.u_ttyd;
  81:     acctbuf.ac_flag = u.u_acflag;
  82: #ifdef  UCB_SUBM
  83:     if(u.u_procp->p_flag & SSUBM)
  84:         acctbuf.ac_flag |= ASUBM;
  85: #endif
  86: #ifdef  UCB_LOGIN
  87:     for(i=0; i<sizeof(acctbuf.ac_crn); i++)
  88:         acctbuf.ac_crn[i] = u.u_crn[i];
  89:     acctbuf.ac_magic = AMAGIC;
  90: #endif
  91:     siz = ip->i_size;
  92:     u.u_offset = siz;
  93:     u.u_base = (caddr_t)&acctbuf;
  94:     u.u_count = sizeof(acctbuf);
  95:     u.u_segflg = 1;
  96:     u.u_error = 0;
  97:     writei(ip);
  98:     if(u.u_error)
  99:         ip->i_size = siz;
 100:     prele(ip);
 101: }
 102: 
 103: /*
 104:  * Produce a pseudo-floating point representation
 105:  * with 3 bits base-8 exponent, 13 bits fraction.
 106:  */
 107: compress(t)
 108: register time_t t;
 109: {
 110:     register exp = 0, round = 0;
 111: 
 112:     while (t >= 8192) {
 113:         exp++;
 114:         round = t&04;
 115:         t >>= 3;
 116:     }
 117:     if (round) {
 118:         t++;
 119:         if (t >= 8192) {
 120:             t >>= 3;
 121:             exp++;
 122:         }
 123:     }
 124:     return((exp<<13) + t);
 125: }
 126: #endif	ACCT

Defined functions

acct defined in line 61; used 1 times
compress defined in line 107; used 3 times
sysacct defined in line 20; never used

Defined struct's

a defined in line 23; used 2 times
  • in line 27(2)
Last modified: 1983-08-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 848
Valid CSS Valid XHTML 1.0 Strict