home *** CD-ROM | disk | FTP | other *** search
- From: jfh@rpp386.cactus.org (John F Haugh II)
- Newsgroups: alt.sources
- Subject: utmp file cleaner upper
- Message-ID: <18844@rpp386.cactus.org>
- Date: 19 Dec 90 16:02:33 GMT
-
-
- 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@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."
-