FreeBSD/usr.bin/last/last.c
/*
 * doentry --
 *	process a single utx.log entry
 */
doentry
process a single utx.log entry
doentry process a single utx . log entry
static void
doentry(struct utmpx *bp)
{
	struct idtab *tt;
	if (bp->ut_type == BOOT_TIME || bp->ut_type == SHUTDOWN_TIME) {
		while ((tt = SLIST_FIRST(&idlist)) != NULL) {
			SLIST_REMOVE_HEAD(&idlist, list);
			free(tt);
		}
		currentout = -bp->ut_tv.tv_sec;
		crmsg = bp->ut_type != SHUTDOWN_TIME ?
		    "crash" : "shutdown";
		if (snaptime && snapfound)
			exit(0);
		if (!snaptime && want(bp))
			printentry(bp, NULL);
		return;
	}
	if (bp->ut_type == OLD_TIME || bp->ut_type == NEW_TIME) {
		if (want(bp) && !snaptime)
			printentry(bp, NULL);
		return;
	}
	if (bp->ut_type != USER_PROCESS && bp->ut_type != DEAD_PROCESS)
		return;
	SLIST_FOREACH(tt, &idlist, list)
	    if (!memcmp(tt->id, bp->ut_id, sizeof bp->ut_id))
		    break;
	if (tt == NULL) {
		tt = malloc(sizeof(struct idtab));
		if (tt == NULL)
			errx(1, "malloc failure");
		tt->logout = currentout;
		memcpy(tt->id, bp->ut_id, sizeof bp->ut_id);
		SLIST_INSERT_HEAD(&idlist, tt, list);
	}
	if (bp->ut_type == USER_PROCESS && (want(bp) ||
	    (bp->ut_tv.tv_sec < snaptime &&
	    (tt->logout > snaptime || tt->logout < 1)))) {
		snapfound = 1;
		printentry(bp, tt);
	}
	tt->logout = bp->ut_tv.tv_sec;
}
static void doentry ( struct utmpx * bp ) { struct idtab * tt ; if ( bp -> ut_type == BOOT_TIME || bp -> ut_type == SHUTDOWN_TIME ) { while ( ( tt = SLIST_FIRST ( & idlist ) ) != NULL ) { SLIST_REMOVE_HEAD ( & idlist , list ) ; free ( tt ) ; } currentout = - bp -> ut_tv . tv_sec ; crmsg = bp -> ut_type != SHUTDOWN_TIME ? " " : " " ; if ( snaptime && snapfound ) exit ( 0 ) ; if ( ! snaptime && want ( bp ) ) printentry ( bp , NULL ) ; return ; } if ( bp -> ut_type == OLD_TIME || bp -> ut_type == NEW_TIME ) { if ( want ( bp ) && ! snaptime ) printentry ( bp , NULL ) ; return ; } if ( bp -> ut_type != USER_PROCESS && bp -> ut_type != DEAD_PROCESS ) return ; SLIST_FOREACH ( tt , & idlist , list ) if ( ! memcmp ( tt -> id , bp -> ut_id , sizeof bp -> ut_id ) ) break ; if ( tt == NULL ) { tt = malloc ( sizeof ( struct idtab ) ) ; if ( tt == NULL ) errx ( 1 , " " ) ; tt -> logout = currentout ; memcpy ( tt -> id , bp -> ut_id , sizeof bp -> ut_id ) ; SLIST_INSERT_HEAD ( & idlist , tt , list ) ; } if ( bp -> ut_type == USER_PROCESS && ( want ( bp ) || ( bp -> ut_tv . tv_sec < snaptime && ( tt -> logout > snaptime || tt -> logout < 1 ) ) ) ) { snapfound = 1 ; printentry ( bp , tt ) ; } tt -> logout = bp -> ut_tv . tv_sec ; }
doentry
      process a single utx.log entry
doentry process a single utx . log entry
/* the machine stopped */ /* everybody just logged out */ /*
		 * if we're in snapshot mode, we want to exit if this
		 * shutdown/reboot appears while we we are tracking the
		 * active range
		 */ /*
		 * don't print shutdown/reboot entries unless flagged for
		 */ /* date got set */ /* find associated identifier */ /* add new one */ /*
	 * print record if not in snapshot mode and wanted
	 * or in snapshot mode and in snapshot range
	 */