acctcon.c revision 21d7f835c9bac5f9e80c72fc972ee5b288845983
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* acctcon [-l file] [-o file] <wtmpx-file
* -l file causes output of line usage summary
* list of sessions, sorted by ending time in tacct.h format
*/
#include <stdio.h>
#include "acctdef.h"
#include <ctype.h>
#include <time.h>
#include <utmpx.h>
#include <locale.h>
#include <string.h>
#include <search.h>
#include <stdlib.h>
static int csize;
struct tbuf {
int tlsess; /* # complete sessions */
int tlon; /* # times on (ut_type of 7) */
int tloff; /* # times off (ut_type != 7) */
long ttotal; /* total time used on this line */
} *tbuf;
struct ctab {
long ct_con[2];
} *pctab;
int nsys;
struct sys {
char snum; /* number of times encountered */
static char time_buf[50];
int ndates; /* number of times date changed */
int exitcode;
static int valid(void);
static void loop(void);
static void bootshut(void);
static int iline(void);
static void upall(void);
static void printrep(void);
static void printlin(void);
static int node_compare(const void *, const void *);
static void print_node(const void *, VISIT, int);
static void output(void);
extern char *optarg;
extern int optind;
int
{
int c;
switch (c) {
case 'l':
break;
case 'o':
break;
case '?':
"[-o reboot]\n", argv[0]);
exit(1);
}
exit(3);
}
/*
* XXX - fixme - need a good way of getting the fd that getutxent would
* use to access wtmpx, so we can convert this read of stdin to use
* the APIs and remove the dependence on the existence of the file.
*/
if (firstime == 0)
if (valid())
loop();
else
}
loop();
output();
printrep();
printlin();
}
/*
* valid: check input wtmpx record, return 1 if looks OK
*/
static int
valid()
{
int i, c;
/* XPG say that user names should not start with a "-" */
return (0);
for (i = 0; i < NSZ; i++) {
c == '_' || c == '-')
continue;
else if (c == '\0')
break;
else
return (0);
}
return (1);
return (0);
}
static void
{
exitcode = 1;
}
static void
loop()
{
int timediff;
return; /* no connect accounting data here */
case OLD_TIME:
return;
case NEW_TIME:
if (datetime == 0)
return;
datetime = 0;
ndates++;
return;
case DOWN_TIME:
return;
case BOOT_TIME:
upall();
case ACCOUNTING:
case RUN_LVL:
bootshut();
return;
case USER_PROCESS:
case LOGIN_PROCESS:
case INIT_PROCESS:
case DEAD_PROCESS: /* WHCC mod 3/86 */
return;
case EMPTY:
return;
default:
time_buf);
}
}
/*
* bootshut: record reboot (or shutdown)
* bump count, looking up wb.ut_line in sy table
*/
static void
bootshut()
{
int i;
;
if (i >= nsys) {
"acctcon: recompile with larger NSYS\n");
return;
}
}
}
/*
* (used to avoid system dependencies on naming)
*/
static int
iline()
{
int i;
for (i = 0; i <= tsize; i++)
return (i);
exit(2);
}
}
return (tsize);
}
static void
upall()
{
}
/*
* update tbuf with new time, write ctmp record for end of session
*/
static void
{
tnew; /* time of this record */
/* Difference is connect time */
exitcode = 1;
return;
}
case USER_PROCESS:
/*
* Someone logged in without logging off. Put out record.
*/
exit(1);
}
} else /* Someone just logged in */
break;
case DEAD_PROCESS:
/* Set up and print ctmp record */
exit(1);
}
}
}
}
static void
printrep()
{
int i;
if (ndates)
'\0'));
for (i = 0; i < nsys; i++)
}
/*
* print summary of line usage
* accuracy only guaranteed for wtmpx file started fresh
*/
static void
printlin()
{
double ttime;
ttime = 0.0;
printf("LINE MINUTES PERCENT # SESS # ON # OFF\n");
(int (*)(const void *, const void *))tcmp);
printf("%-*.*s %-7.0f %-7.0f %-6d %-4d %-5d\n",
}
printf("TOTALS %-7.0f -- %-6d %-4d %-5d\n",
}
static int
{
}
static int
{
return (1);
return (-1);
else
return (0);
}
static void
{
unsigned i;
int j;
exit(2);
}
node_compare)) == NULL) {
exit(1);
}
}
}
static void
{
}
}
static void
output()
{
}