aboutsummaryrefslogtreecommitdiff
path: root/toys/other/w.c
blob: 50f2283b99026937215260edc969144f64a5fe0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* vi: set sw=4 ts=4:
 *
 * w.c - shows logged in users
 *
 * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com>
 *
 * Not in SUSv4.

USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN))

config W
	bool "w"
	default y
	help
	  usage: w 

	  Show who is logged on and since how long they logged in.
*/

#include "toys.h"

void w_main(void)
{
    struct utmpx *x;

    xprintf("USER     TTY             LOGIN@              FROM");
    setutxent();
    while ((x=getutxent()) != NULL)
        if (x->ut_type==7) {
            time_t tt = x->ut_tv.tv_sec;

            xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
                ctime(&tt), x->ut_host);
        }
    xputc('\n');
}