diff options
author | mckusick <mckusick@FreeBSD.org> | 2010-04-28 05:33:59 +0000 |
---|---|---|
committer | mckusick <mckusick@FreeBSD.org> | 2010-04-28 05:33:59 +0000 |
commit | 3a0f5972a0de87aebef1af257922515700da4217 (patch) | |
tree | a65d36ab57a1e076de7e7a1d78add642fbd7062e /usr.sbin/lastlogin | |
parent | f40c3a9dc50f808e512fcc9f9f738717013b483b (diff) | |
parent | a768cbcadec7189b9947e9f3cde39fe806bbc1d7 (diff) | |
download | FreeBSD-src-3a0f5972a0de87aebef1af257922515700da4217.zip FreeBSD-src-3a0f5972a0de87aebef1af257922515700da4217.tar.gz |
Update to current version of head.
Diffstat (limited to 'usr.sbin/lastlogin')
-rw-r--r-- | usr.sbin/lastlogin/lastlogin.8 | 2 | ||||
-rw-r--r-- | usr.sbin/lastlogin/lastlogin.c | 29 |
2 files changed, 26 insertions, 5 deletions
diff --git a/usr.sbin/lastlogin/lastlogin.8 b/usr.sbin/lastlogin/lastlogin.8 index 4d07a2b..0630163 100644 --- a/usr.sbin/lastlogin/lastlogin.8 +++ b/usr.sbin/lastlogin/lastlogin.8 @@ -55,7 +55,7 @@ If more than one is given, the session information for each user is printed in the order given on the command line. Otherwise, information -for all users is printed, sorted by uid. +for all users is printed, sorted by name. .Pp The .Nm diff --git a/usr.sbin/lastlogin/lastlogin.c b/usr.sbin/lastlogin/lastlogin.c index a1b5b6e..4c08547 100644 --- a/usr.sbin/lastlogin/lastlogin.c +++ b/usr.sbin/lastlogin/lastlogin.c @@ -39,6 +39,7 @@ __RCSID("$NetBSD: lastlogin.c,v 1.4 1998/02/03 04:45:35 perry Exp $"); #include <err.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> #include <utmpx.h> @@ -47,11 +48,19 @@ __RCSID("$NetBSD: lastlogin.c,v 1.4 1998/02/03 04:45:35 perry Exp $"); static void output(struct utmpx *); static void usage(void); +static int +utcmp(const void *u1, const void *u2) +{ + + return (strcmp(((const struct utmpx *)u1)->ut_user, + ((const struct utmpx *)u2)->ut_user)); +} + int main(int argc, char *argv[]) { - int ch, i; - struct utmpx *u; + int ch, i, ulistsize; + struct utmpx *u, *ulist; while ((ch = getopt(argc, argv, "")) != -1) { usage(); @@ -74,12 +83,24 @@ main(int argc, char *argv[]) else { if (setutxdb(UTXDB_LASTLOGIN, NULL) != 0) errx(1, "failed to open lastlog database"); + ulist = NULL; + ulistsize = 0; while ((u = getutxent()) != NULL) { if (u->ut_type != USER_PROCESS) continue; - output(u); + if ((ulistsize % 16) == 0) { + ulist = realloc(ulist, + (ulistsize + 16) * sizeof(struct utmpx)); + if (ulist == NULL) + err(1, "malloc"); + } + ulist[ulistsize++] = *u; } endutxent(); + + qsort(ulist, ulistsize, sizeof(struct utmpx), utcmp); + for (i = 0; i < ulistsize; i++) + output(&ulist[i]); } exit(0); @@ -91,7 +112,7 @@ output(struct utmpx *u) { time_t t = u->ut_tv.tv_sec; - printf("%-10s %-8s %-22s %s", + printf("%-10s %-8s %-22.22s %s", u->ut_user, u->ut_line, u->ut_host, ctime(&t)); } |