[de4abd5] | 1 | Submitted By: Jim Gifford <jim at cross-lfs dot org> |
---|
| 2 | Date: 2010-07-26 |
---|
| 3 | Initial Package Version: 5.97 |
---|
| 4 | Upstream Status: Not Accepted |
---|
| 5 | Origin: Gentoo - http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/coreutils |
---|
| 6 | Description: Display CPU Information from /proc/cpuinfo or /proc/sysinfo |
---|
| 7 | |
---|
| 8 | Rediffed for 7.1 by Jim Gifford |
---|
| 9 | Rediffed for 7.5 by Jim Gifford |
---|
| 10 | Rediffed for 8.4 by Joe Ciccone |
---|
| 11 | Rediffed for 8.9 by Joe Ciccone |
---|
| 12 | Rediffed for 8.16 by Jonathan Norman - 2012-06-10 |
---|
[68a11fb] | 13 | Rediffed for 8.19 by William Harrington - 2012-08-27 |
---|
[de4abd5] | 14 | |
---|
[68a11fb] | 15 | diff -Naur coreutils-8.19.orig/src/uname.c coreutils-8.19/src/uname.c |
---|
| 16 | --- coreutils-8.19.orig/src/uname.c 2012-07-21 14:54:31.000000000 +0000 |
---|
| 17 | +++ coreutils-8.19/src/uname.c 2012-08-27 21:20:07.103876901 +0000 |
---|
[de4abd5] | 18 | @@ -49,6 +49,11 @@ |
---|
| 19 | # include <mach-o/arch.h> |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | +#if defined (__linux__) |
---|
| 23 | +# define USE_PROCINFO |
---|
| 24 | +# define UNAME_HARDWARE_PLATFORM |
---|
| 25 | +#endif |
---|
| 26 | + |
---|
| 27 | #include "system.h" |
---|
| 28 | #include "error.h" |
---|
| 29 | #include "quote.h" |
---|
| 30 | @@ -153,6 +158,117 @@ |
---|
| 31 | exit (status); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | +#if defined(USE_PROCINFO) |
---|
| 35 | + |
---|
| 36 | +# if defined(__s390__) || defined(__s390x__) |
---|
| 37 | +# define CPUINFO_FILE "/proc/sysinfo" |
---|
| 38 | +# define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c" |
---|
| 39 | +# else |
---|
| 40 | +# define CPUINFO_FILE "/proc/cpuinfo" |
---|
| 41 | +# define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c" |
---|
| 42 | +# endif |
---|
| 43 | + |
---|
| 44 | +# define PROCINFO_PROCESSOR 0 |
---|
| 45 | +# define PROCINFO_HARDWARE_PLATFORM 1 |
---|
| 46 | + |
---|
| 47 | +static void __eat_cpuinfo_space(char *buf) |
---|
| 48 | +{ |
---|
| 49 | + /* first eat trailing space */ |
---|
| 50 | + char *tmp = buf + strlen(buf) - 1; |
---|
| 51 | + while (tmp > buf && isspace(*tmp)) |
---|
| 52 | + *tmp-- = '\0'; |
---|
| 53 | + /* then eat leading space */ |
---|
| 54 | + tmp = buf; |
---|
| 55 | + while (*tmp && isspace(*tmp)) |
---|
| 56 | + tmp++; |
---|
| 57 | + if (tmp != buf) |
---|
| 58 | + memmove(buf, tmp, strlen(tmp)+1); |
---|
| 59 | + /* finally collapse whitespace */ |
---|
| 60 | + tmp = buf; |
---|
| 61 | + while (tmp[0] && tmp[1]) { |
---|
| 62 | + if (isspace(tmp[0]) && isspace(tmp[1])) { |
---|
| 63 | + memmove(tmp, tmp+1, strlen(tmp)); |
---|
| 64 | + continue; |
---|
| 65 | + } |
---|
| 66 | + ++tmp; |
---|
| 67 | + } |
---|
| 68 | +} |
---|
| 69 | + |
---|
| 70 | +static int __linux_procinfo (int x, char *fstr, size_t s) |
---|
| 71 | +{ |
---|
| 72 | + FILE *fp; |
---|
| 73 | + |
---|
| 74 | + char *procinfo_keys[] = { |
---|
| 75 | + /* --processor --hardware-platform */ |
---|
| 76 | + #if defined(__alpha__) |
---|
| 77 | + "cpu model", "system type" |
---|
| 78 | + #elif defined(__arm__) |
---|
| 79 | + "Processor", "Hardware" |
---|
| 80 | + #elif defined(__avr32__) |
---|
| 81 | + "processor", "cpu family" |
---|
| 82 | + #elif defined(__bfin__) |
---|
| 83 | + "CPU", "BOARD Name" |
---|
| 84 | + #elif defined(__cris__) |
---|
| 85 | + "cpu", "cpu model" |
---|
| 86 | + #elif defined(__frv__) |
---|
| 87 | + "CPU-Core", "System" |
---|
| 88 | + #elif defined(__i386__) || defined(__x86_64__) |
---|
| 89 | + "model name", "vendor_id" |
---|
| 90 | + #elif defined(__ia64__) |
---|
| 91 | + "family", "vendor" |
---|
| 92 | + #elif defined(__hppa__) |
---|
| 93 | + "cpu", "model" |
---|
| 94 | + #elif defined(__m68k__) |
---|
| 95 | + "CPU", "MMU" |
---|
| 96 | + #elif defined(__mips__) |
---|
| 97 | + "cpu model", "system type" |
---|
| 98 | + #elif defined(__powerpc__) || defined(__powerpc64__) |
---|
| 99 | + "cpu", "machine" |
---|
| 100 | + #elif defined(__s390__) || defined(__s390x__) |
---|
| 101 | + "Type", "Manufacturer" |
---|
| 102 | + #elif defined(__sh__) |
---|
| 103 | + "cpu type", "machine" |
---|
| 104 | + #elif defined(sparc) || defined(__sparc__) |
---|
| 105 | + "type", "cpu" |
---|
| 106 | + #elif defined(__vax__) |
---|
| 107 | + "cpu type", "cpu" |
---|
| 108 | + #else |
---|
| 109 | + "unknown", "unknown" |
---|
| 110 | + #endif |
---|
| 111 | + }; |
---|
| 112 | + |
---|
| 113 | + if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) { |
---|
| 114 | + char key[65], value[257], eol, *ret = NULL; |
---|
| 115 | + |
---|
| 116 | + while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) { |
---|
| 117 | + __eat_cpuinfo_space(key); |
---|
| 118 | + if (!strcmp(key, procinfo_keys[x])) { |
---|
| 119 | + __eat_cpuinfo_space(value); |
---|
| 120 | + ret = value; |
---|
| 121 | + break; |
---|
| 122 | + } |
---|
| 123 | + if (eol != '\n') { |
---|
| 124 | + /* we need two fscanf's here in case the previous |
---|
| 125 | + * length limit caused us to read right up to the |
---|
| 126 | + * newline ... doing "%*[^\n]\n" wont eat the newline |
---|
| 127 | + */ |
---|
| 128 | + fscanf(fp, "%*[^\n]"); |
---|
| 129 | + fscanf(fp, "\n"); |
---|
| 130 | + } |
---|
| 131 | + } |
---|
| 132 | + fclose(fp); |
---|
| 133 | + |
---|
| 134 | + if (ret) { |
---|
| 135 | + strncpy(fstr, ret, s); |
---|
| 136 | + return 0; |
---|
| 137 | + } |
---|
| 138 | + } |
---|
| 139 | + |
---|
| 140 | + return -1; |
---|
| 141 | +} |
---|
| 142 | + |
---|
| 143 | +#endif |
---|
| 144 | + |
---|
| 145 | /* Print ELEMENT, preceded by a space if something has already been |
---|
| 146 | printed. */ |
---|
| 147 | |
---|
| 148 | @@ -300,10 +416,14 @@ |
---|
| 149 | if (toprint & PRINT_PROCESSOR) |
---|
| 150 | { |
---|
| 151 | char const *element = unknown; |
---|
| 152 | -#if HAVE_SYSINFO && defined SI_ARCHITECTURE |
---|
| 153 | +#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) |
---|
| 154 | { |
---|
| 155 | static char processor[257]; |
---|
| 156 | +#if defined(USE_PROCINFO) |
---|
| 157 | + if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) |
---|
| 158 | +#else |
---|
| 159 | if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) |
---|
| 160 | +#endif |
---|
| 161 | element = processor; |
---|
| 162 | } |
---|
| 163 | #endif |
---|
| 164 | @@ -356,9 +476,13 @@ |
---|
| 165 | if (element == unknown) |
---|
| 166 | { |
---|
| 167 | static char hardware_platform[257]; |
---|
| 168 | +#if defined(USE_PROCINFO) |
---|
| 169 | + if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform)) |
---|
| 170 | +#else |
---|
| 171 | size_t s = sizeof hardware_platform; |
---|
| 172 | static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; |
---|
| 173 | if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) |
---|
| 174 | +#endif |
---|
| 175 | element = hardware_platform; |
---|
| 176 | } |
---|
| 177 | #endif |
---|
[68a11fb] | 178 | diff -Naur coreutils-8.19.orig/src/uname.c.orig coreutils-8.19/src/uname.c.orig |
---|
| 179 | --- coreutils-8.19.orig/src/uname.c.orig 1970-01-01 00:00:00.000000000 +0000 |
---|
| 180 | +++ coreutils-8.19/src/uname.c.orig 2012-08-27 21:20:07.103876901 +0000 |
---|
[de4abd5] | 181 | @@ -0,0 +1,375 @@ |
---|
| 182 | +/* uname -- print system information |
---|
| 183 | + |
---|
| 184 | + Copyright (C) 1989-2012 Free Software Foundation, Inc. |
---|
| 185 | + |
---|
| 186 | + This program is free software: you can redistribute it and/or modify |
---|
| 187 | + it under the terms of the GNU General Public License as published by |
---|
| 188 | + the Free Software Foundation, either version 3 of the License, or |
---|
| 189 | + (at your option) any later version. |
---|
| 190 | + |
---|
| 191 | + This program is distributed in the hope that it will be useful, |
---|
| 192 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 193 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 194 | + GNU General Public License for more details. |
---|
| 195 | + |
---|
| 196 | + You should have received a copy of the GNU General Public License |
---|
| 197 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
---|
| 198 | + |
---|
| 199 | +/* Written by David MacKenzie <djm@gnu.ai.mit.edu> */ |
---|
| 200 | + |
---|
| 201 | +#include <config.h> |
---|
| 202 | +#include <stdio.h> |
---|
| 203 | +#include <sys/types.h> |
---|
| 204 | +#include <sys/utsname.h> |
---|
| 205 | +#include <getopt.h> |
---|
| 206 | + |
---|
| 207 | +#if HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H |
---|
| 208 | +# include <sys/systeminfo.h> |
---|
| 209 | +#endif |
---|
| 210 | + |
---|
| 211 | +#if HAVE_SYS_SYSCTL_H |
---|
| 212 | +# if HAVE_SYS_PARAM_H |
---|
| 213 | +# include <sys/param.h> /* needed for OpenBSD 3.0 */ |
---|
| 214 | +# endif |
---|
| 215 | +# include <sys/sysctl.h> |
---|
| 216 | +# ifdef HW_MODEL |
---|
| 217 | +# ifdef HW_MACHINE_ARCH |
---|
| 218 | +/* E.g., FreeBSD 4.5, NetBSD 1.5.2 */ |
---|
| 219 | +# define UNAME_HARDWARE_PLATFORM HW_MODEL |
---|
| 220 | +# define UNAME_PROCESSOR HW_MACHINE_ARCH |
---|
| 221 | +# else |
---|
| 222 | +/* E.g., OpenBSD 3.0 */ |
---|
| 223 | +# define UNAME_PROCESSOR HW_MODEL |
---|
| 224 | +# endif |
---|
| 225 | +# endif |
---|
| 226 | +#endif |
---|
| 227 | + |
---|
| 228 | +#ifdef __APPLE__ |
---|
| 229 | +# include <mach/machine.h> |
---|
| 230 | +# include <mach-o/arch.h> |
---|
| 231 | +#endif |
---|
| 232 | + |
---|
| 233 | +#include "system.h" |
---|
| 234 | +#include "error.h" |
---|
| 235 | +#include "quote.h" |
---|
| 236 | +#include "uname.h" |
---|
| 237 | + |
---|
| 238 | +/* The official name of this program (e.g., no 'g' prefix). */ |
---|
| 239 | +#define PROGRAM_NAME (uname_mode == UNAME_UNAME ? "uname" : "arch") |
---|
| 240 | + |
---|
| 241 | +#define AUTHORS proper_name ("David MacKenzie") |
---|
| 242 | +#define ARCH_AUTHORS "David MacKenzie", "Karel Zak" |
---|
| 243 | + |
---|
| 244 | +/* Values that are bitwise or'd into 'toprint'. */ |
---|
| 245 | +/* Kernel name. */ |
---|
| 246 | +#define PRINT_KERNEL_NAME 1 |
---|
| 247 | + |
---|
| 248 | +/* Node name on a communications network. */ |
---|
| 249 | +#define PRINT_NODENAME 2 |
---|
| 250 | + |
---|
| 251 | +/* Kernel release. */ |
---|
| 252 | +#define PRINT_KERNEL_RELEASE 4 |
---|
| 253 | + |
---|
| 254 | +/* Kernel version. */ |
---|
| 255 | +#define PRINT_KERNEL_VERSION 8 |
---|
| 256 | + |
---|
| 257 | +/* Machine hardware name. */ |
---|
| 258 | +#define PRINT_MACHINE 16 |
---|
| 259 | + |
---|
| 260 | +/* Processor type. */ |
---|
| 261 | +#define PRINT_PROCESSOR 32 |
---|
| 262 | + |
---|
| 263 | +/* Hardware platform. */ |
---|
| 264 | +#define PRINT_HARDWARE_PLATFORM 64 |
---|
| 265 | + |
---|
| 266 | +/* Operating system. */ |
---|
| 267 | +#define PRINT_OPERATING_SYSTEM 128 |
---|
| 268 | + |
---|
| 269 | +static struct option const uname_long_options[] = |
---|
| 270 | +{ |
---|
| 271 | + {"all", no_argument, NULL, 'a'}, |
---|
| 272 | + {"kernel-name", no_argument, NULL, 's'}, |
---|
| 273 | + {"sysname", no_argument, NULL, 's'}, /* Obsolescent. */ |
---|
| 274 | + {"nodename", no_argument, NULL, 'n'}, |
---|
| 275 | + {"kernel-release", no_argument, NULL, 'r'}, |
---|
| 276 | + {"release", no_argument, NULL, 'r'}, /* Obsolescent. */ |
---|
| 277 | + {"kernel-version", no_argument, NULL, 'v'}, |
---|
| 278 | + {"machine", no_argument, NULL, 'm'}, |
---|
| 279 | + {"processor", no_argument, NULL, 'p'}, |
---|
| 280 | + {"hardware-platform", no_argument, NULL, 'i'}, |
---|
| 281 | + {"operating-system", no_argument, NULL, 'o'}, |
---|
| 282 | + {GETOPT_HELP_OPTION_DECL}, |
---|
| 283 | + {GETOPT_VERSION_OPTION_DECL}, |
---|
| 284 | + {NULL, 0, NULL, 0} |
---|
| 285 | +}; |
---|
| 286 | + |
---|
| 287 | +static struct option const arch_long_options[] = |
---|
| 288 | +{ |
---|
| 289 | + {GETOPT_HELP_OPTION_DECL}, |
---|
| 290 | + {GETOPT_VERSION_OPTION_DECL}, |
---|
| 291 | + {NULL, 0, NULL, 0} |
---|
| 292 | +}; |
---|
| 293 | + |
---|
| 294 | +void |
---|
| 295 | +usage (int status) |
---|
| 296 | +{ |
---|
| 297 | + if (status != EXIT_SUCCESS) |
---|
| 298 | + emit_try_help (); |
---|
| 299 | + else |
---|
| 300 | + { |
---|
| 301 | + printf (_("Usage: %s [OPTION]...\n"), program_name); |
---|
| 302 | + |
---|
| 303 | + if (uname_mode == UNAME_UNAME) |
---|
| 304 | + { |
---|
| 305 | + fputs (_("\ |
---|
| 306 | +Print certain system information. With no OPTION, same as -s.\n\ |
---|
| 307 | +\n\ |
---|
| 308 | + -a, --all print all information, in the following order,\n\ |
---|
| 309 | + except omit -p and -i if unknown:\n\ |
---|
| 310 | + -s, --kernel-name print the kernel name\n\ |
---|
| 311 | + -n, --nodename print the network node hostname\n\ |
---|
| 312 | + -r, --kernel-release print the kernel release\n\ |
---|
| 313 | +"), stdout); |
---|
| 314 | + fputs (_("\ |
---|
| 315 | + -v, --kernel-version print the kernel version\n\ |
---|
| 316 | + -m, --machine print the machine hardware name\n\ |
---|
| 317 | + -p, --processor print the processor type or \"unknown\"\n\ |
---|
| 318 | + -i, --hardware-platform print the hardware platform or \"unknown\"\n\ |
---|
| 319 | + -o, --operating-system print the operating system\n\ |
---|
| 320 | +"), stdout); |
---|
| 321 | + } |
---|
| 322 | + else |
---|
| 323 | + { |
---|
| 324 | + fputs (_("\ |
---|
| 325 | +Print machine architecture.\n\ |
---|
| 326 | +\n\ |
---|
| 327 | +"), stdout); |
---|
| 328 | + } |
---|
| 329 | + |
---|
| 330 | + fputs (HELP_OPTION_DESCRIPTION, stdout); |
---|
| 331 | + fputs (VERSION_OPTION_DESCRIPTION, stdout); |
---|
| 332 | + emit_ancillary_info (); |
---|
| 333 | + } |
---|
| 334 | + exit (status); |
---|
| 335 | +} |
---|
| 336 | + |
---|
| 337 | +/* Print ELEMENT, preceded by a space if something has already been |
---|
| 338 | + printed. */ |
---|
| 339 | + |
---|
| 340 | +static void |
---|
| 341 | +print_element (char const *element) |
---|
| 342 | +{ |
---|
| 343 | + static bool printed; |
---|
| 344 | + if (printed) |
---|
| 345 | + putchar (' '); |
---|
| 346 | + printed = true; |
---|
| 347 | + fputs (element, stdout); |
---|
| 348 | +} |
---|
| 349 | + |
---|
| 350 | + |
---|
| 351 | +/* Set all the option flags according to the switches specified. |
---|
| 352 | + Return the mask indicating which elements to print. */ |
---|
| 353 | + |
---|
| 354 | +static int |
---|
| 355 | +decode_switches (int argc, char **argv) |
---|
| 356 | +{ |
---|
| 357 | + int c; |
---|
| 358 | + unsigned int toprint = 0; |
---|
| 359 | + |
---|
| 360 | + if (uname_mode == UNAME_ARCH) |
---|
| 361 | + { |
---|
| 362 | + while ((c = getopt_long (argc, argv, "", |
---|
| 363 | + arch_long_options, NULL)) != -1) |
---|
| 364 | + { |
---|
| 365 | + switch (c) |
---|
| 366 | + { |
---|
| 367 | + case_GETOPT_HELP_CHAR; |
---|
| 368 | + |
---|
| 369 | + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, ARCH_AUTHORS); |
---|
| 370 | + |
---|
| 371 | + default: |
---|
| 372 | + usage (EXIT_FAILURE); |
---|
| 373 | + } |
---|
| 374 | + } |
---|
| 375 | + toprint = PRINT_MACHINE; |
---|
| 376 | + } |
---|
| 377 | + else |
---|
| 378 | + { |
---|
| 379 | + while ((c = getopt_long (argc, argv, "asnrvmpio", |
---|
| 380 | + uname_long_options, NULL)) != -1) |
---|
| 381 | + { |
---|
| 382 | + switch (c) |
---|
| 383 | + { |
---|
| 384 | + case 'a': |
---|
| 385 | + toprint = UINT_MAX; |
---|
| 386 | + break; |
---|
| 387 | + |
---|
| 388 | + case 's': |
---|
| 389 | + toprint |= PRINT_KERNEL_NAME; |
---|
| 390 | + break; |
---|
| 391 | + |
---|
| 392 | + case 'n': |
---|
| 393 | + toprint |= PRINT_NODENAME; |
---|
| 394 | + break; |
---|
| 395 | + |
---|
| 396 | + case 'r': |
---|
| 397 | + toprint |= PRINT_KERNEL_RELEASE; |
---|
| 398 | + break; |
---|
| 399 | + |
---|
| 400 | + case 'v': |
---|
| 401 | + toprint |= PRINT_KERNEL_VERSION; |
---|
| 402 | + break; |
---|
| 403 | + |
---|
| 404 | + case 'm': |
---|
| 405 | + toprint |= PRINT_MACHINE; |
---|
| 406 | + break; |
---|
| 407 | + |
---|
| 408 | + case 'p': |
---|
| 409 | + toprint |= PRINT_PROCESSOR; |
---|
| 410 | + break; |
---|
| 411 | + |
---|
| 412 | + case 'i': |
---|
| 413 | + toprint |= PRINT_HARDWARE_PLATFORM; |
---|
| 414 | + break; |
---|
| 415 | + |
---|
| 416 | + case 'o': |
---|
| 417 | + toprint |= PRINT_OPERATING_SYSTEM; |
---|
| 418 | + break; |
---|
| 419 | + |
---|
| 420 | + case_GETOPT_HELP_CHAR; |
---|
| 421 | + |
---|
| 422 | + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); |
---|
| 423 | + |
---|
| 424 | + default: |
---|
| 425 | + usage (EXIT_FAILURE); |
---|
| 426 | + } |
---|
| 427 | + } |
---|
| 428 | + } |
---|
| 429 | + |
---|
| 430 | + if (argc != optind) |
---|
| 431 | + { |
---|
| 432 | + error (0, 0, _("extra operand %s"), quote (argv[optind])); |
---|
| 433 | + usage (EXIT_FAILURE); |
---|
| 434 | + } |
---|
| 435 | + |
---|
| 436 | + return toprint; |
---|
| 437 | +} |
---|
| 438 | + |
---|
| 439 | +int |
---|
| 440 | +main (int argc, char **argv) |
---|
| 441 | +{ |
---|
| 442 | + static char const unknown[] = "unknown"; |
---|
| 443 | + |
---|
| 444 | + /* Mask indicating which elements to print. */ |
---|
| 445 | + unsigned int toprint = 0; |
---|
| 446 | + |
---|
| 447 | + initialize_main (&argc, &argv); |
---|
| 448 | + set_program_name (argv[0]); |
---|
| 449 | + setlocale (LC_ALL, ""); |
---|
| 450 | + bindtextdomain (PACKAGE, LOCALEDIR); |
---|
| 451 | + textdomain (PACKAGE); |
---|
| 452 | + |
---|
| 453 | + atexit (close_stdout); |
---|
| 454 | + |
---|
| 455 | + toprint = decode_switches (argc, argv); |
---|
| 456 | + |
---|
| 457 | + if (toprint == 0) |
---|
| 458 | + toprint = PRINT_KERNEL_NAME; |
---|
| 459 | + |
---|
| 460 | + if (toprint |
---|
| 461 | + & (PRINT_KERNEL_NAME | PRINT_NODENAME | PRINT_KERNEL_RELEASE |
---|
| 462 | + | PRINT_KERNEL_VERSION | PRINT_MACHINE)) |
---|
| 463 | + { |
---|
| 464 | + struct utsname name; |
---|
| 465 | + |
---|
| 466 | + if (uname (&name) == -1) |
---|
| 467 | + error (EXIT_FAILURE, errno, _("cannot get system name")); |
---|
| 468 | + |
---|
| 469 | + if (toprint & PRINT_KERNEL_NAME) |
---|
| 470 | + print_element (name.sysname); |
---|
| 471 | + if (toprint & PRINT_NODENAME) |
---|
| 472 | + print_element (name.nodename); |
---|
| 473 | + if (toprint & PRINT_KERNEL_RELEASE) |
---|
| 474 | + print_element (name.release); |
---|
| 475 | + if (toprint & PRINT_KERNEL_VERSION) |
---|
| 476 | + print_element (name.version); |
---|
| 477 | + if (toprint & PRINT_MACHINE) |
---|
| 478 | + print_element (name.machine); |
---|
| 479 | + } |
---|
| 480 | + |
---|
| 481 | + if (toprint & PRINT_PROCESSOR) |
---|
| 482 | + { |
---|
| 483 | + char const *element = unknown; |
---|
| 484 | +#if HAVE_SYSINFO && defined SI_ARCHITECTURE |
---|
| 485 | + { |
---|
| 486 | + static char processor[257]; |
---|
| 487 | + if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) |
---|
| 488 | + element = processor; |
---|
| 489 | + } |
---|
| 490 | +#endif |
---|
| 491 | +#ifdef UNAME_PROCESSOR |
---|
| 492 | + if (element == unknown) |
---|
| 493 | + { |
---|
| 494 | + static char processor[257]; |
---|
| 495 | + size_t s = sizeof processor; |
---|
| 496 | + static int mib[] = { CTL_HW, UNAME_PROCESSOR }; |
---|
| 497 | + if (sysctl (mib, 2, processor, &s, 0, 0) >= 0) |
---|
| 498 | + element = processor; |
---|
| 499 | + |
---|
| 500 | +# ifdef __APPLE__ |
---|
| 501 | + /* This kludge works around a bug in Mac OS X. */ |
---|
| 502 | + if (element == unknown) |
---|
| 503 | + { |
---|
| 504 | + cpu_type_t cputype; |
---|
| 505 | + size_t s = sizeof cputype; |
---|
| 506 | + NXArchInfo const *ai; |
---|
| 507 | + if (sysctlbyname ("hw.cputype", &cputype, &s, NULL, 0) == 0 |
---|
| 508 | + && (ai = NXGetArchInfoFromCpuType (cputype, |
---|
| 509 | + CPU_SUBTYPE_MULTIPLE)) |
---|
| 510 | + != NULL) |
---|
| 511 | + element = ai->name; |
---|
| 512 | + |
---|
| 513 | + /* Hack "safely" around the ppc vs. powerpc return value. */ |
---|
| 514 | + if (cputype == CPU_TYPE_POWERPC |
---|
| 515 | + && STRNCMP_LIT (element, "ppc") == 0) |
---|
| 516 | + element = "powerpc"; |
---|
| 517 | + } |
---|
| 518 | +# endif |
---|
| 519 | + } |
---|
| 520 | +#endif |
---|
| 521 | + if (! (toprint == UINT_MAX && element == unknown)) |
---|
| 522 | + print_element (element); |
---|
| 523 | + } |
---|
| 524 | + |
---|
| 525 | + if (toprint & PRINT_HARDWARE_PLATFORM) |
---|
| 526 | + { |
---|
| 527 | + char const *element = unknown; |
---|
| 528 | +#if HAVE_SYSINFO && defined SI_PLATFORM |
---|
| 529 | + { |
---|
| 530 | + static char hardware_platform[257]; |
---|
| 531 | + if (0 <= sysinfo (SI_PLATFORM, |
---|
| 532 | + hardware_platform, sizeof hardware_platform)) |
---|
| 533 | + element = hardware_platform; |
---|
| 534 | + } |
---|
| 535 | +#endif |
---|
| 536 | +#ifdef UNAME_HARDWARE_PLATFORM |
---|
| 537 | + if (element == unknown) |
---|
| 538 | + { |
---|
| 539 | + static char hardware_platform[257]; |
---|
| 540 | + size_t s = sizeof hardware_platform; |
---|
| 541 | + static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; |
---|
| 542 | + if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) |
---|
| 543 | + element = hardware_platform; |
---|
| 544 | + } |
---|
| 545 | +#endif |
---|
| 546 | + if (! (toprint == UINT_MAX && element == unknown)) |
---|
| 547 | + print_element (element); |
---|
| 548 | + } |
---|
| 549 | + |
---|
| 550 | + if (toprint & PRINT_OPERATING_SYSTEM) |
---|
| 551 | + print_element (HOST_OPERATING_SYSTEM); |
---|
| 552 | + |
---|
| 553 | + putchar ('\n'); |
---|
| 554 | + |
---|
| 555 | + exit (EXIT_SUCCESS); |
---|
| 556 | +} |
---|