Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!romp!auschs!awdprime!longhorn.austin.ibm.com!crow From: crow@waterloo.austin.ibm.com (David L. Crow) Newsgroups: comp.unix.aix Subject: utmp cleaner Keywords: utmp clean AIX Version 3 Message-ID: <6257@awdprime.UUCP> Date: 29 Mar 91 15:59:22 GMT Sender: news@awdprime.UUCP Organization: IBM AWD, Austin Lines: 48 Originator: crow@longhorn.austin.ibm.com 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 #include #include 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@austin AIX Systems Graphics Development Internet: crow@waterloo.austin.ibm.com ------ Any opinions expressed are those of me and not of my employer. ------