From 74ec67b827826c2ea64786274edba174c145c2de Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Tue, 30 Dec 2014 11:43:12 +0000 Subject: [PATCH] utils: Add who from ELKS --- Applications/util/Makefile | 1 + Applications/util/who.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Applications/util/who.c diff --git a/Applications/util/Makefile b/Applications/util/Makefile index c71caf00..af2158fd 100644 --- a/Applications/util/Makefile +++ b/Applications/util/Makefile @@ -88,6 +88,7 @@ SRCS = banner.c \ uue.c \ wc.c \ which.c \ + who.c \ whoami.c \ write.c \ xargs.c \ diff --git a/Applications/util/who.c b/Applications/util/who.c new file mode 100644 index 00000000..e97a75af --- /dev/null +++ b/Applications/util/who.c @@ -0,0 +1,42 @@ +/* + * who.c + * + * Copyright 1998 Alistair Riddoch + * ajr@ecs.soton.ac.uk + * + * This file may be distributed under the terms of the GNU General Public + * License v2, or at your option any later version. + */ + +/* + * This is a small version of who for use in the ELKS project. + * It is not fully functional, and may not be the most efficient + * implementation for larger systems. It minimises memory usage and + * code size. + */ + + +#include +#include +#include +#include +#include + +void main(int argc, char *argv[]) +{ + register struct utmp * entry; + char * timestr; + + setutent(); + while ((entry = getutent()) != NULL) + if (entry->ut_type == USER_PROCESS) { + timestr = ctime(&entry->ut_time); + timestr[strlen(timestr) - 1] = '\0'; + printf("%s tty%c%c %s %s\n", entry->ut_user, + entry->ut_id[0], + entry->ut_id[1] ? entry->ut_id[1] : 0, + timestr, + entry->ut_host); + } + exit(0); +} -- 2.34.1