source: patches/coreutils-8.16-uname-1.patch@ a518847

clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since a518847 was de4abd5, checked in by Jonathan Norman <jon@…>, 13 years ago

Rediffed coreutils uname patch for 8.16

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