utmp cleaner

David L. Crow crow at waterloo.austin.ibm.com
Sat Mar 30 01:59:22 AEST 1991


    This is the code that John Haugh posted to clean out the utmp file.
  I have changed it a little bit since he posted it, so it is not exactly
  the same.  I think that the only thing that I did was take out a while
  loop that encompassed the entire program and made it more like a daemon.
  As John says in the comment, this is public domain.  This is NOT an
  official program from IBM.


/*
 * this code is in the public domain.  do with it as you
 * please.  - jfh. 12/19/90
 */

#include <sys/types.h>
#include <utmp.h>
#include <fcntl.h>

main ()
{
    int    fd;
    struct    utmp    utmp;

    if ((fd = open ("/etc/utmp", O_RDWR)) < 0) {
        printf("Could not open /etc/utmp\n");
        exit (1);
    }

    while (read (fd, &utmp, sizeof utmp) == sizeof utmp) {
        if (utmp.ut_type != DEAD_PROCESS && kill (utmp.ut_pid, 0) != 0) {
            lseek (fd, - (long) sizeof utmp, 1);
            utmp.ut_type = DEAD_PROCESS;
            if ( write (fd, &utmp, sizeof utmp) != sizeof utmp ) {
                close(fd);
                printf("Could not write to /etc/utmp\n");
                exit(1);
            }
        }
    }
    close (fd);
}


-- 
 - This is only an exhibition, not a competition, so please....no wagering. -
 David Crow        (512) 823-4834    IBM VNET: dlcrow at austin
 AIX Systems Graphics Development    Internet: crow at waterloo.austin.ibm.com
 ------ Any opinions expressed are those of me and not of my employer. ------



More information about the Comp.unix.aix mailing list