USG_PG3/usr/source/opsys/acct.c

Compare this file to the similar file:
Show the results in this format:

#include	"../head/param.h"
#include	"../head/systm.h"
#include	"../head/user.h"
#include	"../head/userx.h"
#include	"../head/inode.h"

/*
 * Perform process accounting functions.
 */

sysacct()
{
	extern uchar();

	if (suser()) {
		if (u.u_arg[0]==0) {
			if (acctp) {
				plock(acctp);
				iput(acctp);
				acctp = NULL;
			}
			return;
		}
		if (acctp) {
			u.u_error = EBUSY;
			return;
		}
		u.u_dirp = u.u_arg[0];
		if ((acctp = namei(&uchar, 0))==NULL)
			return;
		prele(acctp);
	}
}

/*
 * On exit, write a record on the accounting file.
 */
acct()
{
	register struct inode *ip;
	register i;

	if ((ip=acctp)==NULL)
		return;
	plock(ip);
	for (i=0; i<DIRSIZ; i++)
		acctbuf.ac_comm[i] = u.u_comm[i];
	acctbuf.ac_flag = u.u_acflag;
	acctbuf.ac_uid = u.u_ruid;
	acctbuf.ac_date = u.u_start;
	acctbuf.ac_etime = time - u.u_start;
	acctbuf.ac_utime = u.u_utime;
	acctbuf.ac_stime = u.u_stime;
	u.u_offset[0] = ip->i_size0&0377;
	u.u_offset[1] = ip->i_size1;
	u.u_base = &acctbuf;
	u.u_count = sizeof(acctbuf);
	u.u_segflg = 1;
	u.u_error = 0;
	writei(ip);
	prele(ip);
}