Date: Sun, 10 Jan 2010 18:00:45 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r202021 - user/ed/utmpx/usr.bin/last Message-ID: <201001101800.o0AI0jcp098989@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Sun Jan 10 18:00:45 2010 New Revision: 202021 URL: http://svn.freebsd.org/changeset/base/202021 Log: Make last(1) work a lot better. I think it should work properly now. Modified: user/ed/utmpx/usr.bin/last/last.c Modified: user/ed/utmpx/usr.bin/last/last.c ============================================================================== --- user/ed/utmpx/usr.bin/last/last.c Sun Jan 10 17:45:47 2010 (r202020) +++ user/ed/utmpx/usr.bin/last/last.c Sun Jan 10 18:00:45 2010 (r202021) @@ -76,12 +76,12 @@ typedef struct arg { } ARG; ARG *arglist; /* head of linked list */ -LIST_HEAD(ttylisthead, ttytab) ttylist; +LIST_HEAD(idlisthead, idtab) idlist; -struct ttytab { +struct idtab { time_t logout; /* log out time */ - char tty[sizeof ((struct utmpx *)0)->ut_line]; /* terminal name */ - LIST_ENTRY(ttytab) list; + char id[sizeof ((struct utmpx *)0)->ut_id]; /* identifier */ + LIST_ENTRY(idtab) list; }; static const char *crmsg; /* cause of last reboot */ @@ -102,7 +102,7 @@ void addarg(int, char *); time_t dateconv(char *); void doentry(struct utmpx *); void hostconv(char *); -void printentry(struct utmpx *, struct ttytab *); +void printentry(struct utmpx *, struct idtab *); char *ttyconv(char *); int want(struct utmpx *); void usage(void); @@ -212,7 +212,7 @@ wtmp(void) char ct[80]; struct tm *tm; - LIST_INIT(&ttylist); + LIST_INIT(&idlist); (void)time(&t); /* Load the last entries from the file. */ @@ -245,22 +245,19 @@ wtmp(void) void doentry(struct utmpx *bp) { - struct ttytab *tt, *ttx; /* ttylist entry */ + struct idtab *tt, *ttx; /* idlist entry */ - /* - * if the terminal line is '~', the machine stopped. - * see utmp(5) for more info. - */ - if (bp->ut_line[0] == '~' && !bp->ut_line[1]) { + /* the machine stopped */ + if (bp->ut_type == BOOT_TIME || bp->ut_type == SHUTDOWN_TIME) { /* everybody just logged out */ - for (tt = LIST_FIRST(&ttylist); tt;) { + for (tt = LIST_FIRST(&idlist); tt;) { LIST_REMOVE(tt, list); ttx = tt; tt = LIST_NEXT(tt, list); free(ttx); } currentout = -bp->ut_tv.tv_sec; - crmsg = strcmp(bp->ut_user, "shutdown") ? + crmsg = bp->ut_type != SHUTDOWN_TIME ? "crash" : "shutdown"; /* * if we're in snapshot mode, we want to exit if this @@ -276,47 +273,39 @@ doentry(struct utmpx *bp) printentry(bp, NULL); return; } - /* - * if the line is '{' or '|', date got set; see - * utmp(5) for more info. - */ - if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && - !bp->ut_line[1]) { + /* date got set */ + if (bp->ut_type == OLD_TIME || bp->ut_type == NEW_TIME) { if (want(bp) && !snaptime) printentry(bp, NULL); return; } - /* find associated tty */ - LIST_FOREACH(tt, &ttylist, list) - if (!strcmp(tt->tty, bp->ut_line)) + + if (bp->ut_type != USER_PROCESS && bp->ut_type != DEAD_PROCESS) + return; + + /* find associated identifier */ + LIST_FOREACH(tt, &idlist, list) + if (!memcmp(tt->id, bp->ut_id, sizeof bp->ut_id)) break; if (tt == NULL) { /* add new one */ - tt = malloc(sizeof(struct ttytab)); + tt = malloc(sizeof(struct idtab)); if (tt == NULL) errx(1, "malloc failure"); tt->logout = currentout; - strcpy(tt->tty, bp->ut_line); - LIST_INSERT_HEAD(&ttylist, tt, list); + memcpy(tt->id, bp->ut_id, sizeof bp->ut_id); + LIST_INSERT_HEAD(&idlist, tt, list); } /* * print record if not in snapshot mode and wanted * or in snapshot mode and in snapshot range */ - if (bp->ut_user[0] && (want(bp) || (bp->ut_tv.tv_sec < snaptime && + if (bp->ut_type == USER_PROCESS && (want(bp) || + (bp->ut_tv.tv_sec < snaptime && (tt->logout > snaptime || tt->logout < 1)))) { snapfound = 1; - /* - * when uucp and ftp log in over a network, the entry in - * the utmp file is the name plus their process id. See - * etc/ftpd.c and usr.bin/uucp/uucpd.c for more information. - */ - if (!strncmp(bp->ut_line, "ftp", sizeof("ftp") - 1)) - bp->ut_line[3] = '\0'; - else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1)) - bp->ut_line[4] = '\0'; printentry(bp, tt); } tt->logout = bp->ut_tv.tv_sec; @@ -330,7 +319,7 @@ doentry(struct utmpx *bp) * logout type (crash/shutdown) as appropriate. */ void -printentry(struct utmpx *bp, struct ttytab *tt) +printentry(struct utmpx *bp, struct idtab *tt) { char ct[80]; struct tm *tm;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001101800.o0AI0jcp098989>