annotate toys/posix/who.c @ 1775:57f2a26fa92c draft toast

To ensure that toybox can be installed alongside busybox without confusing update-alternatives, the paths of the links installed by toybox should match those installed by busybox. This is accomplished by changing the flags of a few tools within toybox.
author Paul Barker <paul@paulbarker.me.uk>
date Sat, 04 Apr 2015 11:58:06 -0500
parents 685a0da6ca59
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* who.c - display who is on the system
436
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 * Copyright 2012 ProFUSION Embedded Systems
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 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
6 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/who.html
825
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
8 *
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
9 * Posix says to support many options (-abdHlmpqrstTu) but this
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
10 * isn't aimed at minicomputers with modem pools.
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
11
1775
57f2a26fa92c To ensure that toybox can be installed alongside busybox without
Paul Barker <paul@paulbarker.me.uk>
parents: 1564
diff changeset
12 USE_WHO(NEWTOY(who, "a", TOYFLAG_USR|TOYFLAG_BIN))
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
13
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
14 config WHO
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
15 bool "who"
825
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
16 default y
1564
685a0da6ca59 probe for getspnam(), forkpty(), utmpx, replace sethostname()
Isaac Dunham <ibid.ag@gmail.com>
parents: 825
diff changeset
17 depends on TOYBOX_UTMPX
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
18 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
19 usage: who
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
20
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
21 Print logged user information on system
436
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
825
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
24 #define FOR_who
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
25 #include "toys.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 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
29 struct utmpx *entry;
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
30
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
31 setutxent();
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
32
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
33 while ((entry = getutxent())) {
825
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
34 if ((toys.optflags & FLAG_a) || entry->ut_type == USER_PROCESS) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
35 time_t time;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
36 int time_size;
825
53f165466f3b Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
37 char *times;
437
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
38
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
39 time = entry->ut_tv.tv_sec;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
40 times = ctime(&time);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
41 time_size = strlen(times) - 2;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
42 printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line,
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
43 time_size, time_size, ctime(&time), entry->ut_host);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
44 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
45 }
437
2d19539c3aeb Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents: 436
diff changeset
46
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
47 endutxent();
436
bc347fc87b00 Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff changeset
48 }