Subject: Re: xterm

From: [email-masked] (John Caruso)
Date: 22 Apr 1994 10:27:14 -0400

I've had several requests for the utmp cleaning program, and since it's
so short I'll just go ahead and post it again here.  We've been using at
UMUC since it was originally posted a few weeks ago and it works great.
Just FYI, the updates it makes to utmp are automatically propagated to
utmpx as well--apparently this is built into the pututline() routine.

Maybe this should go into the Solaris FAQ?

-------------- cut here -------------------------------------------
/*
 *  TITLE:	cleanutmp
 *  SYNOPSIS:	eliminate entries from /var/adm/utmp for dead processes
 */

#include <sys/types.h>
#include <utmp.h>
#include <errno.h>
#include <time.h>

extern int errno;

main(int argc, char **argv)
{
  struct utmp *current;
  char *ent_time;

  while (current = getutent()) {
    if (current->ut_type == USER_PROCESS
	&& kill((pid_t) current->ut_pid, 0) == -1
	&& errno == ESRCH) {
      ent_time = asctime(localtime(&current->ut_time));
      printf("%-8.8s %-4.4s %-12.12s %5d %24.24s",
	     current->ut_user, current->ut_id,
	     current->ut_line, current->ut_pid, 
	     ent_time);
      current->ut_type = DEAD_PROCESS;
      current->ut_exit.e_termination = ~0;
      current->ut_exit.e_exit = ~0;
      current->ut_time = time(0);
      pututline(current);
      printf(" marked DEAD\n");
    }
  }
}
-------------- cut here -------------------------------------------

---------------------------------------------------------------------
 John Caruso                                    [email-masked]
 Unix/VMS System Administrator                  caruso@UMUC (Bitnet)
 University of Maryland University College      (301) 985-7447
---------------------------------------------------------------------