]>
Commit | Line | Data |
---|---|---|
2aa7d974 JR |
1 | diff -ur rpm-4.16.0/lib/depends.c rpm-4.16.0-cpuinfo/lib/depends.c |
2 | --- rpm-4.16.0/lib/depends.c 2020-11-08 20:19:15.625093667 +0100 | |
3 | +++ rpm-4.16.0-cpuinfo/lib/depends.c 2020-11-08 20:23:46.685893216 +0100 | |
4 | @@ -697,6 +697,16 @@ | |
5 | } | |
6 | } | |
7 | ||
8 | + if (strstr(N, "cpuinfo(") == N) { | |
9 | + if (tsmem->cpuinfo == NULL) | |
10 | + rpmdsCpuinfoPool(rpmtsPool(ts), &(tsmem->cpuinfo)); | |
11 | + | |
12 | + if (tsmem->cpuinfo != NULL && rpmdsSearch(tsmem->cpuinfo, dep) >= 0) { | |
13 | + rpmdsNotify(dep, "(cpuinfo provides)", rc); | |
14 | + goto exit; | |
15 | + } | |
16 | + } | |
17 | + | |
18 | /* Dont look at pre-requisites of already installed packages */ | |
19 | if (!adding && isTransientReq(dsflags)) | |
20 | goto exit; | |
21 | diff -ur rpm-4.16.0/lib/rpmds.c rpm-4.16.0-cpuinfo/lib/rpmds.c | |
22 | --- rpm-4.16.0/lib/rpmds.c 2020-11-08 20:19:15.625093667 +0100 | |
23 | +++ rpm-4.16.0-cpuinfo/lib/rpmds.c 2020-11-08 20:16:25.941242497 +0100 | |
24 | @@ -2,6 +2,8 @@ | |
25 | * \file lib/rpmds.c | |
26 | */ | |
27 | #include "system.h" | |
28 | +#include <popt.h> | |
29 | +#include <ctype.h> | |
30 | #include <sys/utsname.h> | |
31 | ||
32 | #include <rpm/rpmtypes.h> | |
33 | @@ -9,6 +11,9 @@ | |
34 | #include <rpm/rpmstring.h> | |
35 | #include <rpm/rpmlog.h> | |
36 | #include <rpm/rpmstrpool.h> | |
37 | +#include <rpm/rpmmacro.h> | |
38 | + | |
39 | +#include "rpmio/rpmio_internal.h" /* XXX for rpmioSlurp */ | |
40 | ||
41 | #include "lib/rpmds_internal.h" | |
42 | ||
43 | @@ -1655,3 +1670,203 @@ | |
44 | { | |
45 | return rpmdsUnamePool(NULL, dsp); | |
46 | } | |
47 | + | |
48 | +struct cpuinfo_s { | |
49 | + const char *name; | |
50 | + int done; | |
51 | + int flags; | |
52 | +}; | |
53 | + | |
54 | +static struct cpuinfo_s ctags[] = { | |
55 | + { "processor", 0, 0 }, | |
56 | + { "Processor", 0, 1 }, /* XXX armv5 */ | |
57 | + { "vendor_id", 0, 0 }, | |
58 | + { "cpu_family", 0, 1 }, | |
59 | + { "model", 0, 1 }, | |
60 | + { "model_name", 0, 0 }, | |
61 | + { "stepping", 0, 1 }, | |
62 | + { "cpu_MHz", 0, 1 }, | |
63 | + { "CPU_implementer",0, 1 }, /* XXX armv5 */ | |
64 | + { "CPU_architecture",0, 1 }, /* XXX armv5 */ | |
65 | + { "CPU_variant", 0, 1 }, /* XXX armv5 */ | |
66 | + { "CPU_part", 0, 1 }, /* XXX armv5 */ | |
67 | + { "CPU_revision", 0, 1 }, /* XXX armv5 */ | |
68 | + { "Hardware", 0, 2 }, /* XXX armv5 */ | |
69 | + { "Revision", 0, 1 }, /* XXX armv5 */ | |
70 | + { "Serial", 0, 1 }, /* XXX armv5 */ | |
71 | + { "cache_size", 0, 1 }, | |
72 | + { "physical_id", 0, 0 }, | |
73 | + { "siblings", 0, 0 }, | |
74 | + { "core_id", 0, 0 }, | |
75 | + { "cpu_cores", 0, 0 }, | |
76 | + { "fdiv_bug", 0, 3 }, | |
77 | + { "hlt_bug", 0, 3 }, | |
78 | + { "f00f_bug", 0, 3 }, | |
79 | + { "coma_bug", 0, 3 }, | |
80 | + { "fpu", 0, 0 }, /* XXX use flags attribute instead. */ | |
81 | + { "fpu_exception", 0, 3 }, | |
82 | + { "cpuid_level", 0, 0 }, | |
83 | + { "wp", 0, 3 }, | |
84 | + { "flags", 0, 4 }, | |
85 | + { "Features", 0, 4 }, /* XXX armv5 */ | |
86 | + { "bogomips", 0, 1 }, | |
87 | + { "BogoMIPS", 0, 1 }, /* XXX armv5 */ | |
88 | + { "clflush_size", 0, 1 }, | |
89 | + { NULL, 0, -1 } | |
90 | +}; | |
91 | + | |
92 | +/** | |
93 | + * Return dependency format to use for a cpuinfo line. | |
94 | + * @param name field name | |
95 | + * @return type of format (0 == ignore, -1 == not found) | |
96 | + */ | |
97 | +static int rpmdsCpuinfoCtagFlags(const char * name) | |
98 | +{ | |
99 | + struct cpuinfo_s * ct; | |
100 | + int flags = -1; | |
101 | + | |
102 | + for (ct = ctags; ct->name != NULL; ct++) { | |
103 | + if (strcmp(ct->name, name)) | |
104 | + continue; | |
105 | + if (ct->done) | |
106 | + continue; | |
107 | + ct->done = 1; /* XXX insure single occurrence */ | |
108 | + flags = ct->flags; | |
109 | + break; | |
110 | + } | |
111 | + return flags; | |
112 | +} | |
113 | + | |
114 | +#define _PROC_CPUINFO "/proc/cpuinfo" | |
115 | + | |
116 | +int rpmdsCpuinfoPool(rpmstrPool pool, rpmds *dsp) | |
117 | +{ | |
118 | + char * cpuinfo_path = NULL; | |
119 | + struct cpuinfo_s * ct; | |
120 | + const char * NS = "cpuinfo"; | |
121 | + char * iob = NULL; | |
122 | + char * f, * fe, * fend; | |
123 | + char * g, * ge; | |
124 | + char * t; | |
125 | + int rc = -1; | |
126 | + | |
127 | + cpuinfo_path = rpmExpand("%{?_rpmds_cpuinfo_path}", NULL); | |
128 | + /* XXX may need to validate path existence somewhen. */ | |
129 | + if (cpuinfo_path == NULL || *cpuinfo_path != '/') { | |
130 | + cpuinfo_path = _free(cpuinfo_path); | |
131 | + cpuinfo_path = xstrdup(_PROC_CPUINFO); | |
132 | + } | |
133 | + | |
134 | + /* Reset done variables. */ | |
135 | + for (ct = ctags; ct->name != NULL; ct++) | |
136 | + ct->done = 0; | |
137 | + | |
138 | + rc = rpmioSlurp(cpuinfo_path, (uint8_t **) &iob, NULL); | |
139 | + if (rc != 0 || iob == NULL) | |
140 | + goto exit; | |
141 | + | |
142 | + for (f = (char *)iob; *f != '\0'; f = fend) { | |
143 | + /* find EOL */ | |
144 | + fe = f; | |
145 | + while (*fe != '\0' && !(*fe == '\n' || *fe == '\r')) | |
146 | + fe++; | |
147 | + ge = fe; | |
148 | + while (*fe != '\0' && (*fe == '\n' || *fe == '\r')) | |
149 | + *fe++ = '\0'; | |
150 | + fend = fe; | |
151 | + | |
152 | + /* rtrim on line. */ | |
153 | + while (--ge > f && isspace(*ge)) | |
154 | + *ge = '\0'; | |
155 | + | |
156 | + /* ltrim on line. */ | |
157 | + while (*f && isspace(*f)) | |
158 | + f++; | |
159 | + | |
160 | + /* split on ':' */ | |
161 | + fe = f; | |
162 | + while (*fe && *fe != ':') | |
163 | + fe++; | |
164 | + if (*fe == '\0') | |
165 | + continue; | |
166 | + g = fe + 1; | |
167 | + | |
168 | + /* rtrim on field 1. */ | |
169 | + *fe = '\0'; | |
170 | + while (--fe > f && isspace(*fe)) | |
171 | + *fe = '\0'; | |
172 | + if (*f == '\0') | |
173 | + continue; | |
174 | + | |
175 | + /* ltrim on field 2. */ | |
176 | + while (*g && isspace(*g)) | |
177 | + g++; | |
178 | + if (*g == '\0') | |
179 | + continue; | |
180 | + | |
181 | + for (t = f; *t != '\0'; t++) { | |
182 | + if (isspace(*t)) | |
183 | + *t = '_'; | |
184 | + } | |
185 | + | |
186 | + switch (rpmdsCpuinfoCtagFlags(f)) { | |
187 | + case -1: /* not found */ | |
188 | + case 0: /* ignore */ | |
189 | + default: | |
190 | + continue; | |
191 | + break; | |
192 | + case 1: /* Provides: cpuinfo(f) = g */ | |
193 | + for (t = g; *t != '\0'; t++) { | |
194 | + if (isspace(*t) || *t == '(' || *t == ')') | |
195 | + *t = '_'; | |
196 | + } | |
197 | + rc = rpmdsNSAdd(pool, dsp, NS, f, g, RPMSENSE_EQUAL); | |
198 | + if (rc < 0) | |
199 | + goto exit; | |
200 | + break; | |
201 | + case 2: /* Provides: cpuinfo(g) */ | |
202 | + for (t = g; *t != '\0'; t++) { | |
203 | + if (isspace(*t) || *t == '(' || *t == ')') | |
204 | + *t = '_'; | |
205 | + } | |
206 | + rc = rpmdsNSAdd(pool, dsp, NS, g, "", RPMSENSE_ANY); | |
207 | + if (rc < 0) | |
208 | + goto exit; | |
209 | + break; | |
210 | + case 3: /* if ("yes") Provides: cpuinfo(f) */ | |
211 | + if (!strcmp(g, "yes")) { | |
212 | + rc = rpmdsNSAdd(pool, dsp, NS, f, "", RPMSENSE_ANY); | |
213 | + if (rc < 0) | |
214 | + goto exit; | |
215 | + } | |
216 | + break; | |
217 | + case 4: /* Provides: cpuinfo(g[i]) */ | |
218 | + { char ** av = NULL; | |
219 | + int i = 0; | |
220 | + rc = poptParseArgvString(g, NULL, (const char ***)&av); | |
221 | + if (!rc && av != NULL) | |
222 | + while ((t = av[i++]) != NULL) { | |
223 | + rc = rpmdsNSAdd(pool, dsp, NS, t, "", RPMSENSE_ANY); | |
224 | + if (rc < 0) | |
225 | + goto exit; | |
226 | + } | |
227 | + t = NULL; | |
228 | + if (av != NULL) | |
229 | + free(av); | |
230 | + } break; | |
231 | + } | |
232 | + } | |
233 | + | |
234 | +exit: | |
235 | + _free(cpuinfo_path); | |
236 | + free(iob); | |
237 | + /* freeze the pool to save memory, but only if private pool */ | |
238 | + if (*dsp && (*dsp)->pool != pool) | |
239 | + rpmstrPoolFreeze((*dsp)->pool, 0); | |
240 | + return (rc < 0) ? -1 : 0; | |
241 | +} | |
242 | + | |
243 | +int rpmdsCpuinfo(rpmds * dsp) | |
244 | +{ | |
245 | + return rpmdsCpuinfoPool(NULL, dsp); | |
246 | +} | |
247 | diff -ur rpm-4.16.0/lib/rpmds.h rpm-4.16.0-cpuinfo/lib/rpmds.h | |
248 | --- rpm-4.16.0/lib/rpmds.h 2020-11-08 20:19:15.625093667 +0100 | |
249 | +++ rpm-4.16.0-cpuinfo/lib/rpmds.h 2020-11-08 20:03:44.001865655 +0100 | |
250 | @@ -419,6 +419,13 @@ | |
251 | */ | |
252 | int rpmdsUname(rpmds * dsp); | |
253 | ||
254 | +/** | |
255 | + * Load cpuinfo provides into a dependency set. | |
256 | + * @retval *dsp (loaded) dependency set | |
257 | + * @return 0 on success | |
258 | + */ | |
259 | +int rpmdsCpuinfo(rpmds * dsp); | |
260 | + | |
261 | /** \ingroup rpmds | |
262 | * Create and load a dependency set. | |
263 | * @param pool shared string pool (or NULL for private pool) | |
264 | @@ -483,6 +490,14 @@ | |
265 | */ | |
266 | int rpmdsUnamePool(rpmstrPool pool, rpmds * dsp); | |
267 | ||
268 | +/** | |
269 | + * Load cpuinfo provides into a dependency set. | |
270 | + * @param pool shared string pool (or NULL for private pool) | |
271 | + * @retval *dsp (loaded) dependency set | |
272 | + * @return 0 on success | |
273 | + */ | |
274 | +int rpmdsCpuinfoPool(rpmstrPool pool, rpmds * dsp); | |
275 | + | |
276 | ||
277 | typedef enum rpmrichOp_e { | |
278 | RPMRICHOP_SINGLE = 1, | |
279 | diff -ur rpm-4.16.0/lib/rpmts_internal.h rpm-4.16.0-cpuinfo/lib/rpmts_internal.h | |
280 | --- rpm-4.16.0/lib/rpmts_internal.h 2020-11-08 20:19:15.625093667 +0100 | |
281 | +++ rpm-4.16.0-cpuinfo/lib/rpmts_internal.h 2020-11-08 20:22:24.382319931 +0100 | |
282 | @@ -22,6 +22,7 @@ | |
283 | ||
284 | rpmds rpmlib; /*!< rpmlib() dependency set. */ | |
285 | rpmds uname; /*!< uname() dependency set. */ | |
286 | + rpmds cpuinfo; /*!< cpuinfo() dependency set. */ | |
287 | rpmte * order; /*!< Packages sorted by dependencies. */ | |
288 | int orderCount; /*!< No. of transaction elements. */ | |
289 | int orderAlloced; /*!< No. of allocated transaction elements. */ |