source: patches/coreutils-8.22-uname-1.patch@ 4260133

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

Rename coreutils 8.21 uname patch to coreutils 8.22 and add entry into patch header for rename.

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