home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp / 12569 < prev    next >
Encoding:
Text File  |  1992-11-05  |  2.1 KB  |  62 lines

  1. Xref: sparky comp.sys.hp:12569 comp.unix.questions:12941
  2. Newsgroups: comp.sys.hp,comp.unix.questions
  3. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!caen!sol.ctr.columbia.edu!ira.uka.de!rz.uni-karlsruhe.de!rz.uni-karlsruhe.de!chris
  4. From: chris@rz.uni-karlsruhe.de (Christian Finger)
  5. Subject: Re: Resetting the /etc/utmp, wtmp files after crashed logins
  6. Message-ID: <1992Nov5.143413.1956@rz.uni-karlsruhe.de>
  7. Sender: usenet@rz.uni-karlsruhe.de (USENET 'No news is bad news' News System)
  8. Reply-To: finger@rz.uni-karlsruhe.de
  9. Organization: Computer Center, University of Karlsruhe, Germany
  10. References:  <1992Nov3.013718.15982@murdoch.acc.Virginia.EDU>
  11. Date: Thu, 5 Nov 1992 14:34:13 GMT
  12. Lines: 48
  13.  
  14. In article <1992Nov3.013718.15982@murdoch.acc.Virginia.EDU>, prs9k@brain.med.virginia.edu (Phil Scarr) writes:
  15. | After a recent power failure, several PCs which were logged into our
  16. | HP9000 system crashed but their logins still show up with the w command.
  17. | There are no associated processes for these logins, they are just
  18. | phantoms.  Is there any way to reset these ptys?  I would assume you
  19. | could reset the /etc/utmp and wtmp files to do this, but I don't know
  20. | how.  Help!
  21. |     -Phil
  22.  
  23. The following program will do the job for you:
  24.  
  25. /*
  26.  * this code is in the public domain.  do with it as you
  27.  * please.  - jfh. 12/19/90
  28.  */
  29.  
  30. #include <sys/types.h>
  31. #include <utmp.h>
  32. #include <fcntl.h>
  33.  
  34. main ()
  35. {
  36.     int    fd;
  37.     struct    utmp    utmp;
  38.  
  39.     if ((fd = open ("/etc/utmp", O_RDWR)) < 0)
  40.         exit (1);
  41.  
  42.     while (read (fd, &utmp, sizeof utmp) == sizeof utmp) {
  43.         if (utmp.ut_type != DEAD_PROCESS &&
  44.                 kill (utmp.ut_pid, 0) != 0) {
  45.             lseek (fd, - (long) sizeof utmp, 1);
  46.             utmp.ut_type = DEAD_PROCESS;
  47.             write (fd, &utmp, sizeof utmp);
  48.         }
  49.     }
  50.     close (fd);
  51. }
  52.  
  53. Hope that helps,
  54.     -Christian
  55. -- 
  56.   .     Christian Finger         |  Tel   : (+49) 721/608-4038
  57.  |||    Computer Center          |  Fax   : (+49) 721/32550
  58. \|||    University of Karlsruhe  |  EMail : finger@rz.uni-karlsruhe.de
  59.     /   Postfach 6980            |  X.400 : S = finger; OU = rz
  60.         D-7500 Karlsruhe 1       |          P = uni-karlsruhe; A = dpb; C = de
  61.