diff options
author | Ron Yorston <rmy@pobox.com> | 2012-03-22 15:48:57 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-03-22 15:48:57 +0000 |
commit | 9db164d6e39050d09f38288c6045cd2a2cbf6d63 (patch) | |
tree | ea5dc2d28d15da0de25c197ed7d059c3656af1a0 /coreutils | |
parent | 1118c95535ea51961437089fc3dece5ab4ea7e1b (diff) | |
parent | d84b175cb6948eb17f847313bf912174e2f934e1 (diff) | |
download | busybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.tar.gz busybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.tar.bz2 busybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.zip |
Merge commit 'd84b175cb6948eb17f847313bf912174e2f934e1' into merge
Conflicts:
include/platform.h
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/Config.src | 7 | ||||
-rw-r--r-- | coreutils/Kbuild.src | 1 | ||||
-rw-r--r-- | coreutils/df.c | 4 | ||||
-rw-r--r-- | coreutils/ls.c | 4 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 126 | ||||
-rw-r--r-- | coreutils/usleep.c | 4 | ||||
-rw-r--r-- | coreutils/who.c | 90 |
7 files changed, 125 insertions, 111 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src index dcb5add8f..cff2ce216 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src | |||
@@ -728,13 +728,6 @@ config FEATURE_WC_LARGE | |||
728 | help | 728 | help |
729 | Use "unsigned long long" in wc for counter variables. | 729 | Use "unsigned long long" in wc for counter variables. |
730 | 730 | ||
731 | config WHO | ||
732 | bool "who" | ||
733 | default y | ||
734 | depends on FEATURE_UTMP | ||
735 | help | ||
736 | who is used to show who is logged on. | ||
737 | |||
738 | config WHOAMI | 731 | config WHOAMI |
739 | bool "whoami" | 732 | bool "whoami" |
740 | default y | 733 | default y |
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src index 0681e44b0..53d88b391 100644 --- a/coreutils/Kbuild.src +++ b/coreutils/Kbuild.src | |||
@@ -82,6 +82,5 @@ lib-$(CONFIG_USLEEP) += usleep.o | |||
82 | lib-$(CONFIG_UUDECODE) += uudecode.o | 82 | lib-$(CONFIG_UUDECODE) += uudecode.o |
83 | lib-$(CONFIG_UUENCODE) += uuencode.o | 83 | lib-$(CONFIG_UUENCODE) += uuencode.o |
84 | lib-$(CONFIG_WC) += wc.o | 84 | lib-$(CONFIG_WC) += wc.o |
85 | lib-$(CONFIG_WHO) += who.o | ||
86 | lib-$(CONFIG_WHOAMI) += whoami.o | 85 | lib-$(CONFIG_WHOAMI) += whoami.o |
87 | lib-$(CONFIG_YES) += yes.o | 86 | lib-$(CONFIG_YES) += yes.o |
diff --git a/coreutils/df.c b/coreutils/df.c index 846cb38ad..63dbd61bd 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -212,7 +212,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
212 | { | 212 | { |
213 | uni_stat_t uni_stat; | 213 | uni_stat_t uni_stat; |
214 | char *uni_dev = unicode_conv_to_printable(&uni_stat, device); | 214 | char *uni_dev = unicode_conv_to_printable(&uni_stat, device); |
215 | if (uni_stat.unicode_width > 20) { | 215 | if (uni_stat.unicode_width > 20 && !(opt & OPT_POSIX)) { |
216 | printf("%s\n%20s", uni_dev, ""); | 216 | printf("%s\n%20s", uni_dev, ""); |
217 | } else { | 217 | } else { |
218 | printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, ""); | 218 | printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, ""); |
@@ -220,7 +220,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
220 | free(uni_dev); | 220 | free(uni_dev); |
221 | } | 221 | } |
222 | #else | 222 | #else |
223 | if (printf("\n%-20s" + 1, device) > 20) | 223 | if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) |
224 | printf("\n%-20s", ""); | 224 | printf("\n%-20s", ""); |
225 | #endif | 225 | #endif |
226 | 226 | ||
diff --git a/coreutils/ls.c b/coreutils/ls.c index 4abf84513..9876c2db2 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -1120,7 +1120,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1120 | IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;) | 1120 | IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;) |
1121 | opt_complementary = | 1121 | opt_complementary = |
1122 | /* -e implies -l */ | 1122 | /* -e implies -l */ |
1123 | "el" | 1123 | IF_FEATURE_LS_TIMESTAMPS("el") |
1124 | /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: | 1124 | /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: |
1125 | * in some pairs of opts, only last one takes effect: | 1125 | * in some pairs of opts, only last one takes effect: |
1126 | */ | 1126 | */ |
@@ -1130,7 +1130,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1130 | ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ | 1130 | ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ |
1131 | ":C-1:1-C" /* bycols/oneline */ | 1131 | ":C-1:1-C" /* bycols/oneline */ |
1132 | ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ | 1132 | ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ |
1133 | ":c-u:u-c" /* mtime/atime */ | 1133 | IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ |
1134 | /* -w NUM: */ | 1134 | /* -w NUM: */ |
1135 | IF_FEATURE_AUTOWIDTH(":w+"); | 1135 | IF_FEATURE_AUTOWIDTH(":w+"); |
1136 | opt = getopt32(argv, ls_options | 1136 | opt = getopt32(argv, ls_options |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 53fd4d1a8..2cb6dd43c 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -7,12 +7,11 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | //usage:#define md5sum_trivial_usage | 9 | //usage:#define md5sum_trivial_usage |
10 | //usage: "[FILE]..." | 10 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..." |
11 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("\n or: md5sum -c [-sw] [FILE]") | ||
12 | //usage:#define md5sum_full_usage "\n\n" | 11 | //usage:#define md5sum_full_usage "\n\n" |
13 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " MD5 checksums" | 12 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " MD5 checksums" |
14 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" | 13 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" |
15 | //usage: "\n -c Check sums against given list" | 14 | //usage: "\n -c Check sums against list in FILEs" |
16 | //usage: "\n -s Don't output anything, status code shows success" | 15 | //usage: "\n -s Don't output anything, status code shows success" |
17 | //usage: "\n -w Warn about improperly formatted checksum lines" | 16 | //usage: "\n -w Warn about improperly formatted checksum lines" |
18 | //usage: ) | 17 | //usage: ) |
@@ -28,34 +27,31 @@ | |||
28 | //usage: "^D\n" | 27 | //usage: "^D\n" |
29 | //usage: | 28 | //usage: |
30 | //usage:#define sha1sum_trivial_usage | 29 | //usage:#define sha1sum_trivial_usage |
31 | //usage: "[FILE]..." | 30 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..." |
32 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("\n or: sha1sum -c [-sw] [FILE]") | ||
33 | //usage:#define sha1sum_full_usage "\n\n" | 31 | //usage:#define sha1sum_full_usage "\n\n" |
34 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA1 checksums" | 32 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA1 checksums" |
35 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" | 33 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" |
36 | //usage: "\n -c Check sums against given list" | 34 | //usage: "\n -c Check sums against list in FILEs" |
37 | //usage: "\n -s Don't output anything, status code shows success" | 35 | //usage: "\n -s Don't output anything, status code shows success" |
38 | //usage: "\n -w Warn about improperly formatted checksum lines" | 36 | //usage: "\n -w Warn about improperly formatted checksum lines" |
39 | //usage: ) | 37 | //usage: ) |
40 | //usage: | 38 | //usage: |
41 | //usage:#define sha256sum_trivial_usage | 39 | //usage:#define sha256sum_trivial_usage |
42 | //usage: "[FILE]..." | 40 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..." |
43 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("\n or: sha256sum -c [-sw] [FILE]") | ||
44 | //usage:#define sha256sum_full_usage "\n\n" | 41 | //usage:#define sha256sum_full_usage "\n\n" |
45 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA256 checksums" | 42 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA256 checksums" |
46 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" | 43 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" |
47 | //usage: "\n -c Check sums against given list" | 44 | //usage: "\n -c Check sums against list in FILEs" |
48 | //usage: "\n -s Don't output anything, status code shows success" | 45 | //usage: "\n -s Don't output anything, status code shows success" |
49 | //usage: "\n -w Warn about improperly formatted checksum lines" | 46 | //usage: "\n -w Warn about improperly formatted checksum lines" |
50 | //usage: ) | 47 | //usage: ) |
51 | //usage: | 48 | //usage: |
52 | //usage:#define sha512sum_trivial_usage | 49 | //usage:#define sha512sum_trivial_usage |
53 | //usage: "[FILE]..." | 50 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..." |
54 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("\n or: sha512sum -c [-sw] [FILE]") | ||
55 | //usage:#define sha512sum_full_usage "\n\n" | 51 | //usage:#define sha512sum_full_usage "\n\n" |
56 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA512 checksums" | 52 | //usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA512 checksums" |
57 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" | 53 | //usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n" |
58 | //usage: "\n -c Check sums against given list" | 54 | //usage: "\n -c Check sums against list in FILEs" |
59 | //usage: "\n -s Don't output anything, status code shows success" | 55 | //usage: "\n -s Don't output anything, status code shows success" |
60 | //usage: "\n -w Warn about improperly formatted checksum lines" | 56 | //usage: "\n -w Warn about improperly formatted checksum lines" |
61 | //usage: ) | 57 | //usage: ) |
@@ -95,7 +91,7 @@ static uint8_t *hash_file(const char *filename) | |||
95 | sha1_ctx_t sha1; | 91 | sha1_ctx_t sha1; |
96 | md5_ctx_t md5; | 92 | md5_ctx_t md5; |
97 | } context; | 93 | } context; |
98 | uint8_t *hash_value = NULL; | 94 | uint8_t *hash_value; |
99 | void FAST_FUNC (*update)(void*, const void*, size_t); | 95 | void FAST_FUNC (*update)(void*, const void*, size_t); |
100 | void FAST_FUNC (*final)(void*, void*); | 96 | void FAST_FUNC (*final)(void*, void*); |
101 | char hash_algo; | 97 | char hash_algo; |
@@ -137,6 +133,7 @@ static uint8_t *hash_file(const char *filename) | |||
137 | while ((count = safe_read(src_fd, in_buf, 4096)) > 0) { | 133 | while ((count = safe_read(src_fd, in_buf, 4096)) > 0) { |
138 | update(&context, in_buf, count); | 134 | update(&context, in_buf, count); |
139 | } | 135 | } |
136 | hash_value = NULL; | ||
140 | if (count == 0) { | 137 | if (count == 0) { |
141 | final(&context, in_buf); | 138 | final(&context, in_buf); |
142 | hash_value = hash_bin_to_hex(in_buf, hash_len); | 139 | hash_value = hash_bin_to_hex(in_buf, hash_len); |
@@ -178,66 +175,58 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
178 | } | 175 | } |
179 | } | 176 | } |
180 | 177 | ||
181 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) { | 178 | do { |
182 | FILE *pre_computed_stream; | 179 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) { |
183 | int count_total = 0; | 180 | FILE *pre_computed_stream; |
184 | int count_failed = 0; | 181 | char *line; |
185 | char *line; | 182 | int count_total = 0; |
183 | int count_failed = 0; | ||
186 | 184 | ||
187 | if (argv[1]) { | 185 | pre_computed_stream = xfopen_stdin(*argv); |
188 | bb_error_msg_and_die("only one argument may be specified with -c"); | ||
189 | } | ||
190 | |||
191 | pre_computed_stream = xfopen_stdin(argv[0]); | ||
192 | 186 | ||
193 | while ((line = xmalloc_fgetline(pre_computed_stream)) != NULL) { | 187 | while ((line = xmalloc_fgetline(pre_computed_stream)) != NULL) { |
194 | uint8_t *hash_value; | 188 | uint8_t *hash_value; |
195 | char *filename_ptr; | 189 | char *filename_ptr; |
196 | 190 | ||
197 | count_total++; | 191 | count_total++; |
198 | filename_ptr = strstr(line, " "); | 192 | filename_ptr = strstr(line, " "); |
199 | /* handle format for binary checksums */ | 193 | /* handle format for binary checksums */ |
200 | if (filename_ptr == NULL) { | 194 | if (filename_ptr == NULL) { |
201 | filename_ptr = strstr(line, " *"); | 195 | filename_ptr = strstr(line, " *"); |
202 | } | ||
203 | if (filename_ptr == NULL) { | ||
204 | if (flags & FLAG_WARN) { | ||
205 | bb_error_msg("invalid format"); | ||
206 | } | 196 | } |
207 | count_failed++; | 197 | if (filename_ptr == NULL) { |
208 | return_value = EXIT_FAILURE; | 198 | if (flags & FLAG_WARN) { |
199 | bb_error_msg("invalid format"); | ||
200 | } | ||
201 | count_failed++; | ||
202 | return_value = EXIT_FAILURE; | ||
203 | free(line); | ||
204 | continue; | ||
205 | } | ||
206 | *filename_ptr = '\0'; | ||
207 | filename_ptr += 2; | ||
208 | |||
209 | hash_value = hash_file(filename_ptr); | ||
210 | |||
211 | if (hash_value && (strcmp((char*)hash_value, line) == 0)) { | ||
212 | if (!(flags & FLAG_SILENT)) | ||
213 | printf("%s: OK\n", filename_ptr); | ||
214 | } else { | ||
215 | if (!(flags & FLAG_SILENT)) | ||
216 | printf("%s: FAILED\n", filename_ptr); | ||
217 | count_failed++; | ||
218 | return_value = EXIT_FAILURE; | ||
219 | } | ||
220 | /* possible free(NULL) */ | ||
221 | free(hash_value); | ||
209 | free(line); | 222 | free(line); |
210 | continue; | ||
211 | } | 223 | } |
212 | *filename_ptr = '\0'; | 224 | if (count_failed && !(flags & FLAG_SILENT)) { |
213 | filename_ptr += 2; | 225 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", |
214 | 226 | count_failed, count_total); | |
215 | hash_value = hash_file(filename_ptr); | ||
216 | |||
217 | if (hash_value && (strcmp((char*)hash_value, line) == 0)) { | ||
218 | if (!(flags & FLAG_SILENT)) | ||
219 | printf("%s: OK\n", filename_ptr); | ||
220 | } else { | ||
221 | if (!(flags & FLAG_SILENT)) | ||
222 | printf("%s: FAILED\n", filename_ptr); | ||
223 | count_failed++; | ||
224 | return_value = EXIT_FAILURE; | ||
225 | } | 227 | } |
226 | /* possible free(NULL) */ | 228 | fclose_if_not_stdin(pre_computed_stream); |
227 | free(hash_value); | 229 | } else { |
228 | free(line); | ||
229 | } | ||
230 | if (count_failed && !(flags & FLAG_SILENT)) { | ||
231 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", | ||
232 | count_failed, count_total); | ||
233 | } | ||
234 | /* | ||
235 | if (fclose_if_not_stdin(pre_computed_stream) == EOF) { | ||
236 | bb_perror_msg_and_die("can't close file %s", file_ptr); | ||
237 | } | ||
238 | */ | ||
239 | } else { | ||
240 | do { | ||
241 | uint8_t *hash_value = hash_file(*argv); | 230 | uint8_t *hash_value = hash_file(*argv); |
242 | if (hash_value == NULL) { | 231 | if (hash_value == NULL) { |
243 | return_value = EXIT_FAILURE; | 232 | return_value = EXIT_FAILURE; |
@@ -245,7 +234,8 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
245 | printf("%s %s\n", hash_value, *argv); | 234 | printf("%s %s\n", hash_value, *argv); |
246 | free(hash_value); | 235 | free(hash_value); |
247 | } | 236 | } |
248 | } while (*++argv); | 237 | } |
249 | } | 238 | } while (*++argv); |
239 | |||
250 | return return_value; | 240 | return return_value; |
251 | } | 241 | } |
diff --git a/coreutils/usleep.c b/coreutils/usleep.c index 67f94f798..2e4eb5721 100644 --- a/coreutils/usleep.c +++ b/coreutils/usleep.c | |||
@@ -29,9 +29,7 @@ int usleep_main(int argc UNUSED_PARAM, char **argv) | |||
29 | bb_show_usage(); | 29 | bb_show_usage(); |
30 | } | 30 | } |
31 | 31 | ||
32 | if (usleep(xatou(argv[1]))) { | 32 | usleep(xatou(argv[1])); |
33 | bb_perror_nomsg_and_die(); | ||
34 | } | ||
35 | 33 | ||
36 | return EXIT_SUCCESS; | 34 | return EXIT_SUCCESS; |
37 | } | 35 | } |
diff --git a/coreutils/who.c b/coreutils/who.c index 9f37f65fd..c6c925264 100644 --- a/coreutils/who.c +++ b/coreutils/who.c | |||
@@ -18,6 +18,31 @@ | |||
18 | */ | 18 | */ |
19 | /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ | 19 | /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ |
20 | 20 | ||
21 | //config:config WHO | ||
22 | //config: bool "who" | ||
23 | //config: default y | ||
24 | //config: depends on FEATURE_UTMP | ||
25 | //config: help | ||
26 | //config: who is used to show who is logged on. | ||
27 | |||
28 | //config:config USERS | ||
29 | //config: bool "users" | ||
30 | //config: default y | ||
31 | //config: depends on FEATURE_UTMP | ||
32 | //config: help | ||
33 | //config: Print users currently logged on. | ||
34 | |||
35 | //applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users)) | ||
36 | //applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
37 | |||
38 | //kbuild:lib-$(CONFIG_USERS) += who.o | ||
39 | //kbuild:lib-$(CONFIG_WHO) += who.o | ||
40 | |||
41 | //usage:#define users_trivial_usage | ||
42 | //usage: "" | ||
43 | //usage:#define users_full_usage "\n\n" | ||
44 | //usage: "Print the users currently logged on" | ||
45 | |||
21 | //usage:#define who_trivial_usage | 46 | //usage:#define who_trivial_usage |
22 | //usage: "[-a]" | 47 | //usage: "[-a]" |
23 | //usage:#define who_full_usage "\n\n" | 48 | //usage:#define who_full_usage "\n\n" |
@@ -49,9 +74,11 @@ int who_main(int argc UNUSED_PARAM, char **argv) | |||
49 | { | 74 | { |
50 | struct utmp *ut; | 75 | struct utmp *ut; |
51 | unsigned opt; | 76 | unsigned opt; |
77 | int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u')); | ||
78 | const char *fmt = "%s"; | ||
52 | 79 | ||
53 | opt_complementary = "=0"; | 80 | opt_complementary = "=0"; |
54 | opt = getopt32(argv, "aH"); | 81 | opt = getopt32(argv, do_users ? "" : "aH"); |
55 | if (opt & 2) // -H | 82 | if (opt & 2) // -H |
56 | printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n"); | 83 | printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n"); |
57 | 84 | ||
@@ -60,36 +87,43 @@ int who_main(int argc UNUSED_PARAM, char **argv) | |||
60 | if (ut->ut_user[0] | 87 | if (ut->ut_user[0] |
61 | && ((opt & 1) || ut->ut_type == USER_PROCESS) | 88 | && ((opt & 1) || ut->ut_type == USER_PROCESS) |
62 | ) { | 89 | ) { |
63 | char str6[6]; | 90 | if (!do_users) { |
64 | char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1]; | 91 | char str6[6]; |
65 | struct stat st; | 92 | char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1]; |
66 | time_t seconds; | 93 | struct stat st; |
94 | time_t seconds; | ||
67 | 95 | ||
68 | str6[0] = '?'; | 96 | str6[0] = '?'; |
69 | str6[1] = '\0'; | 97 | str6[1] = '\0'; |
70 | strcpy(name, "/dev/"); | 98 | strcpy(name, "/dev/"); |
71 | safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1, | 99 | safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1, |
72 | ut->ut_line, | 100 | ut->ut_line, |
73 | sizeof(ut->ut_line)+1 | 101 | sizeof(ut->ut_line)+1 |
74 | ); | 102 | ); |
75 | if (stat(name, &st) == 0) | 103 | if (stat(name, &st) == 0) |
76 | idle_string(str6, st.st_atime); | 104 | idle_string(str6, st.st_atime); |
77 | /* manpages say ut_tv.tv_sec *is* time_t, | 105 | /* manpages say ut_tv.tv_sec *is* time_t, |
78 | * but some systems have it wrong */ | 106 | * but some systems have it wrong */ |
79 | seconds = ut->ut_tv.tv_sec; | 107 | seconds = ut->ut_tv.tv_sec; |
80 | /* How wide time field can be? | 108 | /* How wide time field can be? |
81 | * "Nov 10 19:33:20": 15 chars | 109 | * "Nov 10 19:33:20": 15 chars |
82 | * "2010-11-10 19:33": 16 chars | 110 | * "2010-11-10 19:33": 16 chars |
83 | */ | 111 | */ |
84 | printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n", | 112 | printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n", |
85 | (int)sizeof(ut->ut_user), ut->ut_user, | 113 | (int)sizeof(ut->ut_user), ut->ut_user, |
86 | (int)sizeof(ut->ut_line), ut->ut_line, | 114 | (int)sizeof(ut->ut_line), ut->ut_line, |
87 | str6, | 115 | str6, |
88 | ctime(&seconds) + 4, | 116 | ctime(&seconds) + 4, |
89 | (int)sizeof(ut->ut_host), ut->ut_host | 117 | (int)sizeof(ut->ut_host), ut->ut_host |
90 | ); | 118 | ); |
119 | } else { | ||
120 | printf(fmt, ut->ut_user); | ||
121 | fmt = " %s"; | ||
122 | } | ||
91 | } | 123 | } |
92 | } | 124 | } |
125 | if (do_users) | ||
126 | bb_putchar('\n'); | ||
93 | if (ENABLE_FEATURE_CLEAN_UP) | 127 | if (ENABLE_FEATURE_CLEAN_UP) |
94 | endutent(); | 128 | endutent(); |
95 | return EXIT_SUCCESS; | 129 | return EXIT_SUCCESS; |