xref: /illumos-gate/usr/src/cmd/bnu/account.c (revision 55fea89d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* from SVR4 bnu:account.c 1.3 */
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include	"uucp.h"
317c478bd9Sstevel@tonic-gate #include	"log.h"
327c478bd9Sstevel@tonic-gate #include <pwd.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate *		SYMBOL DEFINITIONS
367c478bd9Sstevel@tonic-gate */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	FS		' '	/* Field seperator for output records. */
397c478bd9Sstevel@tonic-gate #define	STD		'S'	/* standard service. */
407c478bd9Sstevel@tonic-gate #define LOGCHECK	{ if (Collecting == FALSE) return; }
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate *		STRUCTURE DEFINITIONS
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate struct acData			/* Data for construction of account record. */
477c478bd9Sstevel@tonic-gate 		{
487c478bd9Sstevel@tonic-gate 			char	uid[MODSTR]; /* user id */
497c478bd9Sstevel@tonic-gate 			char	jobID[MODSTR]; /* C. file */
507c478bd9Sstevel@tonic-gate 			off_t	jobsize;	/* Bytes transferred in a job.*/
517c478bd9Sstevel@tonic-gate 			char	status; /* transaction status */
527c478bd9Sstevel@tonic-gate 			char	service; /* service grade */
53*55fea89dSDan Cross 			char	jobgrade[MODSTR]; /* job grade */
547c478bd9Sstevel@tonic-gate 			char	time[MODSTR]; /* date and time the job execed */
557c478bd9Sstevel@tonic-gate 			char	origSystem[MODSTR]; /* originating system's 							   name */
56*55fea89dSDan Cross 			char	origUser[MODSTR]; /* originator's login
577c478bd9Sstevel@tonic-gate 							   name */
58*55fea89dSDan Cross 			char	rmtSystem[MODSTR]; /* system's name of
597c478bd9Sstevel@tonic-gate 							   first hop */
607c478bd9Sstevel@tonic-gate 			char	rmtUser[MODSTR]; /* user's name of first
617c478bd9Sstevel@tonic-gate 							   hop */
627c478bd9Sstevel@tonic-gate 			char	device[MODSTR]; /* network medium */
637c478bd9Sstevel@tonic-gate 			char	netid[MODSTR]; /* Network ID in use */
647c478bd9Sstevel@tonic-gate 			char	type[MODSTR]; /* type of transaction */
657c478bd9Sstevel@tonic-gate 			char	path[BUFSIZ]; /* path of the rest of the hops */
66*55fea89dSDan Cross 
677c478bd9Sstevel@tonic-gate 		};
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate *		LOCAL DATA
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate static int		Collecting = FALSE; /* True if we are collecting
747c478bd9Sstevel@tonic-gate 					     *   data. */
757c478bd9Sstevel@tonic-gate static int		LogFile = CLOSED; /* Log file file destriptor. */
767c478bd9Sstevel@tonic-gate static char		LogName[] = ACCOUNT; /* Name of our log file. */
777c478bd9Sstevel@tonic-gate static char		Record[LOGSIZE]; /* Place to build log records. */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static struct acData	Acct;	/* Accounting data. */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate *		LOCAL FUNCTIONS
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /* Declarations of functions: */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate STATIC_FUNC void	reportJob();
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate * Local Function:	reportJob - Write Job accounting information to Log
917c478bd9Sstevel@tonic-gate *
927c478bd9Sstevel@tonic-gate * This function writes accounting information about the current job to the log
937c478bd9Sstevel@tonic-gate * file.
947c478bd9Sstevel@tonic-gate *
957c478bd9Sstevel@tonic-gate * Parameters:
967c478bd9Sstevel@tonic-gate *
977c478bd9Sstevel@tonic-gate *	none.
987c478bd9Sstevel@tonic-gate */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate STATIC_FUNC void
reportJob()1017c478bd9Sstevel@tonic-gate reportJob ()
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate 	static char	format[] = "%s%c%s%c%ld%c%c%c%c%c%s%c%s%c%s%c(%s)%c%s%c%s%c%s%c%s%c%s%c%s%c";
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	register struct acData *	acptr;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	acptr = &Acct;			/* Point to Acct data. */
1097c478bd9Sstevel@tonic-gate 	sprintf(Record, format,
1107c478bd9Sstevel@tonic-gate 		acptr->uid, FS,
1117c478bd9Sstevel@tonic-gate 		acptr->jobID, FS,
1127c478bd9Sstevel@tonic-gate 		acptr->jobsize, FS,
1137c478bd9Sstevel@tonic-gate 		acptr->status, FS,
1147c478bd9Sstevel@tonic-gate 		acptr->service, FS,
1157c478bd9Sstevel@tonic-gate 		acptr->jobgrade, FS,
1167c478bd9Sstevel@tonic-gate 		acptr->origSystem, FS,
1177c478bd9Sstevel@tonic-gate 		acptr->origUser, FS,
1187c478bd9Sstevel@tonic-gate 		acptr->time, FS,
1197c478bd9Sstevel@tonic-gate 		acptr->rmtSystem, FS,
1207c478bd9Sstevel@tonic-gate   		acptr->rmtUser, FS,
1217c478bd9Sstevel@tonic-gate 		acptr->device, FS,
1227c478bd9Sstevel@tonic-gate 		acptr->netid, FS,
1237c478bd9Sstevel@tonic-gate 		acptr->type, FS,
1247c478bd9Sstevel@tonic-gate 		acptr->path, FS);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	/* Terminate the record and write it out. */
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	(void) strcat(Record, EOR);
1297c478bd9Sstevel@tonic-gate 	writeLog(Record,&LogFile,LogName,&Collecting);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate *		EXTERNAL FUNCTIONS
1357c478bd9Sstevel@tonic-gate */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate * Function:	acConnected - Report Connection Completion
1397c478bd9Sstevel@tonic-gate *
1407c478bd9Sstevel@tonic-gate * Parameters:
1417c478bd9Sstevel@tonic-gate *
1427c478bd9Sstevel@tonic-gate *	remote -	name of the remote system.
1437c478bd9Sstevel@tonic-gate *
1447c478bd9Sstevel@tonic-gate *	device -	the type of device being used for communicaitons.
1457c478bd9Sstevel@tonic-gate */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate void
acConnected(remote,device)1487c478bd9Sstevel@tonic-gate acConnected (remote, device)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate char *	remote;
1517c478bd9Sstevel@tonic-gate char *	device;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	LOGCHECK;
1577c478bd9Sstevel@tonic-gate 	copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), remote);
1587c478bd9Sstevel@tonic-gate 	copyText(acptr->device, sizeof(acptr->device), device);
1597c478bd9Sstevel@tonic-gate 	acptr->service = 'S'; /* default to standard service */
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /* Function:	acDojob - Found Another Job
1637c478bd9Sstevel@tonic-gate *
164*55fea89dSDan Cross * acDojob  is called when a new job has been found.
1657c478bd9Sstevel@tonic-gate *
1667c478bd9Sstevel@tonic-gate * Parameters:
1677c478bd9Sstevel@tonic-gate *
1687c478bd9Sstevel@tonic-gate *	jobid -		The name of the job that was found.
1697c478bd9Sstevel@tonic-gate *
1707c478bd9Sstevel@tonic-gate *	system -	Originating system's name.
1717c478bd9Sstevel@tonic-gate *
1727c478bd9Sstevel@tonic-gate *	user -		Originator's login name.
1737c478bd9Sstevel@tonic-gate */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate void
acDojob(jobid,system,user)1767c478bd9Sstevel@tonic-gate acDojob(jobid, system, user)
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate char *	jobid;
1797c478bd9Sstevel@tonic-gate char *	system;
1807c478bd9Sstevel@tonic-gate char *	user;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate struct passwd *passent;
1867c478bd9Sstevel@tonic-gate 	LOGCHECK;
187*55fea89dSDan Cross 	if (strcmp(acptr->jobID,jobid) == 0)
1887c478bd9Sstevel@tonic-gate 		return;
1897c478bd9Sstevel@tonic-gate 	if ((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0)){
1907c478bd9Sstevel@tonic-gate 		reportJob();
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate 	copyText(acptr->jobID, sizeof(acptr->jobID), jobid);
1937c478bd9Sstevel@tonic-gate 	copyText(acptr->origSystem, sizeof(acptr->origSystem), system);
1947c478bd9Sstevel@tonic-gate 	copyText(acptr->origUser, sizeof(acptr->origUser), user);
1957c478bd9Sstevel@tonic-gate 	copyText(acptr->time, sizeof(acptr->time), timeStamp());
196*55fea89dSDan Cross 	acptr->jobgrade[0] = jobid[strlen(jobid)-5];
1977c478bd9Sstevel@tonic-gate 	acptr->jobgrade[1] = NULLCHAR;/* get job grade from jobid */
1987c478bd9Sstevel@tonic-gate 	acptr->jobsize = 0;
1997c478bd9Sstevel@tonic-gate 	while ((passent = getpwent()) != NULL){
2007c478bd9Sstevel@tonic-gate 	  if (strcmp(passent->pw_name,user) == 0){
2017c478bd9Sstevel@tonic-gate 		sprintf(acptr->uid,"%ld",(long) passent->pw_uid);
2027c478bd9Sstevel@tonic-gate 		break;
2037c478bd9Sstevel@tonic-gate 	  }
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /* End recording the accounting log */
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate void
acEnd(status)2107c478bd9Sstevel@tonic-gate acEnd(status)
2117c478bd9Sstevel@tonic-gate char status;
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	LOGCHECK;
2167c478bd9Sstevel@tonic-gate 	if (((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0))
2177c478bd9Sstevel@tonic-gate 			|| (status == PARTIAL)){
2187c478bd9Sstevel@tonic-gate 		acptr->status = status;
2197c478bd9Sstevel@tonic-gate 		reportJob();
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /* increment job size */
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate void
acInc()2277c478bd9Sstevel@tonic-gate acInc()
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	LOGCHECK;
2327c478bd9Sstevel@tonic-gate 	acptr->jobsize += getfilesize();
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate * Function:	acInit - Initialize Accounting Package
2377c478bd9Sstevel@tonic-gate *
2387c478bd9Sstevel@tonic-gate * This function allows the accounting package to initialize its internal
239*55fea89dSDan Cross * data structures.  It should be called when uucico starts running on master
2407c478bd9Sstevel@tonic-gate * or changes the role from slave to master, or uuxqt is invoked.
2417c478bd9Sstevel@tonic-gate *
2427c478bd9Sstevel@tonic-gate * Parameters:
2437c478bd9Sstevel@tonic-gate *
2447c478bd9Sstevel@tonic-gate *	type: file transfer or remote exec.
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate void
acInit(type)2487c478bd9Sstevel@tonic-gate acInit (type)
2497c478bd9Sstevel@tonic-gate char * type;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	/*
2557c478bd9Sstevel@tonic-gate 	* Attempt to open the log file.  If we can't do it, then we
2567c478bd9Sstevel@tonic-gate 	* won't collect statistics.
2577c478bd9Sstevel@tonic-gate 	*/
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (openLog(&LogFile,LogName) == SUCCESS){
2607c478bd9Sstevel@tonic-gate 		Collecting = TRUE;
2617c478bd9Sstevel@tonic-gate 		acptr->service = STD; /* default to standard service */
2627c478bd9Sstevel@tonic-gate 		acptr->status = COMPLETE; /* default to completed transfer */
2637c478bd9Sstevel@tonic-gate 		copyText(acptr->jobgrade, sizeof(acptr->jobgrade), NOTAVAIL);
2647c478bd9Sstevel@tonic-gate 		copyText(acptr->uid, sizeof(acptr->uid), NOTAVAIL);
2657c478bd9Sstevel@tonic-gate 		copyText(acptr->origSystem, sizeof(acptr->origSystem), NOTAVAIL);
2667c478bd9Sstevel@tonic-gate 		copyText(acptr->origUser, sizeof(acptr->origUser), NOTAVAIL);
2677c478bd9Sstevel@tonic-gate 		copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), NOTAVAIL);
2687c478bd9Sstevel@tonic-gate 		copyText(acptr->rmtUser, sizeof(acptr->rmtUser), NOTAVAIL);
2697c478bd9Sstevel@tonic-gate 		copyText(acptr->device, sizeof(acptr->device), NOTAVAIL);
2707c478bd9Sstevel@tonic-gate 		copyText(acptr->netid, sizeof(acptr->netid), NOTAVAIL);
2717c478bd9Sstevel@tonic-gate 		copyText(acptr->path, sizeof(acptr->path), NOTAVAIL);
2727c478bd9Sstevel@tonic-gate 		copyText(acptr->type, sizeof(acptr->type), type);
2737c478bd9Sstevel@tonic-gate 	}
2747c478bd9Sstevel@tonic-gate 	else
2757c478bd9Sstevel@tonic-gate 		Collecting = FALSE;
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate 
278*55fea89dSDan Cross /*
2797c478bd9Sstevel@tonic-gate * It is called when uuxqt is running
2807c478bd9Sstevel@tonic-gate *
2817c478bd9Sstevel@tonic-gate *	jobid - jobid after X. prefix
2827c478bd9Sstevel@tonic-gate *	origsys - Originating system's name.
2837c478bd9Sstevel@tonic-gate *	origuser - Originator's login name.
284*55fea89dSDan Cross *	connsys - local system
2857c478bd9Sstevel@tonic-gate *	connuser - login user
2867c478bd9Sstevel@tonic-gate *	cmd - command to be execed by uuxqt
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate void
acRexe(jobid,origsys,origuser,connsys,connuser,cmd)2897c478bd9Sstevel@tonic-gate acRexe(jobid,origsys,origuser,connsys,connuser,cmd)
2907c478bd9Sstevel@tonic-gate char * jobid;
2917c478bd9Sstevel@tonic-gate char * origsys;
2927c478bd9Sstevel@tonic-gate char * origuser;
2937c478bd9Sstevel@tonic-gate char * connsys;
2947c478bd9Sstevel@tonic-gate char * connuser;
2957c478bd9Sstevel@tonic-gate char * cmd;
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	LOGCHECK;
3007c478bd9Sstevel@tonic-gate 	copyText(acptr->jobID, sizeof(acptr->jobID), jobid);
3017c478bd9Sstevel@tonic-gate 	copyText(acptr->origSystem, sizeof(acptr->origSystem), origsys);
3027c478bd9Sstevel@tonic-gate 	copyText(acptr->origUser, sizeof(acptr->origUser), origuser);
3037c478bd9Sstevel@tonic-gate 	copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), connsys);
3047c478bd9Sstevel@tonic-gate 	copyText(acptr->rmtUser, sizeof(acptr->rmtUser), connuser);
3057c478bd9Sstevel@tonic-gate 	copyText(acptr->path, sizeof(acptr->path), cmd);
3067c478bd9Sstevel@tonic-gate 	copyText(acptr->time, sizeof(acptr->time), timeStamp());
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate * It is called when the command to be execed is finished
3107c478bd9Sstevel@tonic-gate *
3117c478bd9Sstevel@tonic-gate *	cpucycle: cpu time the command is consumed
3127c478bd9Sstevel@tonic-gate */
3137c478bd9Sstevel@tonic-gate void
acEndexe(cycle,status)3147c478bd9Sstevel@tonic-gate acEndexe(cycle,status)
3157c478bd9Sstevel@tonic-gate time_t	cycle;
3167c478bd9Sstevel@tonic-gate char status;
3177c478bd9Sstevel@tonic-gate {
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	register struct acData *	acptr = &Acct;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	LOGCHECK;
3227c478bd9Sstevel@tonic-gate 	acptr->jobsize = cycle;
3237c478bd9Sstevel@tonic-gate  	acptr->status = status;
3247c478bd9Sstevel@tonic-gate  	reportJob();
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate /*
3277c478bd9Sstevel@tonic-gate  *	cpucycle()
3287c478bd9Sstevel@tonic-gate  *
3297c478bd9Sstevel@tonic-gate  *	return cputime(utime+stime) since last time called
3307c478bd9Sstevel@tonic-gate  */
3317c478bd9Sstevel@tonic-gate time_t
cpucycle()3327c478bd9Sstevel@tonic-gate cpucycle()
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate 	struct tms	tbuf;
3357c478bd9Sstevel@tonic-gate  	time_t	rval;
3367c478bd9Sstevel@tonic-gate  	static time_t	utime,stime;	/* guaranteed 0 first time called */
337*55fea89dSDan Cross 
3387c478bd9Sstevel@tonic-gate  	times(&tbuf);
3397c478bd9Sstevel@tonic-gate  	rval = ((tbuf.tms_utime-utime) + (tbuf.tms_stime-stime))*1000/HZ;
3407c478bd9Sstevel@tonic-gate  	utime = tbuf.tms_utime;
3417c478bd9Sstevel@tonic-gate  	stime = tbuf.tms_stime;
3427c478bd9Sstevel@tonic-gate  	return(rval);
3437c478bd9Sstevel@tonic-gate }
344