Magellan Linux

Contents of /trunk/coreutils/patches-5.94/coreutils-5.3.0-uname.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 115 - (show annotations) (download)
Sun Mar 18 15:57:37 2007 UTC (17 years, 1 month ago) by niro
File size: 3319 byte(s)
patches for 5.94

1 On linux platforms, grok /proc/cpuinfo for the CPU/vendor info.
2
3 Prob not suitable for upstream seeing as how it's 100% linux-specific
4
5 Patch originally by Carlos E. Gorges <carlos@techlinux.com.br>, but
6 heavily reworked to suck less.
7
8 --- coreutils/src/uname.c
9 +++ coreutils/src/uname.c
10 @@ -44,6 +44,11 @@
11 # include <mach-o/arch.h>
12 #endif
13
14 +#if defined (__linux__)
15 +# define USE_PROCINFO
16 +# define UNAME_HARDWARE_PLATFORM
17 +#endif
18 +
19 #include "system.h"
20 #include "error.h"
21 #include "quote.h"
22 @@ -129,6 +134,84 @@
23 exit (status);
24 }
25
26 +#if defined(USE_PROCINFO)
27 +
28 +# if defined(__s390__) || defined(__s390x__)
29 +# define CPUINFO_FILE "/proc/sysinfo"
30 +# define CPUINFO_FORMAT "%[^\t :]%*[ :]%[^\n]\n"
31 +# else
32 +# define CPUINFO_FILE "/proc/cpuinfo"
33 +# define CPUINFO_FORMAT "%[^\t:]\t:%[^\n]\n"
34 +# endif
35 +
36 +# define PROCINFO_ARCHITECTURE 0
37 +# define PROCINFO_HARDWARE_PLATFORM 1
38 +
39 +static void __eat_trailing_space(char *buf)
40 +{
41 + char *tmp = buf + strlen(buf) - 1;
42 + while (tmp > buf && isspace(*tmp))
43 + *tmp-- = '\0';
44 +}
45 +
46 +static int __linux_procinfo (int x, char *fstr)
47 +{
48 + FILE *fp;
49 +
50 + char *procinfo_keys[] = {
51 + #if defined(__i386__) || defined(__x86_64__)
52 + "model name", "vendor_id"
53 + #elif defined(__ia64__)
54 + "model", "vendor"
55 + #elif defined(__alpha__)
56 + "cpu model", "system type"
57 + #elif defined(sparc) || defined(__sparc__)
58 + "type", "cpu"
59 + #elif defined(__hppa__)
60 + "cpu", "model"
61 + #elif defined(__mips__)
62 + "cpu model", "system type"
63 + #elif defined(__powerpc__) || defined(__powerpc64__)
64 + "cpu", "machine"
65 + #elif defined(__arm__)
66 + "Processor", "Hardware"
67 + #elif defined(__s390__) || defined(__s390x__)
68 + "Type", "Manufacturer"
69 + #elif defined(__sh__)
70 + "cpu family", "Machine"
71 + #elif defined(__m68k__)
72 + "CPU", "MMU"
73 + #elif defined(__cris__)
74 + "cpu", "cpu model"
75 + #else
76 + "???", "???"
77 + #endif
78 + };
79 +
80 + if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
81 + char key[64], value[257], *ret = NULL;
82 +
83 + while (fscanf(fp, CPUINFO_FORMAT, key, value) != EOF) {
84 + __eat_trailing_space(key);
85 + if (!strcmp(key, procinfo_keys[x])) {
86 + __eat_trailing_space(value);
87 + ret = value + (isblank(*value) ? 1 : 0);
88 + break;
89 + }
90 + }
91 + fclose(fp);
92 +
93 + if (ret) {
94 + strncpy(fstr, ret, 257);
95 + return 0;
96 + }
97 + }
98 +
99 + return -1;
100 +}
101 +
102 +#endif
103 +
104 /* Print ELEMENT, preceded by a space if something has already been
105 printed. */
106
107 @@ -243,10 +328,14 @@
108 if (toprint & PRINT_PROCESSOR)
109 {
110 char const *element = unknown;
111 -#if HAVE_SYSINFO && defined SI_ARCHITECTURE
112 +#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
113 {
114 static char processor[257];
115 +#if defined(USE_PROCINFO)
116 + if (0 <= __linux_procinfo (PROCINFO_ARCHITECTURE, processor))
117 +#else
118 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
119 +#endif
120 element = processor;
121 }
122 #endif
123 @@ -278,9 +369,13 @@
124 if (element == unknown)
125 {
126 static char hardware_platform[257];
127 +#if defined(USE_PROCINFO)
128 + if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform))
129 +#else
130 size_t s = sizeof hardware_platform;
131 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
132 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
133 +#endif
134 element = hardware_platform;
135 }
136 #endif