v3 of the who(1) patchset.
>From 5ee1ca2d61d351d7059d27eba124b68adb957e18 Mon Sep 17 00:00:00 2001 From: sin <s...@2f30.org> Date: Mon, 5 Aug 2013 15:59:49 +0100 Subject: [PATCH 1/3] Implement -m for who
--- who.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/who.c b/who.c index ae969d6..756363e 100644 --- a/who.c +++ b/who.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdbool.h> #include <unistd.h> #include <time.h> #include <utmp.h> @@ -15,8 +16,17 @@ main(int argc, char **argv) FILE *ufp; time_t t; char timebuf[sizeof "yyyy-mm-dd hh:mm"]; + bool mflag = false; - if(argc!=1) + ARGBEGIN { + case 'm': + mflag = true; + break; + default: + usage(); + } ARGEND; + + if (argc > 0) usage(); if (!(ufp = fopen(_PATH_UTMP, "r"))) { @@ -25,6 +35,9 @@ main(int argc, char **argv) while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) { if (!*usr.ut_name || !*usr.ut_line) continue; + if (mflag && strcmp(usr.ut_line, + strrchr(ttyname(STDIN_FILENO), '/') + 1)) + continue; t = usr.ut_time; strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", localtime(&t)); printf("%-8s %-12s %-16s\n", usr.ut_name, usr.ut_line, timebuf); @@ -36,6 +49,5 @@ main(int argc, char **argv) void usage(void) { - eprintf("usage: who\n"); + eprintf("usage: who [-m]\n"); } - -- 1.8.3.4
>From b79fa641dce58c6efbd909851994198c65a99725 Mon Sep 17 00:00:00 2001 From: sin <s...@2f30.org> Date: Mon, 5 Aug 2013 16:04:49 +0100 Subject: [PATCH 2/3] No need to cast to (char *) --- who.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/who.c b/who.c index 756363e..823142b 100644 --- a/who.c +++ b/who.c @@ -32,7 +32,7 @@ main(int argc, char **argv) if (!(ufp = fopen(_PATH_UTMP, "r"))) { eprintf("fopen:"); } - while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) { + while(fread(&usr, sizeof(usr), 1, ufp) == 1) { if (!*usr.ut_name || !*usr.ut_line) continue; if (mflag && strcmp(usr.ut_line, -- 1.8.3.4
>From a6fad7366977b7a1b6cc0f8de538abb720465133 Mon Sep 17 00:00:00 2001 From: sin <s...@2f30.org> Date: Mon, 5 Aug 2013 16:12:01 +0100 Subject: [PATCH 3/3] Ignore tilde in ut_line --- who.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/who.c b/who.c index 823142b..6093a84 100644 --- a/who.c +++ b/who.c @@ -33,7 +33,8 @@ main(int argc, char **argv) eprintf("fopen:"); } while(fread(&usr, sizeof(usr), 1, ufp) == 1) { - if (!*usr.ut_name || !*usr.ut_line) + if (!*usr.ut_name || !*usr.ut_line || + usr.ut_line[0] == '~') continue; if (mflag && strcmp(usr.ut_line, strrchr(ttyname(STDIN_FILENO), '/') + 1)) -- 1.8.3.4