source: patches/coreutils-8.20-uname-1.patch@ ee47e58

clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since ee47e58 was 3ddeb23, checked in by William Harrington <kb0iic@…>, 12 years ago

Update coreutils patch header information.

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