utmp file cleaner upper

John F Haugh II jfh at rpp386.cactus.org
Thu Dec 20 03:02:33 AEST 1990


I wrote this after getting disgusted with having old entries
sitting around my utmp file, left over from pty login sessions.
Once a minute it makes a sweep of the utmp file and makes
sure all non-DEAD_PROCESS entries actually have processes
associated with them.  It was easier than fixing init ...
---- utmpd.c ----
/*
 * this code is in the public domain.  do with it as you
 * please.  - jfh. 12/19/90
 */

#include <utmp.h>
#include <fcntl.h>

main ()
{
	int	fd;
	struct	utmp	utmp;

	while (1) {
		if ((fd = open ("/etc/utmp", O_RDWR)) < 0)
			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;
				write (fd, &utmp, sizeof utmp);
			}
		}
		close (fd);
		sleep (60);
	}
}
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh at rpp386.cactus.org
"While you are here, your wives and girlfriends are dating handsome American
 movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."



More information about the Alt.sources mailing list