]>
Commit | Line | Data |
---|---|---|
e1fb4052 MF |
1 | Submitted by: DJ Lucas (dj_at_linuxfromscratch_dot_org) |
2 | Date: 2012-04-21 | |
3 | Initial Package Version: 8.16 | |
4 | Upstream Status: Rejected | |
5 | Origin: Based on Gentoo patch | |
6 | Description: Makes uname -m output more descriptive | |
7 | ||
8 | diff -Naurp coreutils-8.16-orig/src/uname.c coreutils-8.16/src/uname.c | |
9 | --- coreutils-8.16-orig/src/uname.c 2012-04-22 20:02:39.000000000 +0000 | |
10 | +++ coreutils-8.16/src/uname.c 2012-04-22 20:02:50.000000000 +0000 | |
11 | @@ -49,6 +49,11 @@ | |
12 | # include <mach-o/arch.h> | |
13 | #endif | |
14 | ||
15 | +#if defined(__linux__) | |
16 | +# define USE_PROCINFO | |
17 | +# define UNAME_HARDWARE_PLATFORM | |
18 | +#endif | |
19 | + | |
20 | #include "system.h" | |
21 | #include "die.h" | |
22 | #include "error.h" | |
23 | @@ -153,6 +158,117 @@ Print machine architecture.\n\ | |
24 | exit (status); | |
25 | } | |
26 | ||
27 | +#if defined(USE_PROCINFO) | |
28 | + | |
29 | +# if defined(__s390__) || defined(__s390x__) | |
30 | +# define CPUINFO_FILE "/proc/sysinfo" | |
31 | +# define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c" | |
32 | +# else | |
33 | +# define CPUINFO_FILE "/proc/cpuinfo" | |
34 | +# define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c" | |
35 | +# endif | |
36 | + | |
37 | +# define PROCINFO_PROCESSOR 0 | |
38 | +# define PROCINFO_HARDWARE_PLATFORM 1 | |
39 | + | |
40 | +static void __eat_cpuinfo_space(char *buf) | |
41 | +{ | |
42 | + /* first eat trailing space */ | |
43 | + char *tmp = buf + strlen(buf) - 1; | |
44 | + while (tmp > buf && isspace(*tmp)) | |
45 | + *tmp-- = '\0'; | |
46 | + /* then eat leading space */ | |
47 | + tmp = buf; | |
48 | + while (*tmp && isspace(*tmp)) | |
49 | + tmp++; | |
50 | + if (tmp != buf) | |
51 | + memmove(buf, tmp, strlen(tmp)+1); | |
52 | + /* finally collapse whitespace */ | |
53 | + tmp = buf; | |
54 | + while (tmp[0] && tmp[1]) { | |
55 | + if (isspace(tmp[0]) && isspace(tmp[1])) { | |
56 | + memmove(tmp, tmp+1, strlen(tmp)); | |
57 | + continue; | |
58 | + } | |
59 | + ++tmp; | |
60 | + } | |
61 | +} | |
62 | + | |
63 | +static int __linux_procinfo(int x, char *fstr, size_t s) | |
64 | +{ | |
65 | + FILE *fp; | |
66 | + | |
67 | + char *procinfo_keys[] = { | |
68 | + /* --processor --hardware-platform */ | |
69 | + #if defined(__alpha__) | |
70 | + "cpu model", "system type" | |
71 | + #elif defined(__arm__) | |
72 | + "Processor", "Hardware" | |
73 | + #elif defined(__avr32__) | |
74 | + "processor", "cpu family" | |
75 | + #elif defined(__bfin__) | |
76 | + "CPU", "BOARD Name" | |
77 | + #elif defined(__cris__) | |
78 | + "cpu", "cpu model" | |
79 | + #elif defined(__frv__) | |
80 | + "CPU-Core", "System" | |
81 | + #elif defined(__i386__) || defined(__x86_64__) | |
82 | + "model name", "vendor_id" | |
83 | + #elif defined(__ia64__) | |
84 | + "family", "vendor" | |
85 | + #elif defined(__hppa__) | |
86 | + "cpu", "model" | |
87 | + #elif defined(__m68k__) | |
88 | + "CPU", "MMU" | |
89 | + #elif defined(__mips__) | |
90 | + "cpu model", "system type" | |
91 | + #elif defined(__powerpc__) || defined(__powerpc64__) | |
92 | + "cpu", "machine" | |
93 | + #elif defined(__s390__) || defined(__s390x__) | |
94 | + "Type", "Manufacturer" | |
95 | + #elif defined(__sh__) | |
96 | + "cpu type", "machine" | |
97 | + #elif defined(sparc) || defined(__sparc__) | |
98 | + "type", "cpu" | |
99 | + #elif defined(__vax__) | |
100 | + "cpu type", "cpu" | |
101 | + #else | |
102 | + "unknown", "unknown" | |
103 | + #endif | |
104 | + }; | |
105 | + | |
106 | + if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) { | |
107 | + char key[65], value[257], eol, *ret = NULL; | |
108 | + | |
109 | + while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) { | |
110 | + __eat_cpuinfo_space(key); | |
111 | + if (!strcmp(key, procinfo_keys[x])) { | |
112 | + __eat_cpuinfo_space(value); | |
113 | + ret = value; | |
114 | + break; | |
115 | + } | |
116 | + if (eol != '\n') { | |
117 | + /* we need two fscanf's here in case the previous | |
118 | + * length limit caused us to read right up to the | |
119 | + * newline ... doing "%*[^\n]\n" wont eat the newline | |
120 | + */ | |
121 | + fscanf(fp, "%*[^\n]"); | |
122 | + fscanf(fp, "\n"); | |
123 | + } | |
124 | + } | |
125 | + fclose(fp); | |
126 | + | |
127 | + if (ret) { | |
128 | + strncpy(fstr, ret, s); | |
129 | + return 0; | |
130 | + } | |
131 | + } | |
132 | + | |
133 | + return -1; | |
134 | +} | |
135 | + | |
136 | +#endif | |
137 | + | |
138 | /* Print ELEMENT, preceded by a space if something has already been | |
139 | printed. */ | |
140 | ||
141 | @@ -300,10 +416,14 @@ main (int argc, char **argv) | |
142 | if (toprint & PRINT_PROCESSOR) | |
143 | { | |
144 | char const *element = unknown; | |
145 | -#if HAVE_SYSINFO && defined SI_ARCHITECTURE | |
146 | +#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) | |
147 | { | |
148 | static char processor[257]; | |
149 | +#if defined(USE_PROCINFO) | |
150 | + if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) | |
151 | +#else | |
152 | if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) | |
153 | +#endif | |
154 | element = processor; | |
155 | } | |
156 | #endif | |
157 | @@ -356,9 +476,13 @@ main (int argc, char **argv) | |
158 | if (element == unknown) | |
159 | { | |
160 | static char hardware_platform[257]; | |
161 | +#if defined(USE_PROCINFO) | |
162 | + if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform)) | |
163 | +#else | |
164 | size_t s = sizeof hardware_platform; | |
165 | static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; | |
166 | if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) | |
167 | +#endif | |
168 | element = hardware_platform; | |
169 | } | |
170 | #endif |