home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.hp:12569 comp.unix.questions:12941
- Newsgroups: comp.sys.hp,comp.unix.questions
- 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
- From: chris@rz.uni-karlsruhe.de (Christian Finger)
- Subject: Re: Resetting the /etc/utmp, wtmp files after crashed logins
- Message-ID: <1992Nov5.143413.1956@rz.uni-karlsruhe.de>
- Sender: usenet@rz.uni-karlsruhe.de (USENET 'No news is bad news' News System)
- Reply-To: finger@rz.uni-karlsruhe.de
- Organization: Computer Center, University of Karlsruhe, Germany
- References: <1992Nov3.013718.15982@murdoch.acc.Virginia.EDU>
- Date: Thu, 5 Nov 1992 14:34:13 GMT
- Lines: 48
-
- In article <1992Nov3.013718.15982@murdoch.acc.Virginia.EDU>, prs9k@brain.med.virginia.edu (Phil Scarr) writes:
- | After a recent power failure, several PCs which were logged into our
- | HP9000 system crashed but their logins still show up with the w command.
- | There are no associated processes for these logins, they are just
- | phantoms. Is there any way to reset these ptys? I would assume you
- | could reset the /etc/utmp and wtmp files to do this, but I don't know
- | how. Help!
- |
- | -Phil
-
- The following program will do the job for you:
-
- /*
- * this code is in the public domain. do with it as you
- * please. - jfh. 12/19/90
- */
-
- #include <sys/types.h>
- #include <utmp.h>
- #include <fcntl.h>
-
- main ()
- {
- int fd;
- struct utmp utmp;
-
- 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);
- }
-
- Hope that helps,
- -Christian
- --
- . Christian Finger | Tel : (+49) 721/608-4038
- ||| Computer Center | Fax : (+49) 721/32550
- \||| University of Karlsruhe | EMail : finger@rz.uni-karlsruhe.de
- / Postfach 6980 | X.400 : S = finger; OU = rz
- D-7500 Karlsruhe 1 | P = uni-karlsruhe; A = dpb; C = de
-