diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-19 16:32:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-19 16:32:23 +0000 |
commit | 059138fd084fdb2d9aeb738167e50e0b7985fbf8 (patch) | |
tree | 341cc7755be1598c7b1ce52ca04acc258aec1bac /coreutils/uname.c | |
parent | ec64a5775e6836f7a74d2262001ef68d3110a243 (diff) | |
download | busybox-w32-059138fd084fdb2d9aeb738167e50e0b7985fbf8.tar.gz busybox-w32-059138fd084fdb2d9aeb738167e50e0b7985fbf8.tar.bz2 busybox-w32-059138fd084fdb2d9aeb738167e50e0b7985fbf8.zip |
uname: add support for -i and -o, fix printing of unknown -p
value with -a option
function old new delta
uname_main 166 185 +19
utsname_offset 12 16 +4
options 621 623 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 25/0) Total: 25 bytes
Diffstat (limited to 'coreutils/uname.c')
-rw-r--r-- | coreutils/uname.c | 105 |
1 files changed, 72 insertions, 33 deletions
diff --git a/coreutils/uname.c b/coreutils/uname.c index e28285c44..8e51aa817 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -9,25 +9,43 @@ | |||
9 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */ | 9 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */ |
10 | 10 | ||
11 | /* Option Example | 11 | /* Option Example |
12 | * -s, --sysname SunOS | ||
13 | * -n, --nodename rocky8 | ||
14 | * -r, --release 4.0 | ||
15 | * -v, --version | ||
16 | * -m, --machine sun | ||
17 | * -a, --all SunOS rocky8 4.0 sun | ||
18 | * | ||
19 | * The default behavior is equivalent to '-s'. | ||
20 | * | ||
21 | * David MacKenzie <djm@gnu.ai.mit.edu> | ||
22 | * | ||
23 | * GNU coreutils 6.10: | ||
24 | * Option: struct Example(s): | ||
25 | * utsname | ||
26 | * field: | ||
27 | * -s, --kernel-name sysname Linux | ||
28 | * -n, --nodename nodename localhost.localdomain | ||
29 | * -r, --kernel-release release 2.6.29 | ||
30 | * -v, --kernel-version version #1 SMP Sun Jan 11 20:52:37 EST 2009 | ||
31 | * -m, --machine machine x86_64 i686 | ||
32 | * -p, --processor (none) x86_64 i686 | ||
33 | * -i, --hardware-platform (none) x86_64 i386 | ||
34 | * NB: vanilla coreutils reports "unknown" -p and -i, | ||
35 | * x86_64 and i686/i386 shown above are Fedora's inventions. | ||
36 | * -o, --operating-system (none) GNU/Linux | ||
37 | * -a, --all: all of the above, in the order shown. | ||
38 | * If -p or -i is not known, don't show them | ||
39 | */ | ||
12 | 40 | ||
13 | -s, --sysname SunOS | 41 | /* Busyboxed by Erik Andersen |
14 | -n, --nodename rocky8 | ||
15 | -r, --release 4.0 | ||
16 | -v, --version | ||
17 | -m, --machine sun | ||
18 | -a, --all SunOS rocky8 4.0 sun | ||
19 | |||
20 | The default behavior is equivalent to '-s'. | ||
21 | |||
22 | David MacKenzie <djm@gnu.ai.mit.edu> */ | ||
23 | |||
24 | /* Busyboxed by Erik Andersen */ | ||
25 | |||
26 | /* Further size reductions by Glenn McGrath and Manuel Novoa III. */ | ||
27 | |||
28 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
29 | * | 42 | * |
30 | * Now does proper error checking on i/o. Plus some further space savings. | 43 | * Before 2003: Glenn McGrath and Manuel Novoa III |
44 | * Further size reductions. | ||
45 | * Mar 16, 2003: Manuel Novoa III (mjn3@codepoet.org) | ||
46 | * Now does proper error checking on i/o. Plus some further space savings. | ||
47 | * Jan 2009: | ||
48 | * Fix handling of -a to not print "unknown", add -o and -i support. | ||
31 | */ | 49 | */ |
32 | 50 | ||
33 | #include <sys/utsname.h> | 51 | #include <sys/utsname.h> |
@@ -35,17 +53,21 @@ | |||
35 | 53 | ||
36 | typedef struct { | 54 | typedef struct { |
37 | struct utsname name; | 55 | struct utsname name; |
38 | char processor[8]; /* for "unknown" */ | 56 | char processor[sizeof(((struct utsname*)NULL)->machine)]; |
57 | char platform[sizeof(((struct utsname*)NULL)->machine)]; | ||
58 | char os[sizeof("GNU/Linux")]; | ||
39 | } uname_info_t; | 59 | } uname_info_t; |
40 | 60 | ||
41 | static const char options[] ALIGN1 = "snrvmpa"; | 61 | static const char options[] ALIGN1 = "snrvmpioa"; |
42 | static const unsigned short utsname_offset[] = { | 62 | static const unsigned short utsname_offset[] = { |
43 | offsetof(uname_info_t, name.sysname), | 63 | offsetof(uname_info_t, name.sysname), /* -s */ |
44 | offsetof(uname_info_t, name.nodename), | 64 | offsetof(uname_info_t, name.nodename), /* -n */ |
45 | offsetof(uname_info_t, name.release), | 65 | offsetof(uname_info_t, name.release), /* -r */ |
46 | offsetof(uname_info_t, name.version), | 66 | offsetof(uname_info_t, name.version), /* -v */ |
47 | offsetof(uname_info_t, name.machine), | 67 | offsetof(uname_info_t, name.machine), /* -m */ |
48 | offsetof(uname_info_t, processor) | 68 | offsetof(uname_info_t, processor), /* -p */ |
69 | offsetof(uname_info_t, platform), /* -i */ | ||
70 | offsetof(uname_info_t, os), /* -o */ | ||
49 | }; | 71 | }; |
50 | 72 | ||
51 | int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 73 | int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -55,6 +77,8 @@ int uname_main(int argc UNUSED_PARAM, char **argv) | |||
55 | #if defined(__sparc__) && defined(__linux__) | 77 | #if defined(__sparc__) && defined(__linux__) |
56 | char *fake_sparc = getenv("FAKE_SPARC"); | 78 | char *fake_sparc = getenv("FAKE_SPARC"); |
57 | #endif | 79 | #endif |
80 | const char *unknown_str = "unknown"; | ||
81 | const char *fmt; | ||
58 | const unsigned short *delta; | 82 | const unsigned short *delta; |
59 | char toprint; | 83 | char toprint; |
60 | 84 | ||
@@ -64,8 +88,9 @@ int uname_main(int argc UNUSED_PARAM, char **argv) | |||
64 | bb_show_usage(); | 88 | bb_show_usage(); |
65 | } | 89 | } |
66 | 90 | ||
67 | if (toprint & (1 << 6)) { /* -a => all opts on */ | 91 | if (toprint & (1 << 8)) { /* -a => all opts on */ |
68 | toprint = 0x3f; | 92 | toprint = (1 << 8) - 1; |
93 | unknown_str = ""; /* -a does not print unknown fields */ | ||
69 | } | 94 | } |
70 | 95 | ||
71 | if (toprint == 0) { /* no opts => -s (sysname) */ | 96 | if (toprint == 0) { /* no opts => -s (sysname) */ |
@@ -79,16 +104,30 @@ int uname_main(int argc UNUSED_PARAM, char **argv) | |||
79 | strcpy(uname_info.name.machine, "sparc"); | 104 | strcpy(uname_info.name.machine, "sparc"); |
80 | } | 105 | } |
81 | #endif | 106 | #endif |
82 | 107 | strcpy(uname_info.processor, unknown_str); | |
83 | strcpy(uname_info.processor, "unknown"); | 108 | strcpy(uname_info.platform, unknown_str); |
109 | strcpy(uname_info.os, "GNU/Linux"); | ||
110 | #if 0 | ||
111 | /* Fedora does something like this */ | ||
112 | strcpy(uname_info.processor, uname_info.name.machine); | ||
113 | strcpy(uname_info.platform, uname_info.name.machine); | ||
114 | if (uname_info.platform[0] == 'i' | ||
115 | && uname_info.platform[1] | ||
116 | && uname_info.platform[2] == '8' | ||
117 | && uname_info.platform[3] == '6' | ||
118 | ) { | ||
119 | uname_info.platform[1] = '3'; | ||
120 | } | ||
121 | #endif | ||
84 | 122 | ||
85 | delta = utsname_offset; | 123 | delta = utsname_offset; |
124 | fmt = " %s" + 1; | ||
86 | do { | 125 | do { |
87 | if (toprint & 1) { | 126 | if (toprint & 1) { |
88 | /* printf would not be safe here */ | 127 | const char *p = (char *)(&uname_info) + *delta; |
89 | fputs((char *)(&uname_info) + *delta, stdout); | 128 | if (p[0]) { |
90 | if (toprint > 1) { | 129 | printf(fmt, p); |
91 | bb_putchar(' '); | 130 | fmt = " %s"; |
92 | } | 131 | } |
93 | } | 132 | } |
94 | ++delta; | 133 | ++delta; |