4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:account.c 1.3 */
38 #define FS ' ' /* Field seperator for output records. */
39 #define STD 'S' /* standard service. */
40 #define LOGCHECK { if (Collecting == FALSE) return; }
43 * STRUCTURE DEFINITIONS
46 struct acData
/* Data for construction of account record. */
48 char uid
[MODSTR
]; /* user id */
49 char jobID
[MODSTR
]; /* C. file */
50 off_t jobsize
; /* Bytes transferred in a job.*/
51 char status
; /* transaction status */
52 char service
; /* service grade */
53 char jobgrade
[MODSTR
]; /* job grade */
54 char time
[MODSTR
]; /* date and time the job execed */
55 char origSystem
[MODSTR
]; /* originating system's name */
56 char origUser
[MODSTR
]; /* originator's login
58 char rmtSystem
[MODSTR
]; /* system's name of
60 char rmtUser
[MODSTR
]; /* user's name of first
62 char device
[MODSTR
]; /* network medium */
63 char netid
[MODSTR
]; /* Network ID in use */
64 char type
[MODSTR
]; /* type of transaction */
65 char path
[BUFSIZ
]; /* path of the rest of the hops */
73 static int Collecting
= FALSE
; /* True if we are collecting
75 static int LogFile
= CLOSED
; /* Log file file destriptor. */
76 static char LogName
[] = ACCOUNT
; /* Name of our log file. */
77 static char Record
[LOGSIZE
]; /* Place to build log records. */
79 static struct acData Acct
; /* Accounting data. */
85 /* Declarations of functions: */
87 STATIC_FUNC
void reportJob();
90 * Local Function: reportJob - Write Job accounting information to Log
92 * This function writes accounting information about the current job to the log
104 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";
106 register struct acData
* acptr
;
108 acptr
= &Acct
; /* Point to Acct data. */
109 sprintf(Record
, format
,
116 acptr
->origSystem
, FS
,
119 acptr
->rmtSystem
, FS
,
126 /* Terminate the record and write it out. */
128 (void) strcat(Record
, EOR
);
129 writeLog(Record
,&LogFile
,LogName
,&Collecting
);
138 * Function: acConnected - Report Connection Completion
142 * remote - name of the remote system.
144 * device - the type of device being used for communicaitons.
148 acConnected (remote
, device
)
154 register struct acData
* acptr
= &Acct
;
157 copyText(acptr
->rmtSystem
, sizeof(acptr
->rmtSystem
), remote
);
158 copyText(acptr
->device
, sizeof(acptr
->device
), device
);
159 acptr
->service
= 'S'; /* default to standard service */
162 /* Function: acDojob - Found Another Job
164 * acDojob is called when a new job has been found.
168 * jobid - The name of the job that was found.
170 * system - Originating system's name.
172 * user - Originator's login name.
176 acDojob(jobid
, system
, user
)
183 register struct acData
* acptr
= &Acct
;
185 struct passwd
*passent
;
187 if (strcmp(acptr
->jobID
,jobid
) == 0)
189 if ((*acptr
->jobID
!= NULLCHAR
) && (acptr
->jobsize
!= 0)){
192 copyText(acptr
->jobID
, sizeof(acptr
->jobID
), jobid
);
193 copyText(acptr
->origSystem
, sizeof(acptr
->origSystem
), system
);
194 copyText(acptr
->origUser
, sizeof(acptr
->origUser
), user
);
195 copyText(acptr
->time
, sizeof(acptr
->time
), timeStamp());
196 acptr
->jobgrade
[0] = jobid
[strlen(jobid
)-5];
197 acptr
->jobgrade
[1] = NULLCHAR
;/* get job grade from jobid */
199 while ((passent
= getpwent()) != NULL
){
200 if (strcmp(passent
->pw_name
,user
) == 0){
201 sprintf(acptr
->uid
,"%ld",(long) passent
->pw_uid
);
207 /* End recording the accounting log */
213 register struct acData
* acptr
= &Acct
;
216 if (((*acptr
->jobID
!= NULLCHAR
) && (acptr
->jobsize
!= 0))
217 || (status
== PARTIAL
)){
218 acptr
->status
= status
;
224 /* increment job size */
229 register struct acData
* acptr
= &Acct
;
232 acptr
->jobsize
+= getfilesize();
236 * Function: acInit - Initialize Accounting Package
238 * This function allows the accounting package to initialize its internal
239 * data structures. It should be called when uucico starts running on master
240 * or changes the role from slave to master, or uuxqt is invoked.
244 * type: file transfer or remote exec.
252 register struct acData
* acptr
= &Acct
;
255 * Attempt to open the log file. If we can't do it, then we
256 * won't collect statistics.
259 if (openLog(&LogFile
,LogName
) == SUCCESS
){
261 acptr
->service
= STD
; /* default to standard service */
262 acptr
->status
= COMPLETE
; /* default to completed transfer */
263 copyText(acptr
->jobgrade
, sizeof(acptr
->jobgrade
), NOTAVAIL
);
264 copyText(acptr
->uid
, sizeof(acptr
->uid
), NOTAVAIL
);
265 copyText(acptr
->origSystem
, sizeof(acptr
->origSystem
), NOTAVAIL
);
266 copyText(acptr
->origUser
, sizeof(acptr
->origUser
), NOTAVAIL
);
267 copyText(acptr
->rmtSystem
, sizeof(acptr
->rmtSystem
), NOTAVAIL
);
268 copyText(acptr
->rmtUser
, sizeof(acptr
->rmtUser
), NOTAVAIL
);
269 copyText(acptr
->device
, sizeof(acptr
->device
), NOTAVAIL
);
270 copyText(acptr
->netid
, sizeof(acptr
->netid
), NOTAVAIL
);
271 copyText(acptr
->path
, sizeof(acptr
->path
), NOTAVAIL
);
272 copyText(acptr
->type
, sizeof(acptr
->type
), type
);
279 * It is called when uuxqt is running
281 * jobid - jobid after X. prefix
282 * origsys - Originating system's name.
283 * origuser - Originator's login name.
284 * connsys - local system
285 * connuser - login user
286 * cmd - command to be execed by uuxqt
289 acRexe(jobid
,origsys
,origuser
,connsys
,connuser
,cmd
)
297 register struct acData
* acptr
= &Acct
;
300 copyText(acptr
->jobID
, sizeof(acptr
->jobID
), jobid
);
301 copyText(acptr
->origSystem
, sizeof(acptr
->origSystem
), origsys
);
302 copyText(acptr
->origUser
, sizeof(acptr
->origUser
), origuser
);
303 copyText(acptr
->rmtSystem
, sizeof(acptr
->rmtSystem
), connsys
);
304 copyText(acptr
->rmtUser
, sizeof(acptr
->rmtUser
), connuser
);
305 copyText(acptr
->path
, sizeof(acptr
->path
), cmd
);
306 copyText(acptr
->time
, sizeof(acptr
->time
), timeStamp());
309 * It is called when the command to be execed is finished
311 * cpucycle: cpu time the command is consumed
314 acEndexe(cycle
,status
)
319 register struct acData
* acptr
= &Acct
;
322 acptr
->jobsize
= cycle
;
323 acptr
->status
= status
;
329 * return cputime(utime+stime) since last time called
336 static time_t utime
,stime
; /* guaranteed 0 first time called */
339 rval
= ((tbuf
.tms_utime
-utime
) + (tbuf
.tms_stime
-stime
))*1000/HZ
;
340 utime
= tbuf
.tms_utime
;
341 stime
= tbuf
.tms_stime
;