1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:account.c 1.3 */ 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #include "uucp.h" 31*7c478bd9Sstevel@tonic-gate #include "log.h" 32*7c478bd9Sstevel@tonic-gate #include <pwd.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate /* 35*7c478bd9Sstevel@tonic-gate * SYMBOL DEFINITIONS 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #define FS ' ' /* Field seperator for output records. */ 39*7c478bd9Sstevel@tonic-gate #define STD 'S' /* standard service. */ 40*7c478bd9Sstevel@tonic-gate #define LOGCHECK { if (Collecting == FALSE) return; } 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * STRUCTURE DEFINITIONS 44*7c478bd9Sstevel@tonic-gate */ 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate struct acData /* Data for construction of account record. */ 47*7c478bd9Sstevel@tonic-gate { 48*7c478bd9Sstevel@tonic-gate char uid[MODSTR]; /* user id */ 49*7c478bd9Sstevel@tonic-gate char jobID[MODSTR]; /* C. file */ 50*7c478bd9Sstevel@tonic-gate off_t jobsize; /* Bytes transferred in a job.*/ 51*7c478bd9Sstevel@tonic-gate char status; /* transaction status */ 52*7c478bd9Sstevel@tonic-gate char service; /* service grade */ 53*7c478bd9Sstevel@tonic-gate char jobgrade[MODSTR]; /* job grade */ 54*7c478bd9Sstevel@tonic-gate char time[MODSTR]; /* date and time the job execed */ 55*7c478bd9Sstevel@tonic-gate char origSystem[MODSTR]; /* originating system's name */ 56*7c478bd9Sstevel@tonic-gate char origUser[MODSTR]; /* originator's login 57*7c478bd9Sstevel@tonic-gate name */ 58*7c478bd9Sstevel@tonic-gate char rmtSystem[MODSTR]; /* system's name of 59*7c478bd9Sstevel@tonic-gate first hop */ 60*7c478bd9Sstevel@tonic-gate char rmtUser[MODSTR]; /* user's name of first 61*7c478bd9Sstevel@tonic-gate hop */ 62*7c478bd9Sstevel@tonic-gate char device[MODSTR]; /* network medium */ 63*7c478bd9Sstevel@tonic-gate char netid[MODSTR]; /* Network ID in use */ 64*7c478bd9Sstevel@tonic-gate char type[MODSTR]; /* type of transaction */ 65*7c478bd9Sstevel@tonic-gate char path[BUFSIZ]; /* path of the rest of the hops */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate }; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate /* 70*7c478bd9Sstevel@tonic-gate * LOCAL DATA 71*7c478bd9Sstevel@tonic-gate */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate static int Collecting = FALSE; /* True if we are collecting 74*7c478bd9Sstevel@tonic-gate * data. */ 75*7c478bd9Sstevel@tonic-gate static int LogFile = CLOSED; /* Log file file destriptor. */ 76*7c478bd9Sstevel@tonic-gate static char LogName[] = ACCOUNT; /* Name of our log file. */ 77*7c478bd9Sstevel@tonic-gate static char Record[LOGSIZE]; /* Place to build log records. */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate static struct acData Acct; /* Accounting data. */ 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * LOCAL FUNCTIONS 83*7c478bd9Sstevel@tonic-gate */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* Declarations of functions: */ 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate STATIC_FUNC void reportJob(); 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* 90*7c478bd9Sstevel@tonic-gate * Local Function: reportJob - Write Job accounting information to Log 91*7c478bd9Sstevel@tonic-gate * 92*7c478bd9Sstevel@tonic-gate * This function writes accounting information about the current job to the log 93*7c478bd9Sstevel@tonic-gate * file. 94*7c478bd9Sstevel@tonic-gate * 95*7c478bd9Sstevel@tonic-gate * Parameters: 96*7c478bd9Sstevel@tonic-gate * 97*7c478bd9Sstevel@tonic-gate * none. 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate STATIC_FUNC void 101*7c478bd9Sstevel@tonic-gate reportJob () 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate { 104*7c478bd9Sstevel@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"; 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate register struct acData * acptr; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate acptr = &Acct; /* Point to Acct data. */ 109*7c478bd9Sstevel@tonic-gate sprintf(Record, format, 110*7c478bd9Sstevel@tonic-gate acptr->uid, FS, 111*7c478bd9Sstevel@tonic-gate acptr->jobID, FS, 112*7c478bd9Sstevel@tonic-gate acptr->jobsize, FS, 113*7c478bd9Sstevel@tonic-gate acptr->status, FS, 114*7c478bd9Sstevel@tonic-gate acptr->service, FS, 115*7c478bd9Sstevel@tonic-gate acptr->jobgrade, FS, 116*7c478bd9Sstevel@tonic-gate acptr->origSystem, FS, 117*7c478bd9Sstevel@tonic-gate acptr->origUser, FS, 118*7c478bd9Sstevel@tonic-gate acptr->time, FS, 119*7c478bd9Sstevel@tonic-gate acptr->rmtSystem, FS, 120*7c478bd9Sstevel@tonic-gate acptr->rmtUser, FS, 121*7c478bd9Sstevel@tonic-gate acptr->device, FS, 122*7c478bd9Sstevel@tonic-gate acptr->netid, FS, 123*7c478bd9Sstevel@tonic-gate acptr->type, FS, 124*7c478bd9Sstevel@tonic-gate acptr->path, FS); 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* Terminate the record and write it out. */ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate (void) strcat(Record, EOR); 129*7c478bd9Sstevel@tonic-gate writeLog(Record,&LogFile,LogName,&Collecting); 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * EXTERNAL FUNCTIONS 135*7c478bd9Sstevel@tonic-gate */ 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * Function: acConnected - Report Connection Completion 139*7c478bd9Sstevel@tonic-gate * 140*7c478bd9Sstevel@tonic-gate * Parameters: 141*7c478bd9Sstevel@tonic-gate * 142*7c478bd9Sstevel@tonic-gate * remote - name of the remote system. 143*7c478bd9Sstevel@tonic-gate * 144*7c478bd9Sstevel@tonic-gate * device - the type of device being used for communicaitons. 145*7c478bd9Sstevel@tonic-gate */ 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate void 148*7c478bd9Sstevel@tonic-gate acConnected (remote, device) 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate char * remote; 151*7c478bd9Sstevel@tonic-gate char * device; 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate { 154*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate LOGCHECK; 157*7c478bd9Sstevel@tonic-gate copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), remote); 158*7c478bd9Sstevel@tonic-gate copyText(acptr->device, sizeof(acptr->device), device); 159*7c478bd9Sstevel@tonic-gate acptr->service = 'S'; /* default to standard service */ 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate /* Function: acDojob - Found Another Job 163*7c478bd9Sstevel@tonic-gate * 164*7c478bd9Sstevel@tonic-gate * acDojob is called when a new job has been found. 165*7c478bd9Sstevel@tonic-gate * 166*7c478bd9Sstevel@tonic-gate * Parameters: 167*7c478bd9Sstevel@tonic-gate * 168*7c478bd9Sstevel@tonic-gate * jobid - The name of the job that was found. 169*7c478bd9Sstevel@tonic-gate * 170*7c478bd9Sstevel@tonic-gate * system - Originating system's name. 171*7c478bd9Sstevel@tonic-gate * 172*7c478bd9Sstevel@tonic-gate * user - Originator's login name. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate void 176*7c478bd9Sstevel@tonic-gate acDojob(jobid, system, user) 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate char * jobid; 179*7c478bd9Sstevel@tonic-gate char * system; 180*7c478bd9Sstevel@tonic-gate char * user; 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate { 183*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate struct passwd *passent; 186*7c478bd9Sstevel@tonic-gate LOGCHECK; 187*7c478bd9Sstevel@tonic-gate if (strcmp(acptr->jobID,jobid) == 0) 188*7c478bd9Sstevel@tonic-gate return; 189*7c478bd9Sstevel@tonic-gate if ((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0)){ 190*7c478bd9Sstevel@tonic-gate reportJob(); 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate copyText(acptr->jobID, sizeof(acptr->jobID), jobid); 193*7c478bd9Sstevel@tonic-gate copyText(acptr->origSystem, sizeof(acptr->origSystem), system); 194*7c478bd9Sstevel@tonic-gate copyText(acptr->origUser, sizeof(acptr->origUser), user); 195*7c478bd9Sstevel@tonic-gate copyText(acptr->time, sizeof(acptr->time), timeStamp()); 196*7c478bd9Sstevel@tonic-gate acptr->jobgrade[0] = jobid[strlen(jobid)-5]; 197*7c478bd9Sstevel@tonic-gate acptr->jobgrade[1] = NULLCHAR;/* get job grade from jobid */ 198*7c478bd9Sstevel@tonic-gate acptr->jobsize = 0; 199*7c478bd9Sstevel@tonic-gate while ((passent = getpwent()) != NULL){ 200*7c478bd9Sstevel@tonic-gate if (strcmp(passent->pw_name,user) == 0){ 201*7c478bd9Sstevel@tonic-gate sprintf(acptr->uid,"%ld",(long) passent->pw_uid); 202*7c478bd9Sstevel@tonic-gate break; 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate /* End recording the accounting log */ 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate void 210*7c478bd9Sstevel@tonic-gate acEnd(status) 211*7c478bd9Sstevel@tonic-gate char status; 212*7c478bd9Sstevel@tonic-gate { 213*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate LOGCHECK; 216*7c478bd9Sstevel@tonic-gate if (((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0)) 217*7c478bd9Sstevel@tonic-gate || (status == PARTIAL)){ 218*7c478bd9Sstevel@tonic-gate acptr->status = status; 219*7c478bd9Sstevel@tonic-gate reportJob(); 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate } 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate /* increment job size */ 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate void 227*7c478bd9Sstevel@tonic-gate acInc() 228*7c478bd9Sstevel@tonic-gate { 229*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate LOGCHECK; 232*7c478bd9Sstevel@tonic-gate acptr->jobsize += getfilesize(); 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate /* 236*7c478bd9Sstevel@tonic-gate * Function: acInit - Initialize Accounting Package 237*7c478bd9Sstevel@tonic-gate * 238*7c478bd9Sstevel@tonic-gate * This function allows the accounting package to initialize its internal 239*7c478bd9Sstevel@tonic-gate * data structures. It should be called when uucico starts running on master 240*7c478bd9Sstevel@tonic-gate * or changes the role from slave to master, or uuxqt is invoked. 241*7c478bd9Sstevel@tonic-gate * 242*7c478bd9Sstevel@tonic-gate * Parameters: 243*7c478bd9Sstevel@tonic-gate * 244*7c478bd9Sstevel@tonic-gate * type: file transfer or remote exec. 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate void 248*7c478bd9Sstevel@tonic-gate acInit (type) 249*7c478bd9Sstevel@tonic-gate char * type; 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate { 252*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* 255*7c478bd9Sstevel@tonic-gate * Attempt to open the log file. If we can't do it, then we 256*7c478bd9Sstevel@tonic-gate * won't collect statistics. 257*7c478bd9Sstevel@tonic-gate */ 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate if (openLog(&LogFile,LogName) == SUCCESS){ 260*7c478bd9Sstevel@tonic-gate Collecting = TRUE; 261*7c478bd9Sstevel@tonic-gate acptr->service = STD; /* default to standard service */ 262*7c478bd9Sstevel@tonic-gate acptr->status = COMPLETE; /* default to completed transfer */ 263*7c478bd9Sstevel@tonic-gate copyText(acptr->jobgrade, sizeof(acptr->jobgrade), NOTAVAIL); 264*7c478bd9Sstevel@tonic-gate copyText(acptr->uid, sizeof(acptr->uid), NOTAVAIL); 265*7c478bd9Sstevel@tonic-gate copyText(acptr->origSystem, sizeof(acptr->origSystem), NOTAVAIL); 266*7c478bd9Sstevel@tonic-gate copyText(acptr->origUser, sizeof(acptr->origUser), NOTAVAIL); 267*7c478bd9Sstevel@tonic-gate copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), NOTAVAIL); 268*7c478bd9Sstevel@tonic-gate copyText(acptr->rmtUser, sizeof(acptr->rmtUser), NOTAVAIL); 269*7c478bd9Sstevel@tonic-gate copyText(acptr->device, sizeof(acptr->device), NOTAVAIL); 270*7c478bd9Sstevel@tonic-gate copyText(acptr->netid, sizeof(acptr->netid), NOTAVAIL); 271*7c478bd9Sstevel@tonic-gate copyText(acptr->path, sizeof(acptr->path), NOTAVAIL); 272*7c478bd9Sstevel@tonic-gate copyText(acptr->type, sizeof(acptr->type), type); 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate else 275*7c478bd9Sstevel@tonic-gate Collecting = FALSE; 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate /* 279*7c478bd9Sstevel@tonic-gate * It is called when uuxqt is running 280*7c478bd9Sstevel@tonic-gate * 281*7c478bd9Sstevel@tonic-gate * jobid - jobid after X. prefix 282*7c478bd9Sstevel@tonic-gate * origsys - Originating system's name. 283*7c478bd9Sstevel@tonic-gate * origuser - Originator's login name. 284*7c478bd9Sstevel@tonic-gate * connsys - local system 285*7c478bd9Sstevel@tonic-gate * connuser - login user 286*7c478bd9Sstevel@tonic-gate * cmd - command to be execed by uuxqt 287*7c478bd9Sstevel@tonic-gate */ 288*7c478bd9Sstevel@tonic-gate void 289*7c478bd9Sstevel@tonic-gate acRexe(jobid,origsys,origuser,connsys,connuser,cmd) 290*7c478bd9Sstevel@tonic-gate char * jobid; 291*7c478bd9Sstevel@tonic-gate char * origsys; 292*7c478bd9Sstevel@tonic-gate char * origuser; 293*7c478bd9Sstevel@tonic-gate char * connsys; 294*7c478bd9Sstevel@tonic-gate char * connuser; 295*7c478bd9Sstevel@tonic-gate char * cmd; 296*7c478bd9Sstevel@tonic-gate { 297*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate LOGCHECK; 300*7c478bd9Sstevel@tonic-gate copyText(acptr->jobID, sizeof(acptr->jobID), jobid); 301*7c478bd9Sstevel@tonic-gate copyText(acptr->origSystem, sizeof(acptr->origSystem), origsys); 302*7c478bd9Sstevel@tonic-gate copyText(acptr->origUser, sizeof(acptr->origUser), origuser); 303*7c478bd9Sstevel@tonic-gate copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), connsys); 304*7c478bd9Sstevel@tonic-gate copyText(acptr->rmtUser, sizeof(acptr->rmtUser), connuser); 305*7c478bd9Sstevel@tonic-gate copyText(acptr->path, sizeof(acptr->path), cmd); 306*7c478bd9Sstevel@tonic-gate copyText(acptr->time, sizeof(acptr->time), timeStamp()); 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate /* 309*7c478bd9Sstevel@tonic-gate * It is called when the command to be execed is finished 310*7c478bd9Sstevel@tonic-gate * 311*7c478bd9Sstevel@tonic-gate * cpucycle: cpu time the command is consumed 312*7c478bd9Sstevel@tonic-gate */ 313*7c478bd9Sstevel@tonic-gate void 314*7c478bd9Sstevel@tonic-gate acEndexe(cycle,status) 315*7c478bd9Sstevel@tonic-gate time_t cycle; 316*7c478bd9Sstevel@tonic-gate char status; 317*7c478bd9Sstevel@tonic-gate { 318*7c478bd9Sstevel@tonic-gate 319*7c478bd9Sstevel@tonic-gate register struct acData * acptr = &Acct; 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate LOGCHECK; 322*7c478bd9Sstevel@tonic-gate acptr->jobsize = cycle; 323*7c478bd9Sstevel@tonic-gate acptr->status = status; 324*7c478bd9Sstevel@tonic-gate reportJob(); 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate /* 327*7c478bd9Sstevel@tonic-gate * cpucycle() 328*7c478bd9Sstevel@tonic-gate * 329*7c478bd9Sstevel@tonic-gate * return cputime(utime+stime) since last time called 330*7c478bd9Sstevel@tonic-gate */ 331*7c478bd9Sstevel@tonic-gate time_t 332*7c478bd9Sstevel@tonic-gate cpucycle() 333*7c478bd9Sstevel@tonic-gate { 334*7c478bd9Sstevel@tonic-gate struct tms tbuf; 335*7c478bd9Sstevel@tonic-gate time_t rval; 336*7c478bd9Sstevel@tonic-gate static time_t utime,stime; /* guaranteed 0 first time called */ 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate times(&tbuf); 339*7c478bd9Sstevel@tonic-gate rval = ((tbuf.tms_utime-utime) + (tbuf.tms_stime-stime))*1000/HZ; 340*7c478bd9Sstevel@tonic-gate utime = tbuf.tms_utime; 341*7c478bd9Sstevel@tonic-gate stime = tbuf.tms_stime; 342*7c478bd9Sstevel@tonic-gate return(rval); 343*7c478bd9Sstevel@tonic-gate } 344