Adding who, chroot, env and split.

Thanks "Galos, David" <galosd83@students.rowan.edu>!
This commit is contained in:
Christoph Lohmann
2013-06-14 18:55:25 +02:00
parent b0898c605d
commit 9df408f8c6
10 changed files with 410 additions and 4 deletions

37
who.c Normal file
View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <utmpx.h>
#include "util.h"
static void usage(void);
int
main(int argc, char **argv)
{
struct utmpx *ut;
time_t t;
char timebuf[sizeof "yyyy-mm-dd hh:mm"];
if(argc!=1)
usage();
while((ut=getutxent())) {
if(ut->ut_type != USER_PROCESS)
continue;
t = ut->ut_tv.tv_sec;
strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", localtime(&t));
printf("%-8s %-12s %-16s\n", ut->ut_user, ut->ut_line, timebuf);
}
endutxent();
return 0;
}
void
usage(void)
{
eprintf("usage: who\n");
}