source: clfs-sysroot/patches/coreutils-7.4-uname-1.patch@ cf44b18

Last change on this file since cf44b18 was 9e7e74c, checked in by Joe Ciccone <jciccone@…>, 15 years ago

Updated Coreutils to 7.4.

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