annotate toys/who.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents 31215cc6c9f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
438
a2f530c4c442 Switching who default to 'n' since it's not yet fully implemented.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 437
diff changeset
15 default n
436
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"
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
24
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
25 void who_main(void)
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 struct utmpx *entry;
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 setutxent();
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 while ((entry = getutxent())) {
437
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
32 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
33 time_t time;
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
34 int time_size;
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
35 char * times;
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
36
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
37 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
38 times = ctime(&time);
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
39 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
40 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
41
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
42 }
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
43 }
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
44
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
45 endutxent();
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
46 }