diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-08-08 22:26:06 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-08-08 22:26:06 +0000 |
commit | 2e9c25700061b23982f8600288178c1f6a370c1e (patch) | |
tree | b9523c8010e85f5879a89e2a4b7e202d674e1e1c | |
parent | f1c56a9306680874577abf01749c4b33877eb89a (diff) | |
download | busybox-w32-2e9c25700061b23982f8600288178c1f6a370c1e.tar.gz busybox-w32-2e9c25700061b23982f8600288178c1f6a370c1e.tar.bz2 busybox-w32-2e9c25700061b23982f8600288178c1f6a370c1e.zip |
Implement a minimalist 'last' which allows the LEAF project to
no longer need dumtp. Remove the 'dumtp' applet.
-Erik
-rw-r--r-- | include/applets.h | 6 | ||||
-rw-r--r-- | include/usage.h | 22 | ||||
-rw-r--r-- | miscutils/Config.in | 10 | ||||
-rw-r--r-- | miscutils/Makefile.in | 2 | ||||
-rw-r--r-- | miscutils/dutmp.c | 66 | ||||
-rw-r--r-- | miscutils/last.c | 107 |
6 files changed, 120 insertions, 93 deletions
diff --git a/include/applets.h b/include/applets.h index 2ee816465..cd5065103 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -169,9 +169,6 @@ | |||
169 | #ifdef CONFIG_DUMPLEASES | 169 | #ifdef CONFIG_DUMPLEASES |
170 | APPLET(dumpleases, dumpleases_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) | 170 | APPLET(dumpleases, dumpleases_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) |
171 | #endif | 171 | #endif |
172 | #ifdef CONFIG_DUTMP | ||
173 | APPLET(dutmp, dutmp_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) | ||
174 | #endif | ||
175 | #ifdef CONFIG_ECHO | 172 | #ifdef CONFIG_ECHO |
176 | APPLET(echo, echo_main, _BB_DIR_BIN, _BB_SUID_NEVER) | 173 | APPLET(echo, echo_main, _BB_DIR_BIN, _BB_SUID_NEVER) |
177 | #endif | 174 | #endif |
@@ -316,6 +313,9 @@ | |||
316 | #ifdef CONFIG_LASH | 313 | #ifdef CONFIG_LASH |
317 | APPLET(lash, lash_main, _BB_DIR_BIN, _BB_SUID_NEVER) | 314 | APPLET(lash, lash_main, _BB_DIR_BIN, _BB_SUID_NEVER) |
318 | #endif | 315 | #endif |
316 | #ifdef CONFIG_LAST | ||
317 | APPLET(last, last_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) | ||
318 | #endif | ||
319 | #ifdef CONFIG_LENGTH | 319 | #ifdef CONFIG_LENGTH |
320 | APPLET(length, length_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) | 320 | APPLET(length, length_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) |
321 | #endif | 321 | #endif |
diff --git a/include/usage.h b/include/usage.h index 7bf9c8952..35a3d5033 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -461,21 +461,6 @@ | |||
461 | "\t-r,\t--remaining\tInterepret lease times as time remaing\n" \ | 461 | "\t-r,\t--remaining\tInterepret lease times as time remaing\n" \ |
462 | "\t-a,\t--absolute\tInterepret lease times as expire time\n" | 462 | "\t-a,\t--absolute\tInterepret lease times as expire time\n" |
463 | 463 | ||
464 | #define dutmp_trivial_usage \ | ||
465 | "[FILE]" | ||
466 | #define dutmp_full_usage \ | ||
467 | "Dump utmp file format (pipe delimited) from FILE\n" \ | ||
468 | "or stdin to stdout. (i.e., 'dutmp /var/run/utmp')" | ||
469 | #define dutmp_example_usage \ | ||
470 | "$ dutmp /var/run/utmp\n" \ | ||
471 | "8|7||si|||0|0|0|955637625|760097|0\n" \ | ||
472 | "2|0|~|~~|reboot||0|0|0|955637625|782235|0\n" \ | ||
473 | "1|20020|~|~~|runlevel||0|0|0|955637625|800089|0\n" \ | ||
474 | "8|125||l4|||0|0|0|955637629|998367|0\n" \ | ||
475 | "6|245|tty1|1|LOGIN||0|0|0|955637630|998974|0\n" \ | ||
476 | "6|246|tty2|2|LOGIN||0|0|0|955637630|999498|0\n" \ | ||
477 | "7|336|pts/0|vt00|andersen|:0.0|0|0|0|955637763|0|0\n" | ||
478 | |||
479 | #ifdef CONFIG_FEATURE_FANCY_ECHO | 464 | #ifdef CONFIG_FEATURE_FANCY_ECHO |
480 | #define USAGE_FANCY_ECHO(a) a | 465 | #define USAGE_FANCY_ECHO(a) a |
481 | #else | 466 | #else |
@@ -2068,7 +2053,7 @@ | |||
2068 | "[FILE]...\n" \ | 2053 | "[FILE]...\n" \ |
2069 | "or: sh -c command [args]..." | 2054 | "or: sh -c command [args]..." |
2070 | #define lash_full_usage \ | 2055 | #define lash_full_usage \ |
2071 | "lash: The BusyBox LAme SHell (command interpreter)" | 2056 | "The BusyBox LAme SHell (command interpreter)" |
2072 | #define lash_notes_usage \ | 2057 | #define lash_notes_usage \ |
2073 | "This command does not yet have proper documentation.\n" \ | 2058 | "This command does not yet have proper documentation.\n" \ |
2074 | "\n" \ | 2059 | "\n" \ |
@@ -2079,6 +2064,11 @@ | |||
2079 | "use ash or bash. If you just need a very simple and extremely small shell,\n" \ | 2064 | "use ash or bash. If you just need a very simple and extremely small shell,\n" \ |
2080 | "this will do the job." | 2065 | "this will do the job." |
2081 | 2066 | ||
2067 | #define last_trivial_usage \ | ||
2068 | "" | ||
2069 | #define last_full_usage \ | ||
2070 | "Shows listing of the last users that logged into the system" | ||
2071 | |||
2082 | #define sha1sum_trivial_usage \ | 2072 | #define sha1sum_trivial_usage \ |
2083 | "[OPTION] [FILE]" | 2073 | "[OPTION] [FILE]" |
2084 | #define sha1sum_full_usage \ | 2074 | #define sha1sum_full_usage \ |
diff --git a/miscutils/Config.in b/miscutils/Config.in index a994c5096..701af9c2d 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -40,15 +40,11 @@ config CONFIG_DC | |||
40 | Dc is a reverse-polish desk calculator which supports unlimited | 40 | Dc is a reverse-polish desk calculator which supports unlimited |
41 | precision arithmetic. | 41 | precision arithmetic. |
42 | 42 | ||
43 | config CONFIG_DUTMP | 43 | config CONFIG_LAST |
44 | bool "dutmp" | 44 | bool "last" |
45 | default n | 45 | default n |
46 | help | 46 | help |
47 | 'dutmp' is a utility used by the Linux Router Project (as far as I | 47 | 'last' displays a list of the last users that logged into the system. |
48 | know nobody else uses it). It dumps the contents of the utmp file to | ||
49 | STDOUT with each field seperated by a colon. IP addresses are are | ||
50 | given in hex in native byte order. It is intended that this format | ||
51 | can then be parsed by shell scripts. | ||
52 | 48 | ||
53 | config CONFIG_HDPARM | 49 | config CONFIG_HDPARM |
54 | bool "hdparm" | 50 | bool "hdparm" |
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in index 0f200f4fb..66370f015 100644 --- a/miscutils/Makefile.in +++ b/miscutils/Makefile.in | |||
@@ -28,8 +28,8 @@ MISCUTILS-$(CONFIG_ADJTIMEX) += adjtimex.o | |||
28 | MISCUTILS-$(CONFIG_CROND) += crond.o | 28 | MISCUTILS-$(CONFIG_CROND) += crond.o |
29 | MISCUTILS-$(CONFIG_CRONTAB) += crontab.o | 29 | MISCUTILS-$(CONFIG_CRONTAB) += crontab.o |
30 | MISCUTILS-$(CONFIG_DC) += dc.o | 30 | MISCUTILS-$(CONFIG_DC) += dc.o |
31 | MISCUTILS-$(CONFIG_DUTMP) += dutmp.o | ||
32 | MISCUTILS-$(CONFIG_HDPARM) += hdparm.o | 31 | MISCUTILS-$(CONFIG_HDPARM) += hdparm.o |
32 | MISCUTILS-$(CONFIG_LAST) += last.o | ||
33 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o | 33 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o |
34 | MISCUTILS-$(CONFIG_MT) += mt.o | 34 | MISCUTILS-$(CONFIG_MT) += mt.o |
35 | MISCUTILS-$(CONFIG_STRINGS) += strings.o | 35 | MISCUTILS-$(CONFIG_STRINGS) += strings.o |
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c deleted file mode 100644 index 86d7ce4b3..000000000 --- a/miscutils/dutmp.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
4 | * | ||
5 | * dutmp | ||
6 | * Takes utmp formated file on stdin and dumps it's contents | ||
7 | * out in colon delimited fields. Easy to 'cut' for shell based | ||
8 | * versions of 'who', 'last', etc. IP Addr is output in hex, | ||
9 | * little endian on x86. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | /* Mar 13, 2003 Manuel Novoa III | ||
14 | * | ||
15 | * 1) Added proper error checking. | ||
16 | * 2) Allow '-' arg for stdin. | ||
17 | * 3) For modern libcs, take into account that utmp char[] members | ||
18 | * need not be nul-terminated. | ||
19 | */ | ||
20 | |||
21 | #include <stdlib.h> | ||
22 | #include <unistd.h> | ||
23 | #include <fcntl.h> | ||
24 | #include <utmp.h> | ||
25 | #include "busybox.h" | ||
26 | |||
27 | /* Grr... utmp char[] members do not have to be nul-terminated. | ||
28 | * Do what we can while still keeping this reasonably small. | ||
29 | * Note: We are assuming the ut_id[] size is fixed at 4. */ | ||
30 | |||
31 | #if (UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256) | ||
32 | #error struct utmp member char[] size(s) have changed! | ||
33 | #endif | ||
34 | |||
35 | extern int dutmp_main(int argc, char **argv) | ||
36 | { | ||
37 | int file = STDIN_FILENO; | ||
38 | ssize_t n; | ||
39 | struct utmp ut; | ||
40 | |||
41 | if (argc > 2) { | ||
42 | bb_show_usage(); | ||
43 | } | ||
44 | ++argv; | ||
45 | if ((argc == 2) && ((argv[0][0] != '-') || argv[0][1])) { | ||
46 | file = bb_xopen(*argv, O_RDONLY); | ||
47 | } | ||
48 | |||
49 | |||
50 | while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) { | ||
51 | |||
52 | if (n != sizeof(struct utmp)) { | ||
53 | bb_perror_msg_and_die("short read"); | ||
54 | } | ||
55 | |||
56 | bb_printf("%d|%d|%.32s|%.4s|%.32s|%.256s|%d|%d|%ld|%ld|%ld|%x\n", | ||
57 | ut.ut_type, ut.ut_pid, ut.ut_line, | ||
58 | ut.ut_id, ut.ut_user, ut.ut_host, | ||
59 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, | ||
60 | ut.ut_session, | ||
61 | ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, | ||
62 | ut.ut_addr); | ||
63 | } | ||
64 | |||
65 | bb_fflush_stdout_and_exit(EXIT_SUCCESS); | ||
66 | } | ||
diff --git a/miscutils/last.c b/miscutils/last.c new file mode 100644 index 000000000..e7f9eb57a --- /dev/null +++ b/miscutils/last.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * last implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2003 Erik Andersen <andersen@codepoet.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sys/types.h> | ||
24 | #include <fcntl.h> | ||
25 | #include <unistd.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <utmp.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <errno.h> | ||
30 | #include <string.h> | ||
31 | #include <time.h> | ||
32 | #include "busybox.h" | ||
33 | |||
34 | #ifndef SHUTDOWN_TIME | ||
35 | # define SHUTDOWN_TIME 254 | ||
36 | #endif | ||
37 | |||
38 | /* Grr... utmp char[] members do not have to be nul-terminated. | ||
39 | * Do what we can while still keeping this reasonably small. | ||
40 | * Note: We are assuming the ut_id[] size is fixed at 4. */ | ||
41 | |||
42 | #if (UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256) | ||
43 | #error struct utmp member char[] size(s) have changed! | ||
44 | #endif | ||
45 | |||
46 | extern int last_main(int argc, char **argv) | ||
47 | { | ||
48 | struct utmp ut; | ||
49 | int n, file = STDIN_FILENO; | ||
50 | |||
51 | if (argc > 1) { | ||
52 | bb_show_usage(); | ||
53 | } | ||
54 | file = bb_xopen(_PATH_WTMP, O_RDONLY); | ||
55 | |||
56 | printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME"); | ||
57 | while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) { | ||
58 | |||
59 | if (n != sizeof(struct utmp)) { | ||
60 | bb_perror_msg_and_die("short read"); | ||
61 | } | ||
62 | |||
63 | if (strncmp(ut.ut_line, "~", 1) == 0) { | ||
64 | if (strncmp(ut.ut_user, "shutdown", 8) == 0) | ||
65 | ut.ut_type = SHUTDOWN_TIME; | ||
66 | else if (strncmp(ut.ut_user, "reboot", 6) == 0) | ||
67 | ut.ut_type = BOOT_TIME; | ||
68 | else if (strncmp(ut.ut_user, "runlevel", 7) == 0) | ||
69 | ut.ut_type = RUN_LVL; | ||
70 | } else { | ||
71 | if (!ut.ut_name[0] || strcmp(ut.ut_name, "LOGIN") == 0 || | ||
72 | ut.ut_name[0] == 0) | ||
73 | { | ||
74 | /* Don't bother. This means we can't find how long | ||
75 | * someone was logged in for. Oh well. */ | ||
76 | continue; | ||
77 | } | ||
78 | if (ut.ut_type != DEAD_PROCESS && | ||
79 | ut.ut_name[0] && ut.ut_line[0]) | ||
80 | { | ||
81 | ut.ut_type = USER_PROCESS; | ||
82 | } | ||
83 | if (strcmp(ut.ut_name, "date") == 0) { | ||
84 | if (ut.ut_line[0] == '|') ut.ut_type = OLD_TIME; | ||
85 | if (ut.ut_line[0] == '{') ut.ut_type = NEW_TIME; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | if (ut.ut_type!=USER_PROCESS) { | ||
90 | switch (ut.ut_type) { | ||
91 | case OLD_TIME: | ||
92 | case NEW_TIME: | ||
93 | case RUN_LVL: | ||
94 | case SHUTDOWN_TIME: | ||
95 | continue; | ||
96 | case BOOT_TIME: | ||
97 | strcpy(ut.ut_line, "system boot"); | ||
98 | break; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | printf("%-10s %-14s %-18s %-12.12s\n", ut.ut_user, ut.ut_line, ut.ut_host, | ||
103 | ctime(&(ut.ut_tv.tv_sec)) + 4); | ||
104 | } | ||
105 | |||
106 | bb_fflush_stdout_and_exit(EXIT_SUCCESS); | ||
107 | } | ||