Mercurial > hg > toybox
annotate toys/who.c @ 437:2d19539c3aeb
Added time to the output of who command.
author | Luis Felipe Strano Moraes <lfelipe@profusion.mobi> |
---|---|
date | Tue, 07 Feb 2012 09:15:17 -0800 |
parents | bc347fc87b00 |
children | a2f530c4c442 |
rev | line source |
---|---|
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
2 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
3 * who.c - display who is on the system |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
4 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
5 * Copyright 2012 ProFUSION Embedded Systems |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
6 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
7 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi> |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
8 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
9 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/who.html |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
10 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
11 USE_WHO(NEWTOY(who, NULL, TOYFLAG_BIN)) |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
12 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
13 config WHO |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
14 bool "who" |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
15 default y |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
16 help |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
17 usage: who |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
18 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
19 Print logged user information on system |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
20 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
21 */ |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
22 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
23 #include "toys.h" |
437
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
24 #include <time.h> |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
25 #include <utmpx.h> |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
26 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
27 void who_main(void) |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
28 { |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
29 struct utmpx *entry; |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
30 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
31 setutxent(); |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
32 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
33 while ((entry = getutxent())) { |
437
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
34 if (entry->ut_type == USER_PROCESS) { |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
35 time_t time; |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
36 int time_size; |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
37 char * times; |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
38 |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
39 time = entry->ut_tv.tv_sec; |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
40 times = ctime(&time); |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
41 time_size = strlen(times) - 2; |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
42 printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line, time_size, time_size, ctime(&time), entry->ut_host); |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
43 |
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
44 } |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
45 } |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
46 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
47 endutxent(); |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
48 } |