/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
#ident	"$Header: closewtmp.c,v 1.4.2.1 92/06/24 13:26:02 marker Exp $"
#ifndef lint
static char * _Sccs_Id_closewtmp_c = "@(#)closewtmp.c   1.2 2/21/90 - DR";
#endif !lint

/*      fludge an entry to wtmp for each user who is still logs on when
 *      acct is being run. This entry marks a DEAD_PROCESS, and the
 *      current time as time stamp. This should be done before connect
 *      time is processed. Call by runacct.
 */

#include <stdio.h>
#include <sys/types.h>
#include <utmpx.h>

main()
{
        struct utmp *getutent(), *utmp;
        struct utmpx *getutxent(), *utmpx;
        FILE *fp;

        fp = fopen(WTMPX_FILE, "r+");
        while ((utmpx=getutxent()) != NULL) {
                if (utmpx->ut_type == USER_PROCESS) {
                        utmpx->ut_type = DEAD_PROCESS;
                        time( &utmpx->ut_xtime );
                        fseek(fp,0L,2);
                        fwrite( utmpx, sizeof(*utmpx), 1, fp);
                }
        }
        fclose(fp);

        fp = fopen(WTMP_FILE, "r+");
        while ((utmp=getutent()) != NULL) {
                if (utmp->ut_type == USER_PROCESS) {
                        utmp->ut_type = DEAD_PROCESS;
                        time( &utmp->ut_time );
                        fseek(fp,0L,2);
                        fwrite( utmp, sizeof(*utmp), 1, fp);
                }
        }
        fclose(fp);
}
