source: patches/coreutils-8.23-uname-1.patch@ 2315dc8

sysvinit
Last change on this file since 2315dc8 was fdb2795, checked in by William Harrington <kb0iic@…>, 10 years ago

Add Coreutils 8.23 uname patch for 8.23 version upgrade.

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