source: patches/coreutils-6.12-uname-1.patch@ 4ea666a

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 4ea666a was 7b31c44, checked in by Joe Ciccone <jciccone@…>, 16 years ago

Updated Coreutils to 6.12.
Drop Mktemp in favor of the version included in Coreutils.
Updated Perl to 5.10.0.
Updated File to 4.25.
Updated File to 4.26.
Updated GCC to 4.3.2.

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[f74ae22]1Submitted By: Jim Gifford <jim at linuxfromscratch dot org>
2Date: 2006-08-24
3Initial Package Version: 5.97
[7b31c44]4 Rediffed against 6.12 by Joe Ciccone on 2008-08-30
[f74ae22]5Upstream Status: Not Accepted
6Origin: Gentoo - http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/coreutils
7Description: Display CPU Information from /proc/cpuinfo or /proc/sysinfo
8
9Original Patch by - Matthew Burgess and Scot McPherson
10
[7b31c44]11diff -Naur coreutils-6.12.orig/src/uname.c coreutils-6.12/src/uname.c
12--- coreutils-6.12.orig/src/uname.c 2008-05-26 02:40:33.000000000 -0400
13+++ coreutils-6.12/src/uname.c 2008-08-31 12:03:12.000000000 -0400
14@@ -50,6 +50,11 @@
[f74ae22]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"
[7b31c44]26@@ -158,6 +163,106 @@
[f74ae22]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);
55+}
56+
57+static int __linux_procinfo (int x, char *fstr, size_t s)
58+{
59+ FILE *fp;
60+
61+ char *procinfo_keys[] = {
62+ /* --processor --hardware-platform */
63+ #if defined(__alpha__)
64+ "cpu model", "system type"
65+ #elif defined(__arm__)
66+ "Processor", "Hardware"
67+ #elif defined(bfin)
68+ "CPU", "BOARD Name"
69+ #elif defined(__cris__)
70+ "cpu", "cpu model"
71+ #elif defined(__frv__)
72+ "CPU-Core", "System"
73+ #elif defined(__i386__) || defined(__x86_64__)
74+ "model name", "vendor_id"
75+ #elif defined(__ia64__)
76+ "family", "vendor"
77+ #elif defined(__hppa__)
78+ "cpu", "model"
79+ #elif defined(__m68k__)
80+ "CPU", "MMU"
81+ #elif defined(__mips__)
82+ "cpu model", "system type"
83+ #elif defined(__powerpc__) || defined(__powerpc64__)
84+ "cpu", "machine"
85+ #elif defined(__s390__) || defined(__s390x__)
86+ "Type", "Manufacturer"
87+ #elif defined(__sh__)
88+ "cpu type", "machine"
89+ #elif defined(sparc) || defined(__sparc__)
90+ "type", "cpu"
91+ #elif defined(__vax__)
92+ "cpu type", "cpu"
93+ #else
94+ "unknown", "unknown"
95+ #endif
96+ };
97+
98+ if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
99+ char key[65], value[257], eol, *ret = NULL;
100+
101+ while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
102+ __eat_cpuinfo_space(key);
103+ if (!strcmp(key, procinfo_keys[x])) {
104+ __eat_cpuinfo_space(value);
105+ ret = value;
106+ break;
107+ }
108+ if (eol != '\n') {
109+ /* we need two fscanf's here in case the previous
110+ * length limit caused us to read right up to the
111+ * newline ... doing "%*[^\n]\n" wont eat the newline
112+ */
113+ fscanf(fp, "%*[^\n]");
114+ fscanf(fp, "\n");
115+ }
116+ }
117+ fclose(fp);
118+
119+ if (ret) {
120+ strncpy(fstr, ret, s);
121+ return 0;
122+ }
123+ }
124+
125+ return -1;
126+}
127+
128+#endif
129+
130 /* Print ELEMENT, preceded by a space if something has already been
131 printed. */
132
[7b31c44]133@@ -305,10 +410,14 @@
[f74ae22]134 if (toprint & PRINT_PROCESSOR)
135 {
136 char const *element = unknown;
137-#if HAVE_SYSINFO && defined SI_ARCHITECTURE
138+#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
139 {
140 static char processor[257];
141+#if defined(USE_PROCINFO)
142+ if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
143+#else
144 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
145+#endif
146 element = processor;
147 }
148 #endif
[7b31c44]149@@ -361,9 +470,13 @@
[f74ae22]150 if (element == unknown)
151 {
152 static char hardware_platform[257];
153+#if defined(USE_PROCINFO)
154+ if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
155+#else
156 size_t s = sizeof hardware_platform;
157 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
158 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
159+#endif
160 element = hardware_platform;
161 }
162 #endif
Note: See TracBrowser for help on using the repository browser.