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 /*
237c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * This module is intended to collect performance statistics about the
327c478bd9Sstevel@tonic-gate * operation of uucico. All instances of uucico will write their log
337c478bd9Sstevel@tonic-gate * entries to the files who's path is defined by PERFLOG. Statistics
347c478bd9Sstevel@tonic-gate * will only be collected if PERFLOG exists when uucico starts, it will
357c478bd9Sstevel@tonic-gate * not be created automatically. This gives the SA an easy way to turn
367c478bd9Sstevel@tonic-gate * statistics collection on or off at run time. Three types
377c478bd9Sstevel@tonic-gate * of records will be written to the file, and each record will be
387c478bd9Sstevel@tonic-gate * identified by a mnemonic type at the begining of the record. The record
397c478bd9Sstevel@tonic-gate * types are as follows:
407c478bd9Sstevel@tonic-gate *
417c478bd9Sstevel@tonic-gate * conn - Contains statistics about the establishment of
427c478bd9Sstevel@tonic-gate * a connection.
437c478bd9Sstevel@tonic-gate *
447c478bd9Sstevel@tonic-gate * xfer - Contains statistics about a file transfer.
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate * The intention is to use grep to select the conn and xfer records and put
477c478bd9Sstevel@tonic-gate * them in two Unity data bases. No attempt will be made to process the
487c478bd9Sstevel@tonic-gate * error records with Unity.
497c478bd9Sstevel@tonic-gate *
507c478bd9Sstevel@tonic-gate * Both the conn and the xfer records will contain a time stamp field.
517c478bd9Sstevel@tonic-gate * This field will be written in case there is a desire to do time of
527c478bd9Sstevel@tonic-gate * day traffic studies. The time that will be written will be GMT
537c478bd9Sstevel@tonic-gate * to avoid the vagaries of time zone setting for uucico. The time
547c478bd9Sstevel@tonic-gate * stamp will contain 12 digits of the form YYMMDDhhmmss. This allows
557c478bd9Sstevel@tonic-gate * proper sorting by time, and the fixed length field type of Unity
567c478bd9Sstevel@tonic-gate * can be used to pick it apart if necessary. The time stamp is the
577c478bd9Sstevel@tonic-gate * time that the record is written.
587c478bd9Sstevel@tonic-gate *
597c478bd9Sstevel@tonic-gate * Statistics will be collected on the wall clock (real) time to perform
607c478bd9Sstevel@tonic-gate * an action and CPU consumption to perform an action. These times will
617c478bd9Sstevel@tonic-gate * be written in seconds and fractions of a second to two decimal places.
627c478bd9Sstevel@tonic-gate *
637c478bd9Sstevel@tonic-gate * The conn and xfer records will be written so that they can be processed
647c478bd9Sstevel@tonic-gate * with the following Unity schema (D files). For those not familiar with
657c478bd9Sstevel@tonic-gate * Unity, the columns are:
667c478bd9Sstevel@tonic-gate *
677c478bd9Sstevel@tonic-gate * column 1 - field name
687c478bd9Sstevel@tonic-gate * column 2 - field type (t=variable width) and field separator.
697c478bd9Sstevel@tonic-gate * column 3 - number of columns to use when printing the field
707c478bd9Sstevel@tonic-gate * with uprint.
717c478bd9Sstevel@tonic-gate * column 4 - a user friendly field name.
727c478bd9Sstevel@tonic-gate *
737c478bd9Sstevel@tonic-gate * Conn:
747c478bd9Sstevel@tonic-gate *
757c478bd9Sstevel@tonic-gate * type t| 4 record type (always conn)
767c478bd9Sstevel@tonic-gate * ts t| 12 time stamp
777c478bd9Sstevel@tonic-gate * procid t| 5 uucico's process id
787c478bd9Sstevel@tonic-gate * myname t| 6 name of the machine where the record is written
797c478bd9Sstevel@tonic-gate * role t| 1 M = master, S = slave
807c478bd9Sstevel@tonic-gate * remote t| 6 name of remote system
817c478bd9Sstevel@tonic-gate * device t| 6 name of device used for connection
827c478bd9Sstevel@tonic-gate * protocol t| 1 the protocal that is used for communication
837c478bd9Sstevel@tonic-gate * netid t| 6 physical network ID
847c478bd9Sstevel@tonic-gate * real t| 6 real time to connect
857c478bd9Sstevel@tonic-gate * user t| 6 user time to connect
867c478bd9Sstevel@tonic-gate * sys t\n 6 system (kernal) time to connect
877c478bd9Sstevel@tonic-gate *
887c478bd9Sstevel@tonic-gate * The timer for connection processing starts immediately after the
897c478bd9Sstevel@tonic-gate * command line processing is complete, and it is stopped after the
907c478bd9Sstevel@tonic-gate * protocol has been selected.
917c478bd9Sstevel@tonic-gate *
927c478bd9Sstevel@tonic-gate * Xfer:
937c478bd9Sstevel@tonic-gate *
947c478bd9Sstevel@tonic-gate * type t| 4 record type (always xfer)
957c478bd9Sstevel@tonic-gate * jobgrade t| 1 job grade ID
967c478bd9Sstevel@tonic-gate * ts t| 12 time stamp
977c478bd9Sstevel@tonic-gate * procid t| 5 uucico's process id
987c478bd9Sstevel@tonic-gate * myname t| 6 name of the machine where the record is written
997c478bd9Sstevel@tonic-gate * role t| 1 M = master, S = slave
1007c478bd9Sstevel@tonic-gate * remote t| 6 name of remote system
1017c478bd9Sstevel@tonic-gate * device t| 6 name of device used for connection
1027c478bd9Sstevel@tonic-gate * protocol t| 1 the protocal that is used for communication
1037c478bd9Sstevel@tonic-gate * netid t| 6 physical network ID
1047c478bd9Sstevel@tonic-gate * job t| 7 name of the job. (Master only).
1057c478bd9Sstevel@tonic-gate * inqueue t| 6 time in seconds that file was in queue (Master
1067c478bd9Sstevel@tonic-gate * only).
1077c478bd9Sstevel@tonic-gate * tat t| 6 turn around time in sec. (Master only).
1087c478bd9Sstevel@tonic-gate * bytes t| 6 size of the file that was transferred
1097c478bd9Sstevel@tonic-gate * flags t| 3 m = mail to requester on completion,
1107c478bd9Sstevel@tonic-gate * n = notify remote user, s = write status
1117c478bd9Sstevel@tonic-gate * file. (Master only).
1127c478bd9Sstevel@tonic-gate * streal t| 6 real time to start up transfer (master only).
1137c478bd9Sstevel@tonic-gate * stuser t| 6
1147c478bd9Sstevel@tonic-gate * stsys t| 6
1157c478bd9Sstevel@tonic-gate * xfrreal t| 6 real time to transfer file
1167c478bd9Sstevel@tonic-gate * xfruser t| 6
1177c478bd9Sstevel@tonic-gate * xfrsys t| 6
1187c478bd9Sstevel@tonic-gate * trmreal t| 6 real time to terminate the transfer
1197c478bd9Sstevel@tonic-gate * trmuser t| 6
1207c478bd9Sstevel@tonic-gate * trmsys t| 6
1217c478bd9Sstevel@tonic-gate * text t| 12 "PARTIAL FILE" if the data is being transmitted
122*2a8bcb4eSToomas Soome * before breaking the transmission; blank if the
1237c478bd9Sstevel@tonic-gate * partial file after the breakpoint or the whole
1247c478bd9Sstevel@tonic-gate * file is being transmitted completely.
1257c478bd9Sstevel@tonic-gate *
1267c478bd9Sstevel@tonic-gate * Start up time includes the time for the master to search the queues
1277c478bd9Sstevel@tonic-gate * for the next file, for the master and slave to exchange work vectors,
1287c478bd9Sstevel@tonic-gate * and time to open files. It is only recorded on the master.
1297c478bd9Sstevel@tonic-gate * Xfer times is the time to transfer the data, close the file, and
1307c478bd9Sstevel@tonic-gate * exchange confirmation messages. Termination time is the time to send
1317c478bd9Sstevel@tonic-gate * mail notifications and write status files. Turn around time is the
1327c478bd9Sstevel@tonic-gate * difference between the time that the file was queued and the time that
1337c478bd9Sstevel@tonic-gate * the final notification was sent.
1347c478bd9Sstevel@tonic-gate */
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate #include "uucp.h"
1377c478bd9Sstevel@tonic-gate #include "log.h"
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * SYMBOL DEFINITIONS
1417c478bd9Sstevel@tonic-gate */
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate #define FS '|' /* Field seperator for output records. */
1447c478bd9Sstevel@tonic-gate #define LOGCHECK {if ((Initialized == FALSE) || \
1457c478bd9Sstevel@tonic-gate (Collecting == FALSE)) return; }
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /* Subscripts for connection time marks: */
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate #define CT_START 0 /* Start connection establishment. */
1507c478bd9Sstevel@tonic-gate #define CT_CONNECTED 1 /* Connection completed. */
1517c478bd9Sstevel@tonic-gate #define CT_SIZE 2 /* Number of elements in array. */
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /* Subscripts for xfer time marks: */
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate #define XT_LOOK 0 /* Start looking for a file (master only). */
1567c478bd9Sstevel@tonic-gate #define XT_FOUND 1 /* File found (master only). */
1577c478bd9Sstevel@tonic-gate #define XT_BEGXFER 2 /* Start of xfer of data. */
1587c478bd9Sstevel@tonic-gate #define XT_ENDXFER 3 /* Data xfer complete. */
1597c478bd9Sstevel@tonic-gate #define XT_ENDFILE 4 /* Done mailing and notifying. */
1607c478bd9Sstevel@tonic-gate #define XT_SIZE 5 /* Number of elements in array. */
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate * STRUCTURE DEFINITIONS
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate typedef struct timeUsed /* Time consummed between events. */
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate float tu_real; /* Real time used. */
1697c478bd9Sstevel@tonic-gate float tu_user; /* User time used. */
1707c478bd9Sstevel@tonic-gate float tu_sys; /* System time used. */
1717c478bd9Sstevel@tonic-gate } TUSED;
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate typedef struct timeMark /* Holds times for an event. */
1747c478bd9Sstevel@tonic-gate {
1757c478bd9Sstevel@tonic-gate int tm_valid; /* True if data present. */
1767c478bd9Sstevel@tonic-gate long tm_real; /* Relative wall clock. */
1777c478bd9Sstevel@tonic-gate struct tms tm_cycles; /* CPU consumption. */
1787c478bd9Sstevel@tonic-gate } TMARK;
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate struct connData /* Data for construction of conn record. */
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate char cn_role; /* Master/slave indicator. */
1837c478bd9Sstevel@tonic-gate TMARK cn_times[CT_SIZE]; /* Event data. */
1847c478bd9Sstevel@tonic-gate };
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate struct xferData /* Data for construction of xfer record. */
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate char xf_role; /* Master/slave indicator. */
1897c478bd9Sstevel@tonic-gate char xf_direction; /* Send/receive indicator. */
1907c478bd9Sstevel@tonic-gate time_t xf_intoque; /* Time that file was placed
1917c478bd9Sstevel@tonic-gate * in the queue. (master
1927c478bd9Sstevel@tonic-gate * only). */
1937c478bd9Sstevel@tonic-gate long xf_deque; /* Time that file was
1947c478bd9Sstevel@tonic-gate * dequeued. (master only)*/
1957c478bd9Sstevel@tonic-gate long xf_filedone; /* Time that file was
1967c478bd9Sstevel@tonic-gate * completed. */
1977c478bd9Sstevel@tonic-gate char xf_jobname[MODSTR]; /* C. file (master only)*/
1987c478bd9Sstevel@tonic-gate char xf_jobgrade[MODSTR]; /* job grade id */
1997c478bd9Sstevel@tonic-gate off_t xf_bytes; /* Bytes transferred. */
2007c478bd9Sstevel@tonic-gate char xf_flags[MODSTR]; /* Notification flags. */
2017c478bd9Sstevel@tonic-gate TMARK xf_times[XT_SIZE]; /* Event data. */
2027c478bd9Sstevel@tonic-gate };
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * LOCAL DATA
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate static int Collecting = FALSE; /* True if we are collecting
2097c478bd9Sstevel@tonic-gate * data. */
2107c478bd9Sstevel@tonic-gate static struct connData Conn = {0}; /* Connection data. */
2117c478bd9Sstevel@tonic-gate static char Device[MODSTR] = ""; /* Type of communication
2127c478bd9Sstevel@tonic-gate * device. */
2137c478bd9Sstevel@tonic-gate static int Initialized = FALSE; /* True if we have been
2147c478bd9Sstevel@tonic-gate * initialized. */
2157c478bd9Sstevel@tonic-gate static int LogFile = CLOSED; /* Log file file destriptor. */
2167c478bd9Sstevel@tonic-gate static char LogName[] = PERFLOG; /* Name of our log file. */
2177c478bd9Sstevel@tonic-gate static pid_t Procid = {0}; /* Our processid. */
2187c478bd9Sstevel@tonic-gate static char Record[LOGSIZE]; /* Place to build log records. */
2197c478bd9Sstevel@tonic-gate static char Remote[MODSTR] = ""; /* Name of the remote system. */
2207c478bd9Sstevel@tonic-gate static char myname[MAXBASENAME+1] = ""; /* Name of the source system
2217c478bd9Sstevel@tonic-gate . */
2227c478bd9Sstevel@tonic-gate static char Protocol[MODSTR]; /* Protocol in use */
2237c478bd9Sstevel@tonic-gate static char Netid[MODSTR] = NOTAVAIL; /* Network ID in use */
2247c478bd9Sstevel@tonic-gate static struct xferData Xfer = {0}; /* Transfer data. */
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /* Messages: */
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate static char Msg_badopen[] = "failed to open %s. Errno=%%d\n";
2297c478bd9Sstevel@tonic-gate static char Msg_opening[] = "attempting to open %s\n";
2307c478bd9Sstevel@tonic-gate static char Msg_write[] = "error in writing to %s. Errno=%%d.\n";
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * LOCAL FUNCTIONS
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /* Declarations of functions: */
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate STATIC_FUNC void grabTimes();
2397c478bd9Sstevel@tonic-gate STATIC_FUNC void pfloat();
2407c478bd9Sstevel@tonic-gate STATIC_FUNC void reportConn();
2417c478bd9Sstevel@tonic-gate STATIC_FUNC void reportFile();
2427c478bd9Sstevel@tonic-gate STATIC_FUNC void reportTimes();
2437c478bd9Sstevel@tonic-gate STATIC_FUNC void subTimes();
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * Local Function: grabTimes - Get Real and CPU Times
2487c478bd9Sstevel@tonic-gate *
2497c478bd9Sstevel@tonic-gate * This function uses times(2) to obtain the current real time and CPU
2507c478bd9Sstevel@tonic-gate * consumption. The time mark is also marked as valid.
2517c478bd9Sstevel@tonic-gate *
2527c478bd9Sstevel@tonic-gate * Parameters:
2537c478bd9Sstevel@tonic-gate *
2547c478bd9Sstevel@tonic-gate * markptr - Address of structure to save times.
2557c478bd9Sstevel@tonic-gate *
2567c478bd9Sstevel@tonic-gate * Return:
2577c478bd9Sstevel@tonic-gate *
2587c478bd9Sstevel@tonic-gate * none.
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate STATIC_FUNC void
grabTimes(markptr)2627c478bd9Sstevel@tonic-gate grabTimes (markptr)
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate register TMARK * markptr;
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate {
2677c478bd9Sstevel@tonic-gate markptr->tm_real = times(&markptr->tm_cycles);
2687c478bd9Sstevel@tonic-gate if (markptr->tm_real != FAIL)
2697c478bd9Sstevel@tonic-gate markptr->tm_valid = TRUE;
2707c478bd9Sstevel@tonic-gate return;
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate * Local Function: pfloat - Print a Floating Number
2767c478bd9Sstevel@tonic-gate *
2777c478bd9Sstevel@tonic-gate * Format a floating point number for output to the Unity data base.
2787c478bd9Sstevel@tonic-gate * If the number is NOTIME, "na" will be displayed instead.
2797c478bd9Sstevel@tonic-gate *
2807c478bd9Sstevel@tonic-gate * Parameters:
2817c478bd9Sstevel@tonic-gate *
2827c478bd9Sstevel@tonic-gate * dest - The result will be concatenated to this string.
2837c478bd9Sstevel@tonic-gate *
2847c478bd9Sstevel@tonic-gate * number - The number to be formated.
2857c478bd9Sstevel@tonic-gate *
2867c478bd9Sstevel@tonic-gate * sep - Field separator character.
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate STATIC_FUNC void
pfloat(dest,number,sep)2907c478bd9Sstevel@tonic-gate pfloat (dest, number, sep)
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate char * dest;
2937c478bd9Sstevel@tonic-gate double number; /* float is promoted to double for args. */
2947c478bd9Sstevel@tonic-gate char sep;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate static char rformat[] = "%c%.2f";
2987c478bd9Sstevel@tonic-gate static char naformat[] = "%c%s";
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate register char * cp;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate cp = dest + strlen(dest);
3037c478bd9Sstevel@tonic-gate if (number == (float) NOTIME)
3047c478bd9Sstevel@tonic-gate sprintf(cp, naformat, sep, NOTAVAIL);
3057c478bd9Sstevel@tonic-gate else
3067c478bd9Sstevel@tonic-gate sprintf(cp, rformat, sep, number);
3077c478bd9Sstevel@tonic-gate return;
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate * Local Function: reportConn - Write Out Conn Record
3127c478bd9Sstevel@tonic-gate *
3137c478bd9Sstevel@tonic-gate * This function writes a conn record to the logfile.
3147c478bd9Sstevel@tonic-gate *
3157c478bd9Sstevel@tonic-gate * Parameters:
3167c478bd9Sstevel@tonic-gate *
3177c478bd9Sstevel@tonic-gate * None.
3187c478bd9Sstevel@tonic-gate *
3197c478bd9Sstevel@tonic-gate * Returns:
3207c478bd9Sstevel@tonic-gate *
3217c478bd9Sstevel@tonic-gate * None.
3227c478bd9Sstevel@tonic-gate */
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate STATIC_FUNC void
reportConn()3257c478bd9Sstevel@tonic-gate reportConn ()
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate TUSED contimes; /* Times to make connection. */
3297c478bd9Sstevel@tonic-gate static char format[] = "%s%c%s%c%ld%c%s%c%c%c%s%c%s%c%s%c%s";
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate sprintf(Record, format,
3327c478bd9Sstevel@tonic-gate "conn", FS, /* record type. */
3337c478bd9Sstevel@tonic-gate gmt(), FS, /* current time. */
3347c478bd9Sstevel@tonic-gate (long) Procid, FS, /* our process id. */
3357c478bd9Sstevel@tonic-gate myname, FS, /* name of local system */
3367c478bd9Sstevel@tonic-gate Conn.cn_role, FS, /* slave or master. */
3377c478bd9Sstevel@tonic-gate Remote, FS, /* name of remote system. */
3387c478bd9Sstevel@tonic-gate Device, FS, /* device used for communication. */
3397c478bd9Sstevel@tonic-gate Protocol, FS, /* protocol used for comm. */
3407c478bd9Sstevel@tonic-gate Netid /* Network ID */
3417c478bd9Sstevel@tonic-gate );
3427c478bd9Sstevel@tonic-gate subTimes(&contimes, &Conn.cn_times[CT_CONNECTED],
3437c478bd9Sstevel@tonic-gate &Conn.cn_times[CT_START]);
3447c478bd9Sstevel@tonic-gate reportTimes(Record, &contimes, FS);
3457c478bd9Sstevel@tonic-gate strcat(Record, EOR);
3467c478bd9Sstevel@tonic-gate writeLog(Record,&LogFile,LogName,&Collecting);
3477c478bd9Sstevel@tonic-gate return;
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * Local Function: reportFile - Write File Statistics to Log
3527c478bd9Sstevel@tonic-gate *
3537c478bd9Sstevel@tonic-gate * This function writes statistics about the current file to the log
3547c478bd9Sstevel@tonic-gate * file.
3557c478bd9Sstevel@tonic-gate *
3567c478bd9Sstevel@tonic-gate * Parameters:
3577c478bd9Sstevel@tonic-gate *
3587c478bd9Sstevel@tonic-gate * none.
3597c478bd9Sstevel@tonic-gate */
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate STATIC_FUNC void
reportFile(breakmsg)3627c478bd9Sstevel@tonic-gate reportFile (breakmsg)
3637c478bd9Sstevel@tonic-gate char * breakmsg;
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate /* minuend, subtrahand */
3677c478bd9Sstevel@tonic-gate static int drvtab[] = {
3687c478bd9Sstevel@tonic-gate XT_FOUND, XT_LOOK, /* startup */
3697c478bd9Sstevel@tonic-gate XT_ENDXFER, XT_BEGXFER, /* xfer */
3707c478bd9Sstevel@tonic-gate XT_ENDFILE, XT_ENDXFER /* term. */
3717c478bd9Sstevel@tonic-gate };
3727c478bd9Sstevel@tonic-gate static char format1[] = "%s%c%s%c%s%c%ld%c%s%c%c%c%s%c%s%c%s%c%s%c%s";
3737c478bd9Sstevel@tonic-gate static char format2[] = "%c%ld%c%s"; /* Bytes & flags. */
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate register struct xferData * xdptr;
3767c478bd9Sstevel@tonic-gate register TMARK * tdptr;
3777c478bd9Sstevel@tonic-gate register int i;
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate TUSED diff; /* time difference between events. */
3807c478bd9Sstevel@tonic-gate float inque; /* time in queue. */
3817c478bd9Sstevel@tonic-gate int lastbyte; /* Offset to last byte in Record. */
3827c478bd9Sstevel@tonic-gate char * na = NOTAVAIL; /* String to show data not available*/
3837c478bd9Sstevel@tonic-gate char role; /* Current master/slave status. */
3847c478bd9Sstevel@tonic-gate float tat; /* Turn around time. */
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate xdptr = &Xfer; /* Point to Xfer data. */
3877c478bd9Sstevel@tonic-gate role = xdptr->xf_role;
3887c478bd9Sstevel@tonic-gate sprintf(Record, format1,
3897c478bd9Sstevel@tonic-gate "xfer", FS, /* Record type. */
3907c478bd9Sstevel@tonic-gate (role == MCHAR) ? xdptr->xf_jobgrade : na ,FS, /* job grade */
3917c478bd9Sstevel@tonic-gate gmt(), FS, /* Current time. */
3927c478bd9Sstevel@tonic-gate (long) Procid, FS, /* Our process id. */
3937c478bd9Sstevel@tonic-gate myname, FS, /* name of local system */
3947c478bd9Sstevel@tonic-gate role, FS, /* master/slave. */
3957c478bd9Sstevel@tonic-gate Remote, FS, /* remote. */
3967c478bd9Sstevel@tonic-gate Device, FS, /* communications device. */
3977c478bd9Sstevel@tonic-gate Protocol, FS, /* protocol used for comm. */
3987c478bd9Sstevel@tonic-gate Netid, FS, /* Network ID */
3997c478bd9Sstevel@tonic-gate (role == MCHAR) ? xdptr->xf_jobname : na
4007c478bd9Sstevel@tonic-gate );
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate /* Do time in queue and turn around time. */
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate if (role == MCHAR)
4057c478bd9Sstevel@tonic-gate {
4067c478bd9Sstevel@tonic-gate inque = (float) (xdptr->xf_deque - xdptr->xf_intoque);
4077c478bd9Sstevel@tonic-gate tat = (float) (xdptr->xf_filedone - xdptr->xf_intoque);
4087c478bd9Sstevel@tonic-gate } else
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate inque = (float) NOTIME; /* Not app. if not master. */
4117c478bd9Sstevel@tonic-gate tat = (float) NOTIME;
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate pfloat(Record, inque, FS);
4147c478bd9Sstevel@tonic-gate pfloat(Record, tat, FS);
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate /*
4177c478bd9Sstevel@tonic-gate * Report bytes transferred and notification flags.
4187c478bd9Sstevel@tonic-gate */
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate lastbyte = strlen(Record);
4217c478bd9Sstevel@tonic-gate (void) sprintf(Record+lastbyte, format2,
4227c478bd9Sstevel@tonic-gate FS, getfilesize(),FS,
4237c478bd9Sstevel@tonic-gate (role == MCHAR) ? xdptr->xf_flags : na
4247c478bd9Sstevel@tonic-gate );
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate * Report resource consumption for file startup, file transfer,
4287c478bd9Sstevel@tonic-gate * and file termination. This means reporting the differences
4297c478bd9Sstevel@tonic-gate * between pairs of elements in the xf_times array of Xfer. This
4307c478bd9Sstevel@tonic-gate * will be controled by drvtab which contains pairs of subscripts
4317c478bd9Sstevel@tonic-gate * to designate the xf_times elements.
4327c478bd9Sstevel@tonic-gate */
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate tdptr = &xdptr->xf_times[0];
4357c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof(drvtab)/(sizeof(int)); i += 2)
4367c478bd9Sstevel@tonic-gate {
4377c478bd9Sstevel@tonic-gate subTimes(&diff, (tdptr + drvtab[i]), (tdptr + drvtab[i+1]));
4387c478bd9Sstevel@tonic-gate reportTimes(Record, &diff, FS);
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate * write file status
4437c478bd9Sstevel@tonic-gate */
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate lastbyte = strlen(Record);
4467c478bd9Sstevel@tonic-gate (void) sprintf(Record+lastbyte, "%c%s%c",
4477c478bd9Sstevel@tonic-gate FS, (*breakmsg == NULLCHAR) ? NOTAVAIL : breakmsg, FS);
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate /* Terminate the record and write it out. */
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate (void) strcat(Record, EOR);
4527c478bd9Sstevel@tonic-gate writeLog(Record,&LogFile,LogName,&Collecting);
4537c478bd9Sstevel@tonic-gate return;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate * Local Function: reportTimes - Print Real, User, and Sys Times
4587c478bd9Sstevel@tonic-gate *
4597c478bd9Sstevel@tonic-gate * This function is used to convert the real, user, and system times from
4607c478bd9Sstevel@tonic-gate * a TUSED structure to Ascii strings. The results are concatenated to
4617c478bd9Sstevel@tonic-gate * the dest string. If any of the times are NOTIME, they will be reported
4627c478bd9Sstevel@tonic-gate * as "na". The fields will be seperated by the sep character and the
4637c478bd9Sstevel@tonic-gate * sep character will be the first character concatenated to the buffer. No
4647c478bd9Sstevel@tonic-gate * seperator character will be placed at the end. Thus, the output string
4657c478bd9Sstevel@tonic-gate * will be of the form:
4667c478bd9Sstevel@tonic-gate *
4677c478bd9Sstevel@tonic-gate * |real|user|sys
4687c478bd9Sstevel@tonic-gate *
4697c478bd9Sstevel@tonic-gate * Parameters:
4707c478bd9Sstevel@tonic-gate *
4717c478bd9Sstevel@tonic-gate * dest - String to receive Ascii times.
4727c478bd9Sstevel@tonic-gate *
4737c478bd9Sstevel@tonic-gate * diffptr - Address of the time data.
4747c478bd9Sstevel@tonic-gate *
4757c478bd9Sstevel@tonic-gate * sep - The field seperator character.
4767c478bd9Sstevel@tonic-gate */
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate STATIC_FUNC void
reportTimes(dest,diffptr,sep)4797c478bd9Sstevel@tonic-gate reportTimes (dest, diffptr, sep)
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate register char * dest;
4827c478bd9Sstevel@tonic-gate register TUSED * diffptr;
4837c478bd9Sstevel@tonic-gate char sep;
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate pfloat(dest, diffptr->tu_real, sep);
4877c478bd9Sstevel@tonic-gate pfloat(dest, diffptr->tu_user, sep);
4887c478bd9Sstevel@tonic-gate pfloat(dest, diffptr->tu_sys, sep);
4897c478bd9Sstevel@tonic-gate return;
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate /*
4937c478bd9Sstevel@tonic-gate * Local Function: subTimes - Subtract Times Between Events
4947c478bd9Sstevel@tonic-gate *
4957c478bd9Sstevel@tonic-gate * This function takes the output from two calls to times(2) in the form
4967c478bd9Sstevel@tonic-gate * of two TMARK structures, and determines the amount of time consummed
4977c478bd9Sstevel@tonic-gate * for various categories. The result is stored in the specified
4987c478bd9Sstevel@tonic-gate * TUSED structure.
4997c478bd9Sstevel@tonic-gate *
5007c478bd9Sstevel@tonic-gate * Parameters:
5017c478bd9Sstevel@tonic-gate *
5027c478bd9Sstevel@tonic-gate * diff - Place to store the result of the subtraction.
5037c478bd9Sstevel@tonic-gate * minuend - The second time event.
5047c478bd9Sstevel@tonic-gate * subtra - The subtrahend in the subtraction. This should
5057c478bd9Sstevel@tonic-gate * be the first of two time events.
5067c478bd9Sstevel@tonic-gate *
5077c478bd9Sstevel@tonic-gate * On the large scale this function does the following:
5087c478bd9Sstevel@tonic-gate *
5097c478bd9Sstevel@tonic-gate * diff = minuend - subtra
5107c478bd9Sstevel@tonic-gate */
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate STATIC_FUNC void
subTimes(diff,minuend,subtra)5137c478bd9Sstevel@tonic-gate subTimes (diff, minuend, subtra)
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate register TUSED * diff;
5167c478bd9Sstevel@tonic-gate register TMARK * minuend;
5177c478bd9Sstevel@tonic-gate register TMARK * subtra;
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate {
5207c478bd9Sstevel@tonic-gate register struct tms * mintms;
5217c478bd9Sstevel@tonic-gate register struct tms * subtms;
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate long ltemp; /* Temporary storage for long arith. */
5247c478bd9Sstevel@tonic-gate float ticks; /* Clock interrupts per second. */
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate if ((minuend->tm_valid != TRUE) || (subtra->tm_valid != TRUE))
5277c478bd9Sstevel@tonic-gate { /* If data has not been collected. */
5287c478bd9Sstevel@tonic-gate diff->tu_real = NOTIME;
5297c478bd9Sstevel@tonic-gate diff->tu_user = NOTIME;
5307c478bd9Sstevel@tonic-gate diff->tu_sys = NOTIME;
5317c478bd9Sstevel@tonic-gate } else
5327c478bd9Sstevel@tonic-gate {
5337c478bd9Sstevel@tonic-gate ticks = (float) HZ; /* HZ defined in <sys/param.h>. */
5347c478bd9Sstevel@tonic-gate mintms = &minuend->tm_cycles;
5357c478bd9Sstevel@tonic-gate subtms = &subtra->tm_cycles;
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate /* Calculate real time. */
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate ltemp = minuend->tm_real - subtra->tm_real;
5407c478bd9Sstevel@tonic-gate diff->tu_real = ((float) ltemp)/ticks;
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate /* Calculate user time. */
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate ltemp = mintms->tms_utime
5457c478bd9Sstevel@tonic-gate - subtms->tms_utime
5467c478bd9Sstevel@tonic-gate + mintms->tms_cutime
5477c478bd9Sstevel@tonic-gate - subtms->tms_cutime;
5487c478bd9Sstevel@tonic-gate diff->tu_user = ((float) ltemp)/ticks;
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate /* Calculate user time. */
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate ltemp = mintms->tms_stime
5537c478bd9Sstevel@tonic-gate - subtms->tms_stime
5547c478bd9Sstevel@tonic-gate + mintms->tms_cstime
5557c478bd9Sstevel@tonic-gate - subtms->tms_cstime;
5567c478bd9Sstevel@tonic-gate diff->tu_sys = ((float) ltemp)/ticks;
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate return;
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate /*
5627c478bd9Sstevel@tonic-gate * EXTERNAL FUNCTIONS
5637c478bd9Sstevel@tonic-gate */
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate /*
5667c478bd9Sstevel@tonic-gate * Function: gmt - Generate Current Time String
5677c478bd9Sstevel@tonic-gate *
5687c478bd9Sstevel@tonic-gate * This function returns the address a string containing the current
5697c478bd9Sstevel@tonic-gate * GMT in the form YYMMDDhhmmss.
5707c478bd9Sstevel@tonic-gate *
5717c478bd9Sstevel@tonic-gate * Parameters:
5727c478bd9Sstevel@tonic-gate *
5737c478bd9Sstevel@tonic-gate * none
5747c478bd9Sstevel@tonic-gate *
5757c478bd9Sstevel@tonic-gate * Return:
5767c478bd9Sstevel@tonic-gate *
5777c478bd9Sstevel@tonic-gate * An address of a static character array containing the date.
5787c478bd9Sstevel@tonic-gate */
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate char *
gmt()5817c478bd9Sstevel@tonic-gate gmt()
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate {
5847c478bd9Sstevel@tonic-gate static char date[] = "YYMMDDhhmmss";
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate register struct tm * td;
5877c478bd9Sstevel@tonic-gate time_t now; /* Current time. */
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate now = time((time_t *) 0);
5907c478bd9Sstevel@tonic-gate td = gmtime(&now);
5917c478bd9Sstevel@tonic-gate (void) sprintf(date, "%02d%02d%02d%02d%02d%02d",
5927c478bd9Sstevel@tonic-gate (td->tm_year % 100),
5937c478bd9Sstevel@tonic-gate td->tm_mon + 1,
5947c478bd9Sstevel@tonic-gate td->tm_mday,
5957c478bd9Sstevel@tonic-gate td->tm_hour,
5967c478bd9Sstevel@tonic-gate td->tm_min,
5977c478bd9Sstevel@tonic-gate td->tm_sec
5987c478bd9Sstevel@tonic-gate );
5997c478bd9Sstevel@tonic-gate return date;
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate /*
6047c478bd9Sstevel@tonic-gate * Function: writeLog - Write String to Log File
6057c478bd9Sstevel@tonic-gate *
6067c478bd9Sstevel@tonic-gate * After insuring that the log file is open, this function will write
6077c478bd9Sstevel@tonic-gate * the specified string to the log file. If a write error occurs,
6087c478bd9Sstevel@tonic-gate * statistics collection will be disabled.
6097c478bd9Sstevel@tonic-gate *
6107c478bd9Sstevel@tonic-gate * Parameters:
6117c478bd9Sstevel@tonic-gate *
6127c478bd9Sstevel@tonic-gate * string - Null terminated string to be written out.
6137c478bd9Sstevel@tonic-gate * logfile - file descripter
6147c478bd9Sstevel@tonic-gate * logname - name of log file.
6157c478bd9Sstevel@tonic-gate * collecting - log enable/disable
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate void
writeLog(string,logfile,logname,collecting)6197c478bd9Sstevel@tonic-gate writeLog (string, logfile, logname, collecting)
6207c478bd9Sstevel@tonic-gate
6217c478bd9Sstevel@tonic-gate char * string;
6227c478bd9Sstevel@tonic-gate int * logfile;
6237c478bd9Sstevel@tonic-gate char * logname;
6247c478bd9Sstevel@tonic-gate int * collecting;
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate register int length; /* Length of the string. */
6287c478bd9Sstevel@tonic-gate register int rv; /* Return value from write. */
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate char errmsg[BUFSIZ]; /* Place for error messages. */
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate if (openLog(logfile,logname) != SUCCESS){
6337c478bd9Sstevel@tonic-gate *collecting = FALSE;
6347c478bd9Sstevel@tonic-gate return;
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate length = strlen(string);
6377c478bd9Sstevel@tonic-gate do
6387c478bd9Sstevel@tonic-gate {
6397c478bd9Sstevel@tonic-gate rv = write(*logfile, string, (unsigned) length);
6407c478bd9Sstevel@tonic-gate } while ((rv < 0) && (errno == EINTR)); /* Retry if interrupted. */
6417c478bd9Sstevel@tonic-gate if (rv < length)
6427c478bd9Sstevel@tonic-gate { /* Error or incomplete output. */
6437c478bd9Sstevel@tonic-gate (void) sprintf(errmsg, Msg_write, logname);
6447c478bd9Sstevel@tonic-gate DEBUG(DB_IMPORTANT, errmsg, errno);
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate /* If we had a write error, lets give up on loggine. */
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate closeLog(logfile);
6497c478bd9Sstevel@tonic-gate *collecting = FALSE;
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate return;
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate /*
6557c478bd9Sstevel@tonic-gate * Function: closeLog - Close the Log File
6567c478bd9Sstevel@tonic-gate *
6577c478bd9Sstevel@tonic-gate * This function allows uucico to close the log file in preparation for
6587c478bd9Sstevel@tonic-gate * forking.
6597c478bd9Sstevel@tonic-gate *
6607c478bd9Sstevel@tonic-gate * Parameters:
6617c478bd9Sstevel@tonic-gate *
6627c478bd9Sstevel@tonic-gate * log file descriptor
6637c478bd9Sstevel@tonic-gate */
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate void
closeLog(logfile)6667c478bd9Sstevel@tonic-gate closeLog (logfile)
6677c478bd9Sstevel@tonic-gate int *logfile;
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate {
6707c478bd9Sstevel@tonic-gate if (*logfile != CLOSED)
6717c478bd9Sstevel@tonic-gate {
6727c478bd9Sstevel@tonic-gate (void) close(*logfile);
6737c478bd9Sstevel@tonic-gate *logfile = CLOSED;
6747c478bd9Sstevel@tonic-gate }
6757c478bd9Sstevel@tonic-gate return;
6767c478bd9Sstevel@tonic-gate }
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate /*
6807c478bd9Sstevel@tonic-gate * Function: copyText - Copy String to Dynamic Memory
6817c478bd9Sstevel@tonic-gate *
6827c478bd9Sstevel@tonic-gate * This function copies a string to a buffer. It insures that there is
6837c478bd9Sstevel@tonic-gate * no overflow of the buffer and that the result is null terminated.
6847c478bd9Sstevel@tonic-gate *
6857c478bd9Sstevel@tonic-gate * Parameters:
6867c478bd9Sstevel@tonic-gate *
6877c478bd9Sstevel@tonic-gate * tptr - address of the buffer where the string is to
6887c478bd9Sstevel@tonic-gate * be stored.
6897c478bd9Sstevel@tonic-gate *
6907c478bd9Sstevel@tonic-gate * size - number of bytes in the buffer.
6917c478bd9Sstevel@tonic-gate *
6927c478bd9Sstevel@tonic-gate * string - string to be saved.
6937c478bd9Sstevel@tonic-gate *
6947c478bd9Sstevel@tonic-gate * Returns:
6957c478bd9Sstevel@tonic-gate *
6967c478bd9Sstevel@tonic-gate * none.
6977c478bd9Sstevel@tonic-gate */
6987c478bd9Sstevel@tonic-gate
6997c478bd9Sstevel@tonic-gate void
copyText(tptr,size,string)7007c478bd9Sstevel@tonic-gate copyText (tptr, size, string)
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gate register char * tptr;
7037c478bd9Sstevel@tonic-gate register int size;
7047c478bd9Sstevel@tonic-gate char * string;
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate {
7077c478bd9Sstevel@tonic-gate (void) strncpy(tptr, string, size);
7087c478bd9Sstevel@tonic-gate *(tptr + size - 1) = NULLCHAR;
7097c478bd9Sstevel@tonic-gate return;
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate /*
7137c478bd9Sstevel@tonic-gate * Function: pfConnected - Report Connection Completion
7147c478bd9Sstevel@tonic-gate *
7157c478bd9Sstevel@tonic-gate * Uucico uses pfConnected to tell this performance package that a connection
7167c478bd9Sstevel@tonic-gate * has been established with the remote system.
7177c478bd9Sstevel@tonic-gate *
7187c478bd9Sstevel@tonic-gate * Parameters:
7197c478bd9Sstevel@tonic-gate *
7207c478bd9Sstevel@tonic-gate * remote - name of the remote system.
7217c478bd9Sstevel@tonic-gate *
7227c478bd9Sstevel@tonic-gate * device - the type of device being used for communicaitons.
7237c478bd9Sstevel@tonic-gate */
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate void
pfConnected(remote,device)7267c478bd9Sstevel@tonic-gate pfConnected (remote, device)
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate char * remote;
7297c478bd9Sstevel@tonic-gate char * device;
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate register int i;
7337c478bd9Sstevel@tonic-gate register TMARK * tptr;
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate LOGCHECK;
7367c478bd9Sstevel@tonic-gate grabTimes(&Conn.cn_times[CT_CONNECTED]);
7377c478bd9Sstevel@tonic-gate copyText(Remote, sizeof(Remote), remote);
7387c478bd9Sstevel@tonic-gate copyText(Device, sizeof(Device), device);
7397c478bd9Sstevel@tonic-gate reportConn();
7407c478bd9Sstevel@tonic-gate tptr = &Conn.cn_times[0];
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate /*
7437c478bd9Sstevel@tonic-gate * Mark connection times as invalid. This is really unnecessary
7447c478bd9Sstevel@tonic-gate * since there should only be one connection per invocation of uucico.
7457c478bd9Sstevel@tonic-gate * We do it for consistency with use of the transfer data.
7467c478bd9Sstevel@tonic-gate */
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate for (i = 0; i < CT_SIZE; i++, tptr++)
7497c478bd9Sstevel@tonic-gate tptr->tm_valid = FALSE;
7507c478bd9Sstevel@tonic-gate return;
7517c478bd9Sstevel@tonic-gate }
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate
7547c478bd9Sstevel@tonic-gate /*
7557c478bd9Sstevel@tonic-gate * Function: pfEndFile - Report End of File
7567c478bd9Sstevel@tonic-gate *
7577c478bd9Sstevel@tonic-gate * Uucico uses pfEndFile to tell our statistics collection package that
7587c478bd9Sstevel@tonic-gate * all processing has been finished on the current file. PfEndfile should
7597c478bd9Sstevel@tonic-gate * be called after all notifications have been done and after the status
7607c478bd9Sstevel@tonic-gate * file has been written. PfEndfile writes out a xfer record for the
7617c478bd9Sstevel@tonic-gate * file that just completed.
7627c478bd9Sstevel@tonic-gate *
7637c478bd9Sstevel@tonic-gate * Parameters:
7647c478bd9Sstevel@tonic-gate *
7657c478bd9Sstevel@tonic-gate * none
7667c478bd9Sstevel@tonic-gate */
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate void
pfEndfile(breakmsg)7697c478bd9Sstevel@tonic-gate pfEndfile (breakmsg)
7707c478bd9Sstevel@tonic-gate char * breakmsg;
7717c478bd9Sstevel@tonic-gate {
7727c478bd9Sstevel@tonic-gate register int i;
7737c478bd9Sstevel@tonic-gate register TMARK * tdptr;
7747c478bd9Sstevel@tonic-gate register struct xferData * xptr = &Xfer;
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate LOGCHECK;
7777c478bd9Sstevel@tonic-gate grabTimes(&Xfer.xf_times[XT_ENDFILE]);
7787c478bd9Sstevel@tonic-gate Xfer.xf_filedone = time((time_t *) 0);
7797c478bd9Sstevel@tonic-gate reportFile(breakmsg);
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate /* Now that we have reported them, mark all times as invalid. */
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate copyText(xptr->xf_flags, sizeof(xptr->xf_flags), NOTAVAIL);
7847c478bd9Sstevel@tonic-gate tdptr = &Xfer.xf_times[0];
7857c478bd9Sstevel@tonic-gate for (i = 0; i < XT_SIZE; i++, tdptr++)
7867c478bd9Sstevel@tonic-gate tdptr->tm_valid = FALSE;
7877c478bd9Sstevel@tonic-gate return;
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate /*
7917c478bd9Sstevel@tonic-gate * Function: pfEndXfer - File Transfer Complete
7927c478bd9Sstevel@tonic-gate *
7937c478bd9Sstevel@tonic-gate * Calling pfEndXfer tells the performance package that a file transfer
7947c478bd9Sstevel@tonic-gate * has been completed. It should be called after the destination site
7957c478bd9Sstevel@tonic-gate * closes the file and confirms receipt, but before notifications are done.
7967c478bd9Sstevel@tonic-gate *
7977c478bd9Sstevel@tonic-gate * Parameters:
7987c478bd9Sstevel@tonic-gate *
7997c478bd9Sstevel@tonic-gate * none
8007c478bd9Sstevel@tonic-gate */
8017c478bd9Sstevel@tonic-gate
8027c478bd9Sstevel@tonic-gate void
pfEndXfer()8037c478bd9Sstevel@tonic-gate pfEndXfer ()
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate {
8067c478bd9Sstevel@tonic-gate LOGCHECK;
8077c478bd9Sstevel@tonic-gate grabTimes(&Xfer.xf_times[XT_ENDXFER]);
8087c478bd9Sstevel@tonic-gate return;
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate /*
8127c478bd9Sstevel@tonic-gate * Function: pfFindFile - Looking for Another File
8137c478bd9Sstevel@tonic-gate *
8147c478bd9Sstevel@tonic-gate * Uucico uses pfFindFile to announce that it is going to explore the
8157c478bd9Sstevel@tonic-gate * queues for another file transfer to do. PfFindFile is only called
8167c478bd9Sstevel@tonic-gate * when uucico is in the role of master.
8177c478bd9Sstevel@tonic-gate *
8187c478bd9Sstevel@tonic-gate * Parameters:
8197c478bd9Sstevel@tonic-gate *
8207c478bd9Sstevel@tonic-gate * none
8217c478bd9Sstevel@tonic-gate */
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate void
pfFindFile()8247c478bd9Sstevel@tonic-gate pfFindFile ()
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate {
8277c478bd9Sstevel@tonic-gate LOGCHECK;
8287c478bd9Sstevel@tonic-gate grabTimes(&Xfer.xf_times[XT_LOOK]);
8297c478bd9Sstevel@tonic-gate return;
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gate /*
8337c478bd9Sstevel@tonic-gate * Function: pfFound - Found Another File
8347c478bd9Sstevel@tonic-gate *
8357c478bd9Sstevel@tonic-gate * PfFound is a counterpart of pfFindFile. It is called when a new file
8367c478bd9Sstevel@tonic-gate * has been found. Like pfFindFile it is called only by a master uucico.
8377c478bd9Sstevel@tonic-gate *
8387c478bd9Sstevel@tonic-gate * Parameters:
8397c478bd9Sstevel@tonic-gate *
8407c478bd9Sstevel@tonic-gate * jobid - The name of the job that was found.
8417c478bd9Sstevel@tonic-gate *
8427c478bd9Sstevel@tonic-gate * flags - Options flags that were stored in the queue.
8437c478bd9Sstevel@tonic-gate * These flags are originally set by uucp.
8447c478bd9Sstevel@tonic-gate *
8457c478bd9Sstevel@tonic-gate * intoQue - The time that the C. file was placed in the queue.
8467c478bd9Sstevel@tonic-gate */
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate void
pfFound(jobid,flags,intoQue)8497c478bd9Sstevel@tonic-gate pfFound (jobid, flags, intoQue)
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate char * jobid;
8527c478bd9Sstevel@tonic-gate char * flags;
8537c478bd9Sstevel@tonic-gate time_t intoQue;
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate {
8567c478bd9Sstevel@tonic-gate register struct xferData * xptr = &Xfer;
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate LOGCHECK;
8597c478bd9Sstevel@tonic-gate grabTimes(&xptr->xf_times[XT_FOUND]);
8607c478bd9Sstevel@tonic-gate copyText(xptr->xf_jobname, sizeof(xptr->xf_jobname), jobid);
861*2a8bcb4eSToomas Soome xptr->xf_jobgrade[0] = jobid[strlen(jobid)-5];
8627c478bd9Sstevel@tonic-gate xptr->xf_jobgrade[1] = NULLCHAR;/* get job grade from jobid */
8637c478bd9Sstevel@tonic-gate copyText(xptr->xf_flags, sizeof(xptr->xf_flags), flags);
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate /* Save time that file was placed in queue and current time. */
8667c478bd9Sstevel@tonic-gate
8677c478bd9Sstevel@tonic-gate xptr->xf_intoque = intoQue;
8687c478bd9Sstevel@tonic-gate xptr->xf_deque = time((time_t *) 0);
8697c478bd9Sstevel@tonic-gate return;
8707c478bd9Sstevel@tonic-gate }
8717c478bd9Sstevel@tonic-gate
8727c478bd9Sstevel@tonic-gate /*
8737c478bd9Sstevel@tonic-gate * Function: pfInit - Initialize Performance Package
8747c478bd9Sstevel@tonic-gate *
8757c478bd9Sstevel@tonic-gate * This function allows the performance package to initialize its internal
8767c478bd9Sstevel@tonic-gate * data structures. It should be called one time only when uucico starts
8777c478bd9Sstevel@tonic-gate * running.
8787c478bd9Sstevel@tonic-gate *
8797c478bd9Sstevel@tonic-gate * Parameters:
8807c478bd9Sstevel@tonic-gate *
8817c478bd9Sstevel@tonic-gate * none
8827c478bd9Sstevel@tonic-gate */
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate void
pfInit()8857c478bd9Sstevel@tonic-gate pfInit ()
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate {
8887c478bd9Sstevel@tonic-gate register struct xferData * xptr = &Xfer;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate if (Initialized == TRUE)
8917c478bd9Sstevel@tonic-gate return;
8927c478bd9Sstevel@tonic-gate Procid = getpid();
8937c478bd9Sstevel@tonic-gate myName(myname);
8947c478bd9Sstevel@tonic-gate copyText(xptr->xf_flags, sizeof(xptr->xf_flags), NOTAVAIL);
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate /*
8977c478bd9Sstevel@tonic-gate * Attempt to open the log file. If we can't do it, then we
8987c478bd9Sstevel@tonic-gate * won't collect statistics.
8997c478bd9Sstevel@tonic-gate */
9007c478bd9Sstevel@tonic-gate
9017c478bd9Sstevel@tonic-gate if (openLog(&LogFile,LogName) == SUCCESS)
9027c478bd9Sstevel@tonic-gate Collecting = TRUE;
9037c478bd9Sstevel@tonic-gate else
9047c478bd9Sstevel@tonic-gate Collecting = FALSE;
9057c478bd9Sstevel@tonic-gate Initialized = TRUE;
9067c478bd9Sstevel@tonic-gate return;
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate /*
9107c478bd9Sstevel@tonic-gate * Function: pfStrtConn - Going to Establish Connection
9117c478bd9Sstevel@tonic-gate *
9127c478bd9Sstevel@tonic-gate * Uucico uses pfStrtConn to announce that it is going to attempt
9137c478bd9Sstevel@tonic-gate * to establish a connection.
9147c478bd9Sstevel@tonic-gate *
9157c478bd9Sstevel@tonic-gate * Parameters:
9167c478bd9Sstevel@tonic-gate *
9177c478bd9Sstevel@tonic-gate * role - An indication of whether uucico is currently
9187c478bd9Sstevel@tonic-gate * running in master or slave mode. M = master,
9197c478bd9Sstevel@tonic-gate * S = slave.
9207c478bd9Sstevel@tonic-gate */
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate void
pfStrtConn(role)9237c478bd9Sstevel@tonic-gate pfStrtConn (role)
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate char role;
9267c478bd9Sstevel@tonic-gate {
9277c478bd9Sstevel@tonic-gate LOGCHECK;
9287c478bd9Sstevel@tonic-gate grabTimes(&Conn.cn_times[CT_START]);
9297c478bd9Sstevel@tonic-gate Conn.cn_role = role;
9307c478bd9Sstevel@tonic-gate return;
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate /*
9347c478bd9Sstevel@tonic-gate * Function: pfStrtXfer - Starting File Transfer
9357c478bd9Sstevel@tonic-gate *
9367c478bd9Sstevel@tonic-gate * This function should be called just as the first byte of data is
9377c478bd9Sstevel@tonic-gate * about to be transferred.
9387c478bd9Sstevel@tonic-gate *
9397c478bd9Sstevel@tonic-gate * Parameters:
9407c478bd9Sstevel@tonic-gate *
9417c478bd9Sstevel@tonic-gate * role - An indication of whether uucico is currently
9427c478bd9Sstevel@tonic-gate * running in master or slave mode. M = master,
9437c478bd9Sstevel@tonic-gate * S = slave.
9447c478bd9Sstevel@tonic-gate *
9457c478bd9Sstevel@tonic-gate * direction - Direction of file transfer. S = sending to
9467c478bd9Sstevel@tonic-gate * remote, R = receiving from remote.
9477c478bd9Sstevel@tonic-gate */
9487c478bd9Sstevel@tonic-gate
9497c478bd9Sstevel@tonic-gate void
pfStrtXfer(role,direction)9507c478bd9Sstevel@tonic-gate pfStrtXfer(role, direction)
9517c478bd9Sstevel@tonic-gate
9527c478bd9Sstevel@tonic-gate char role;
9537c478bd9Sstevel@tonic-gate char direction;
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate {
9567c478bd9Sstevel@tonic-gate register struct xferData * xptr = &Xfer;
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate LOGCHECK;
9597c478bd9Sstevel@tonic-gate grabTimes(&xptr->xf_times[XT_BEGXFER]);
9607c478bd9Sstevel@tonic-gate xptr->xf_role = role;
9617c478bd9Sstevel@tonic-gate xptr->xf_direction = direction;
9627c478bd9Sstevel@tonic-gate return;
9637c478bd9Sstevel@tonic-gate }
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate /*
9667c478bd9Sstevel@tonic-gate A protocol which both master and slave sides agree on
9677c478bd9Sstevel@tonic-gate */
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate void
pfPtcl(str)9707c478bd9Sstevel@tonic-gate pfPtcl(str)
9717c478bd9Sstevel@tonic-gate char *str;
9727c478bd9Sstevel@tonic-gate {
9737c478bd9Sstevel@tonic-gate strcpy(Protocol,str);
9747c478bd9Sstevel@tonic-gate return;
9757c478bd9Sstevel@tonic-gate }
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate /*
9787c478bd9Sstevel@tonic-gate * Function: openLog - Open the Log File
9797c478bd9Sstevel@tonic-gate *
9807c478bd9Sstevel@tonic-gate * If the log file is already open this function immediately returns
9817c478bd9Sstevel@tonic-gate * success. Otherwise, an attempt is made to open the logfile in append
9827c478bd9Sstevel@tonic-gate * mode.
9837c478bd9Sstevel@tonic-gate *
9847c478bd9Sstevel@tonic-gate * Parameters:
9857c478bd9Sstevel@tonic-gate *
9867c478bd9Sstevel@tonic-gate * logfile - file descripter
9877c478bd9Sstevel@tonic-gate * logname - name of log file.
9887c478bd9Sstevel@tonic-gate *
9897c478bd9Sstevel@tonic-gate * Returns:
9907c478bd9Sstevel@tonic-gate *
9917c478bd9Sstevel@tonic-gate * SUCCESS - The log file is open.
9927c478bd9Sstevel@tonic-gate * FAIL - Unable to open logfile.
9937c478bd9Sstevel@tonic-gate */
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate int
openLog(logfile,logname)9967c478bd9Sstevel@tonic-gate openLog (logfile,logname)
9977c478bd9Sstevel@tonic-gate int *logfile;
9987c478bd9Sstevel@tonic-gate char *logname;
9997c478bd9Sstevel@tonic-gate {
10007c478bd9Sstevel@tonic-gate register int fd; /* File descriptor of log file. */
10017c478bd9Sstevel@tonic-gate
10027c478bd9Sstevel@tonic-gate int level; /* Level for debug message. */
10037c478bd9Sstevel@tonic-gate char msgbuf[BUFSIZ];
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate /* See if file already open. */
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate if (*logfile != CLOSED)
10087c478bd9Sstevel@tonic-gate return (SUCCESS);
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate /* Attempt to open the file. */
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gate DEBUG(DB_TRACE, Msg_opening, logname);
10137c478bd9Sstevel@tonic-gate do
10147c478bd9Sstevel@tonic-gate {
10157c478bd9Sstevel@tonic-gate fd = open(logname, O_WRONLY | O_APPEND);
10167c478bd9Sstevel@tonic-gate } while ((fd < 0) && (errno == EINTR)); /* Retry if interrupted. */
10177c478bd9Sstevel@tonic-gate if (fd < 0) { /* Error on open. */
10187c478bd9Sstevel@tonic-gate (void) sprintf(msgbuf, Msg_badopen, logname);
10197c478bd9Sstevel@tonic-gate if (errno == ENOENT)
10207c478bd9Sstevel@tonic-gate level = DB_DETAIL; /* If the file is not there
10217c478bd9Sstevel@tonic-gate * it will usually mean
10227c478bd9Sstevel@tonic-gate * that the SA doesn't
10237c478bd9Sstevel@tonic-gate * want to collect
10247c478bd9Sstevel@tonic-gate * statisitcs. */
10257c478bd9Sstevel@tonic-gate else
10267c478bd9Sstevel@tonic-gate level = DB_IMPORTANT; /* Unexpected error */
10277c478bd9Sstevel@tonic-gate DEBUG(level, msgbuf, errno); /* No log file. */
10287c478bd9Sstevel@tonic-gate return FAIL;
10297c478bd9Sstevel@tonic-gate } else {
10307c478bd9Sstevel@tonic-gate *logfile = fd;
10317c478bd9Sstevel@tonic-gate return SUCCESS;
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate }
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gate #ifdef BSD4_2
10367c478bd9Sstevel@tonic-gate #include <sys/time.h>
10377c478bd9Sstevel@tonic-gate #include <sys/times.h>
10387c478bd9Sstevel@tonic-gate #include <sys/resource.h>
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate static clock_t
scale60(tvp)10417c478bd9Sstevel@tonic-gate scale60(tvp)
10427c478bd9Sstevel@tonic-gate register struct timeval *tvp;
10437c478bd9Sstevel@tonic-gate {
10447c478bd9Sstevel@tonic-gate return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
10457c478bd9Sstevel@tonic-gate }
10467c478bd9Sstevel@tonic-gate
10477c478bd9Sstevel@tonic-gate clock_t
times(tmsp)10487c478bd9Sstevel@tonic-gate times(tmsp)
10497c478bd9Sstevel@tonic-gate register struct tms *tmsp;
10507c478bd9Sstevel@tonic-gate {
10517c478bd9Sstevel@tonic-gate struct rusage ru;
10527c478bd9Sstevel@tonic-gate struct timeval now;
10537c478bd9Sstevel@tonic-gate static time_t epoch;
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate if (getrusage(RUSAGE_SELF, &ru) < 0)
10567c478bd9Sstevel@tonic-gate return (clock_t)(-1);
10577c478bd9Sstevel@tonic-gate tmsp->tms_utime = scale60(&ru.ru_utime);
10587c478bd9Sstevel@tonic-gate tmsp->tms_stime = scale60(&ru.ru_stime);
10597c478bd9Sstevel@tonic-gate if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
10607c478bd9Sstevel@tonic-gate return (clock_t)(-1);
10617c478bd9Sstevel@tonic-gate tmsp->tms_cutime = scale60(&ru.ru_utime);
10627c478bd9Sstevel@tonic-gate tmsp->tms_cstime = scale60(&ru.ru_stime);
10637c478bd9Sstevel@tonic-gate if (gettimeofday(&now, (struct timezone *)0) < 0)
10647c478bd9Sstevel@tonic-gate return (clock_t)(-1);
10657c478bd9Sstevel@tonic-gate if (epoch == 0)
10667c478bd9Sstevel@tonic-gate epoch = now.tv_sec;
10677c478bd9Sstevel@tonic-gate now.tv_sec -= epoch;
10687c478bd9Sstevel@tonic-gate return (scale60(&now));
10697c478bd9Sstevel@tonic-gate }
10707c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */
1071