home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2365 < prev    next >
Internet Message Format  |  1990-12-28  |  1KB

  1. From: jfh@rpp386.cactus.org (John F Haugh II)
  2. Newsgroups: alt.sources
  3. Subject: utmp file cleaner upper
  4. Message-ID: <18844@rpp386.cactus.org>
  5. Date: 19 Dec 90 16:02:33 GMT
  6.  
  7.  
  8. I wrote this after getting disgusted with having old entries
  9. sitting around my utmp file, left over from pty login sessions.
  10. Once a minute it makes a sweep of the utmp file and makes
  11. sure all non-DEAD_PROCESS entries actually have processes
  12. associated with them.  It was easier than fixing init ...
  13. ---- utmpd.c ----
  14. /*
  15.  * this code is in the public domain.  do with it as you
  16.  * please.  - jfh. 12/19/90
  17.  */
  18.  
  19. #include <utmp.h>
  20. #include <fcntl.h>
  21.  
  22. main ()
  23. {
  24.     int    fd;
  25.     struct    utmp    utmp;
  26.  
  27.     while (1) {
  28.         if ((fd = open ("/etc/utmp", O_RDWR)) < 0)
  29.             exit (1);
  30.  
  31.         while (read (fd, &utmp, sizeof utmp) == sizeof utmp) {
  32.             if (utmp.ut_type != DEAD_PROCESS &&
  33.                     kill (utmp.ut_pid, 0) != 0) {
  34.                 lseek (fd, - (long) sizeof utmp, 1);
  35.                 utmp.ut_type = DEAD_PROCESS;
  36.                 write (fd, &utmp, sizeof utmp);
  37.             }
  38.         }
  39.         close (fd);
  40.         sleep (60);
  41.     }
  42. }
  43. -- 
  44. John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
  45. Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
  46. "While you are here, your wives and girlfriends are dating handsome American
  47.  movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."
  48.