13125Sdg/* 23125Sdg * Copyright (c) 1994 Christopher G. Demetriou 33125Sdg * All rights reserved. 43125Sdg * 53125Sdg * Redistribution and use in source and binary forms, with or without 63125Sdg * modification, are permitted provided that the following conditions 73125Sdg * are met: 83125Sdg * 1. Redistributions of source code must retain the above copyright 93125Sdg * notice, this list of conditions and the following disclaimer. 103125Sdg * 2. Redistributions in binary form must reproduce the above copyright 113125Sdg * notice, this list of conditions and the following disclaimer in the 123125Sdg * documentation and/or other materials provided with the distribution. 133125Sdg * 3. All advertising materials mentioning features or use of this software 143125Sdg * must display the following acknowledgement: 153125Sdg * This product includes software developed by Christopher G. Demetriou. 163125Sdg * 4. The name of the author may not be used to endorse or promote products 173125Sdg * derived from this software without specific prior written permission 183125Sdg * 193125Sdg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 203125Sdg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 213125Sdg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 223125Sdg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 233125Sdg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 243125Sdg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 253125Sdg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 263125Sdg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 273125Sdg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 283125Sdg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 293125Sdg * 3050479Speter * $FreeBSD$ 313125Sdg */ 323125Sdg 333125Sdg#include <sys/types.h> 343125Sdg#include <sys/param.h> 353125Sdg#include <db.h> 363125Sdg 373125Sdg/* structures */ 383125Sdg 39169857Sdds/* All times are stored in 1e-6s units. */ 40169857Sdds 413125Sdgstruct cmdinfo { 423125Sdg char ci_comm[MAXCOMLEN+2]; /* command name (+ '*') */ 43169857Sdds uid_t ci_uid; /* user id */ 443125Sdg u_quad_t ci_calls; /* number of calls */ 45169857Sdds double ci_etime; /* elapsed time */ 46169857Sdds double ci_utime; /* user time */ 47169857Sdds double ci_stime; /* system time */ 48169857Sdds double ci_mem; /* memory use */ 49169857Sdds double ci_io; /* number of disk i/o ops */ 503125Sdg u_int ci_flags; /* flags; see below */ 513125Sdg}; 523125Sdg#define CI_UNPRINTABLE 0x0001 /* unprintable chars in name */ 533125Sdg 543125Sdgstruct userinfo { 55169857Sdds uid_t ui_uid; /* user id; for consistency */ 563125Sdg u_quad_t ui_calls; /* number of invocations */ 57169857Sdds double ui_utime; /* user time */ 58169857Sdds double ui_stime; /* system time */ 59169857Sdds double ui_mem; /* memory use */ 60169857Sdds double ui_io; /* number of disk i/o ops */ 613125Sdg}; 623125Sdg 633125Sdg/* typedefs */ 643125Sdg 6599829Salfredtypedef int (*cmpf_t)(const DBT *, const DBT *); 663125Sdg 67169857Sdds/* external functions in db.c */ 68169857Sddsint db_copy_in(DB **mdb, const char *dbname, const char *name, 69169857Sdds BTREEINFO *bti, int (*v1_to_v2)(DBT *key, DBT *data)); 70169857Sddsint db_copy_out(DB *mdb, const char *dbname, const char *name, 71169857Sdds BTREEINFO *bti); 72169857Sddsvoid db_destroy(DB *db, const char *uname); 73169857Sdds 743125Sdg/* external functions in pdb.c */ 7599829Salfredint pacct_init(void); 7699829Salfredvoid pacct_destroy(void); 7799829Salfredint pacct_add(const struct cmdinfo *); 7899829Salfredint pacct_update(void); 7999829Salfredvoid pacct_print(void); 803125Sdg 81169857Sdds/* external functions in readrec.c */ 82169857Sddsint readrec_forward(FILE *f, struct acctv2 *av2); 83169857Sdds 843125Sdg/* external functions in usrdb.c */ 8599829Salfredint usracct_init(void); 8699829Salfredvoid usracct_destroy(void); 8799829Salfredint usracct_add(const struct cmdinfo *); 8899829Salfredint usracct_update(void); 8999829Salfredvoid usracct_print(void); 903125Sdg 913125Sdg/* variables */ 923125Sdg 933125Sdgextern int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; 943125Sdgextern int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; 9599829Salfredextern u_quad_t cutoff; 963125Sdgextern cmpf_t sa_cmp; 97169670Sddsextern const char *pdb_file, *usrdb_file; 983125Sdg 993125Sdg/* some #defines to help with db's stupidity */ 1003125Sdg 1013125Sdg#define DB_CLOSE(db) \ 1023125Sdg ((*(db)->close)(db)) 1033125Sdg#define DB_GET(db, key, data, flags) \ 1043125Sdg ((*(db)->get)((db), (key), (data), (flags))) 1053125Sdg#define DB_PUT(db, key, data, flags) \ 1063125Sdg ((*(db)->put)((db), (key), (data), (flags))) 1073125Sdg#define DB_SYNC(db, flags) \ 1083125Sdg ((*(db)->sync)((db), (flags))) 1093125Sdg#define DB_SEQ(db, key, data, flags) \ 1103125Sdg ((*(db)->seq)((db), (key), (data), (flags))) 111