source: patches/coreutils-8.21-uname-1.patch@ 8d9474c2

clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 8d9474c2 was 7718031, checked in by William Harrington <kb0iic@…>, 11 years ago

Update coreutils uname patch.

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[7718031]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
13Rediffed for 8.19 by William Harrington - 2012-08-27
14Renamed for 8.20 by William Harrington - 2012-11-01
15Rediffed for 8.21 by William Harrington 2013-05-31
16
17diff -Naur coreutils-8.21.orig/src/uname.c coreutils-8.21/src/uname.c
18--- coreutils-8.21.orig/src/uname.c 2013-01-31 00:46:24.000000000 +0000
19+++ coreutils-8.21/src/uname.c 2013-05-31 13:41:32.683326834 +0000
20@@ -49,6 +49,11 @@
21 # include <mach-o/arch.h>
22 #endif
23
24+#if defined (__linux__)
25+# define USE_PROCINFO
26+# define UNAME_HARDWARE_PLATFORM
27+#endif
28+
29 #include "system.h"
30 #include "error.h"
31 #include "quote.h"
32@@ -153,6 +158,117 @@
33 exit (status);
34 }
35
36+#if defined(USE_PROCINFO)
37+
38+# if defined(__s390__) || defined(__s390x__)
39+# define CPUINFO_FILE "/proc/sysinfo"
40+# define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c"
41+# else
42+# define CPUINFO_FILE "/proc/cpuinfo"
43+# define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c"
44+# endif
45+
46+# define PROCINFO_PROCESSOR 0
47+# define PROCINFO_HARDWARE_PLATFORM 1
48+
49+static void __eat_cpuinfo_space(char *buf)
50+{
51+ /* first eat trailing space */
52+ char *tmp = buf + strlen(buf) - 1;
53+ while (tmp > buf && isspace(*tmp))
54+ *tmp-- = '\0';
55+ /* then eat leading space */
56+ tmp = buf;
57+ while (*tmp && isspace(*tmp))
58+ tmp++;
59+ if (tmp != buf)
60+ memmove(buf, tmp, strlen(tmp)+1);
61+ /* finally collapse whitespace */
62+ tmp = buf;
63+ while (tmp[0] && tmp[1]) {
64+ if (isspace(tmp[0]) && isspace(tmp[1])) {
65+ memmove(tmp, tmp+1, strlen(tmp));
66+ continue;
67+ }
68+ ++tmp;
69+ }
70+}
71+
72+static int __linux_procinfo (int x, char *fstr, size_t s)
73+{
74+ FILE *fp;
75+
76+ char *procinfo_keys[] = {
77+ /* --processor --hardware-platform */
78+ #if defined(__alpha__)
79+ "cpu model", "system type"
80+ #elif defined(__arm__)
81+ "Processor", "Hardware"
82+ #elif defined(__avr32__)
83+ "processor", "cpu family"
84+ #elif defined(__bfin__)
85+ "CPU", "BOARD Name"
86+ #elif defined(__cris__)
87+ "cpu", "cpu model"
88+ #elif defined(__frv__)
89+ "CPU-Core", "System"
90+ #elif defined(__i386__) || defined(__x86_64__)
91+ "model name", "vendor_id"
92+ #elif defined(__ia64__)
93+ "family", "vendor"
94+ #elif defined(__hppa__)
95+ "cpu", "model"
96+ #elif defined(__m68k__)
97+ "CPU", "MMU"
98+ #elif defined(__mips__)
99+ "cpu model", "system type"
100+ #elif defined(__powerpc__) || defined(__powerpc64__)
101+ "cpu", "machine"
102+ #elif defined(__s390__) || defined(__s390x__)
103+ "Type", "Manufacturer"
104+ #elif defined(__sh__)
105+ "cpu type", "machine"
106+ #elif defined(sparc) || defined(__sparc__)
107+ "type", "cpu"
108+ #elif defined(__vax__)
109+ "cpu type", "cpu"
110+ #else
111+ "unknown", "unknown"
112+ #endif
113+ };
114+
115+ if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
116+ char key[65], value[257], eol, *ret = NULL;
117+
118+ while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
119+ __eat_cpuinfo_space(key);
120+ if (!strcmp(key, procinfo_keys[x])) {
121+ __eat_cpuinfo_space(value);
122+ ret = value;
123+ break;
124+ }
125+ if (eol != '\n') {
126+ /* we need two fscanf's here in case the previous
127+ * length limit caused us to read right up to the
128+ * newline ... doing "%*[^\n]\n" wont eat the newline
129+ */
130+ fscanf(fp, "%*[^\n]");
131+ fscanf(fp, "\n");
132+ }
133+ }
134+ fclose(fp);
135+
136+ if (ret) {
137+ strncpy(fstr, ret, s);
138+ return 0;
139+ }
140+ }
141+
142+ return -1;
143+}
144+
145+#endif
146+
147 /* Print ELEMENT, preceded by a space if something has already been
148 printed. */
149
150@@ -300,10 +416,14 @@
151 if (toprint & PRINT_PROCESSOR)
152 {
153 char const *element = unknown;
154-#if HAVE_SYSINFO && defined SI_ARCHITECTURE
155+#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
156 {
157 static char processor[257];
158+#if defined(USE_PROCINFO)
159+ if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
160+#else
161 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
162+#endif
163 element = processor;
164 }
165 #endif
166@@ -356,9 +476,13 @@
167 if (element == unknown)
168 {
169 static char hardware_platform[257];
170+#if defined(USE_PROCINFO)
171+ if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
172+#else
173 size_t s = sizeof hardware_platform;
174 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
175 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
176+#endif
177 element = hardware_platform;
178 }
179 #endif
Note: See TracBrowser for help on using the repository browser.