source: patches/coreutils-8.11-uname-1.patch@ a092f8af

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since a092f8af was 26f3d5db, checked in by Joe Ciccone <jciccone@…>, 14 years ago

Updated Coreutils to 8.11.

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