utmp fix?

John F Haugh II jfh at rpp386.cactus.org
Sun Jun 2 14:23:54 AEST 1991


In article <1991May30.011132.28981 at magnus.acs.ohio-state.edu> mcover at magnus.acs.ohio-state.edu (Mark Coverdill) writes:
>   I typed in a program I saw about two weeks back to fix this
>problem but that had no effect and have been unable to locate it
>in various archives. Soooo, if someone would kindly repost the
>entire procedure on how to do this or tell me where I can ftp
>the procedure to cleanup the utmp file I would appreciate it.

This is a program that I use here to keep my utmp file clean.  I
posted it once before and someone at IBM brushed it up and made
it look pretty.  Here it is again ...
-- 
#include <sys/types.h>
#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 == USER_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        | Distribution to  | UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 255-8251 | GEnie PROHIBITED :-) |  Domain: jfh at rpp386.cactus.org
"If liberals interpreted the 2nd Amendment the same way they interpret the
 rest of the Constitution, gun ownership would be mandatory."



More information about the Comp.unix.aix mailing list