1 /* vi: set sw=4 ts=4: */
2 /* uname -- print system information
3 * Copyright (C) 1989-1999 Free Software Foundation, Inc.
5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 * -n, --nodename rocky8
13 * -a, --all SunOS rocky8 4.0 sun
15 * The default behavior is equivalent to '-s'.
17 * David MacKenzie <djm@gnu.ai.mit.edu>
20 * Option: struct Example(s):
23 * -s, --kernel-name sysname Linux
24 * -n, --nodename nodename localhost.localdomain
25 * -r, --kernel-release release 2.6.29
26 * -v, --kernel-version version #1 SMP Sun Jan 11 20:52:37 EST 2009
27 * -m, --machine machine x86_64 i686
28 * -p, --processor (none) x86_64 i686
29 * -i, --hardware-platform (none) x86_64 i386
30 * NB: vanilla coreutils reports "unknown" -p and -i,
31 * x86_64 and i686/i386 shown above are Fedora's inventions.
32 * -o, --operating-system (none) GNU/Linux
33 * -a, --all: all of the above, in the order shown.
34 * If -p or -i is not known, don't show them
36 /* Busyboxed by Erik Andersen
38 * Before 2003: Glenn McGrath and Manuel Novoa III
39 * Further size reductions.
40 * Mar 16, 2003: Manuel Novoa III (mjn3@codepoet.org)
41 * Now does proper error checking on i/o. Plus some further space savings.
43 * Fix handling of -a to not print "unknown", add -o and -i support.
46 //config: bool "uname"
49 //config: uname is used to print system information.
51 //config:config UNAME_OSNAME
52 //config: string "Operating system name"
53 //config: default "GNU/Linux"
54 //config: depends on UNAME
56 //config: Sets the operating system name reported by uname -o. The
57 //config: default is "GNU/Linux".
59 //applet:IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP))
61 //kbuild:lib-$(CONFIG_UNAME) += uname.o
63 /* BB_AUDIT SUSv3 compliant */
64 /* http://www.opengroup.org/onlinepubs/007904975/utilities/uname.html */
66 //usage:#define uname_trivial_usage
67 //usage: "[-amnrspvio]"
68 //usage:#define uname_full_usage "\n\n"
69 //usage: "Print system information\n"
70 //usage: "\n -a Print all"
71 //usage: "\n -m The machine (hardware) type"
72 //usage: "\n -n Hostname"
73 //usage: "\n -r Kernel release"
74 //usage: "\n -s Kernel name (default)"
75 //usage: "\n -p Processor type"
76 //usage: "\n -v Kernel version"
77 //usage: "\n -i The hardware platform"
78 //usage: "\n -o OS name"
80 //usage:#define uname_example_usage
81 //usage: "$ uname -a\n"
82 //usage: "Linux debian 2.4.23 #2 Tue Dec 23 17:09:10 MST 2003 i686 GNU/Linux\n"
85 /* After libbb.h, since it needs sys/types.h on some systems */
86 #include <sys/utsname.h>
90 char processor[sizeof(((struct utsname*)NULL)->machine)];
91 char platform[sizeof(((struct utsname*)NULL)->machine)];
92 char os[sizeof(CONFIG_UNAME_OSNAME)];
95 static const char options[] ALIGN1 = "snrvmpioa";
96 static const unsigned short utsname_offset[] = {
97 offsetof(uname_info_t, name.sysname), /* -s */
98 offsetof(uname_info_t, name.nodename), /* -n */
99 offsetof(uname_info_t, name.release), /* -r */
100 offsetof(uname_info_t, name.version), /* -v */
101 offsetof(uname_info_t, name.machine), /* -m */
102 offsetof(uname_info_t, processor), /* -p */
103 offsetof(uname_info_t, platform), /* -i */
104 offsetof(uname_info_t, os), /* -o */
107 int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
108 int uname_main(int argc UNUSED_PARAM, char **argv)
111 static const char uname_longopts[] ALIGN1 =
112 /* name, has_arg, val */
113 "all\0" No_argument "a"
114 "kernel-name\0" No_argument "s"
115 "nodename\0" No_argument "n"
116 "kernel-release\0" No_argument "r"
117 "release\0" No_argument "r"
118 "kernel-version\0" No_argument "v"
119 "machine\0" No_argument "m"
120 "processor\0" No_argument "p"
121 "hardware-platform\0" No_argument "i"
122 "operating-system\0" No_argument "o"
125 uname_info_t uname_info;
126 #if defined(__sparc__) && defined(__linux__)
127 char *fake_sparc = getenv("FAKE_SPARC");
129 const char *unknown_str = "unknown";
131 const unsigned short *delta;
134 IF_LONG_OPTS(applet_long_options = uname_longopts);
135 toprint = getopt32(argv, options);
137 if (argv[optind]) { /* coreutils-6.9 compat */
141 if (toprint & (1 << 8)) { /* -a => all opts on */
142 toprint = (1 << 8) - 1;
143 unknown_str = ""; /* -a does not print unknown fields */
146 if (toprint == 0) { /* no opts => -s (sysname) */
150 uname(&uname_info.name); /* never fails */
152 #if defined(__sparc__) && defined(__linux__)
153 if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') {
154 strcpy(uname_info.name.machine, "sparc");
157 strcpy(uname_info.processor, unknown_str);
158 strcpy(uname_info.platform, unknown_str);
159 strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
161 /* Fedora does something like this */
162 strcpy(uname_info.processor, uname_info.name.machine);
163 strcpy(uname_info.platform, uname_info.name.machine);
164 if (uname_info.platform[0] == 'i'
165 && uname_info.platform[1]
166 && uname_info.platform[2] == '8'
167 && uname_info.platform[3] == '6'
169 uname_info.platform[1] = '3';
173 delta = utsname_offset;
177 const char *p = (char *)(&uname_info) + *delta;
184 } while (toprint >>= 1);
187 fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */