* Copyright (c) 1982, 1986, 1989 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)kern_acct.c 7.8 (Berkeley) %G%
* Values associated with enabling and disabling accounting
int acctsuspend
= 2; /* stop accounting when < 2% free space left */
int acctresume
= 4; /* resume when free space risen to > 4% */
struct timeval chk
= { 15, 0 };/* frequency to check space for accounting */
* SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
* Perform process accounting functions.
register struct vnode
*vp
;
} *uap
= (struct a
*)u
.u_ap
;
register struct nameidata
*ndp
= &u
.u_nd
;
if (u
.u_error
= suser(u
.u_cred
, &u
.u_acflag
))
untimeout(acctwatch
, (caddr_t
)&chk
);
ndp
->ni_nameiop
= LOOKUP
| FOLLOW
;
ndp
->ni_segflg
= UIO_USERSPACE
;
ndp
->ni_dirp
= uap
->fname
;
if (u
.u_error
= namei(ndp
))
if (vp
->v_type
!= VREG
) {
if (vp
->v_mount
->m_flag
& M_RDONLY
) {
* Periodically check the file system to see if accounting
* should be turned on or off.
struct timeval
*resettime
;
(void)VFS_STATFS(savacctp
->v_mount
, &sb
);
if (sb
.f_bavail
> acctresume
* sb
.f_blocks
/ 100) {
log(LOG_NOTICE
, "Accounting resumed\n");
(void)VFS_STATFS(acctp
->v_mount
, &sb
);
if (sb
.f_bavail
<= acctsuspend
* sb
.f_blocks
/ 100) {
log(LOG_NOTICE
, "Accounting suspended\n");
timeout(acctwatch
, (caddr_t
)resettime
, hzto(resettime
));
* On exit, write a record on the accounting file.
register struct rusage
*ru
;
struct timeval t
, ut
, st
;
register struct acct
*ap
= &acctbuf
;
register struct proc
*p
= u
.u_procp
;
if ((vp
= acctp
) == NULL
)
bcopy(p
->p_comm
, ap
->ac_comm
, sizeof(ap
->ac_comm
));
ap
->ac_utime
= compress(ut
.tv_sec
, ut
.tv_usec
);
ap
->ac_stime
= compress(st
.tv_sec
, st
.tv_usec
);
timevalsub(&t
, &u
.u_start
);
ap
->ac_etime
= compress(t
.tv_sec
, t
.tv_usec
);
ap
->ac_btime
= u
.u_start
.tv_sec
;
ap
->ac_uid
= u
.u_procp
->p_ruid
;
ap
->ac_gid
= u
.u_procp
->p_rgid
;
if (i
= t
.tv_sec
* hz
+ t
.tv_usec
/ tick
)
ap
->ac_mem
= (ru
->ru_ixrss
+ru
->ru_idrss
+ru
->ru_isrss
) / i
;
ap
->ac_mem
>>= CLSIZELOG2
;
ap
->ac_io
= compress(ru
->ru_inblock
+ ru
->ru_oublock
, (long)0);
if (p
->p_session
->s_ttyp
)
ap
->ac_tty
= p
->p_session
->s_ttyp
->t_dev
;
ap
->ac_flag
= u
.u_acflag
;
u
.u_error
= vn_rdwr(UIO_WRITE
, vp
, (caddr_t
)ap
, sizeof (acctbuf
),
(off_t
)0, UIO_SYSSPACE
, IO_UNIT
|IO_APPEND
, u
.u_cred
, (int *)0);
* Produce a pseudo-floating point representation
* with 3 bits base-8 exponent, 13 bits fraction.
register exp
= 0, round
= 0;
t
= t
* AHZ
; /* compiler will convert only this format to a shift */
t
+= ut
/ (1000000 / AHZ
);