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
8 + if (strstr(N, "cpuinfo(") == N) {
9 + if (tsmem->cpuinfo == NULL)
10 + rpmdsCpuinfoPool(rpmtsPool(ts), &(tsmem->cpuinfo));
12 + if (tsmem->cpuinfo != NULL && rpmdsSearch(tsmem->cpuinfo, dep) >= 0) {
13 + rpmdsNotify(dep, "(cpuinfo provides)", rc);
18 /* Dont look at pre-requisites of already installed packages */
19 if (!adding && isTransientReq(dsflags))
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
30 #include <sys/utsname.h>
32 #include <rpm/rpmtypes.h>
34 #include <rpm/rpmstring.h>
35 #include <rpm/rpmlog.h>
36 #include <rpm/rpmstrpool.h>
37 +#include <rpm/rpmmacro.h>
39 +#include "rpmio/rpmio_internal.h" /* XXX for rpmioSlurp */
41 #include "lib/rpmds_internal.h"
43 @@ -1655,3 +1670,203 @@
45 return rpmdsUnamePool(NULL, dsp);
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 },
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 },
85 + { "Features", 0, 4 }, /* XXX armv5 */
86 + { "bogomips", 0, 1 },
87 + { "BogoMIPS", 0, 1 }, /* XXX armv5 */
88 + { "clflush_size", 0, 1 },
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)
97 +static int rpmdsCpuinfoCtagFlags(const char * name)
99 + struct cpuinfo_s * ct;
102 + for (ct = ctags; ct->name != NULL; ct++) {
103 + if (strcmp(ct->name, name))
107 + ct->done = 1; /* XXX insure single occurrence */
114 +#define _PROC_CPUINFO "/proc/cpuinfo"
116 +int rpmdsCpuinfoPool(rpmstrPool pool, rpmds *dsp)
118 + char * cpuinfo_path = NULL;
119 + struct cpuinfo_s * ct;
120 + const char * NS = "cpuinfo";
122 + char * f, * fe, * fend;
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);
134 + /* Reset done variables. */
135 + for (ct = ctags; ct->name != NULL; ct++)
138 + rc = rpmioSlurp(cpuinfo_path, (uint8_t **) &iob, NULL);
139 + if (rc != 0 || iob == NULL)
142 + for (f = (char *)iob; *f != '\0'; f = fend) {
145 + while (*fe != '\0' && !(*fe == '\n' || *fe == '\r'))
148 + while (*fe != '\0' && (*fe == '\n' || *fe == '\r'))
152 + /* rtrim on line. */
153 + while (--ge > f && isspace(*ge))
156 + /* ltrim on line. */
157 + while (*f && isspace(*f))
162 + while (*fe && *fe != ':')
168 + /* rtrim on field 1. */
170 + while (--fe > f && isspace(*fe))
175 + /* ltrim on field 2. */
176 + while (*g && isspace(*g))
181 + for (t = f; *t != '\0'; t++) {
186 + switch (rpmdsCpuinfoCtagFlags(f)) {
187 + case -1: /* not found */
188 + case 0: /* ignore */
192 + case 1: /* Provides: cpuinfo(f) = g */
193 + for (t = g; *t != '\0'; t++) {
194 + if (isspace(*t) || *t == '(' || *t == ')')
197 + rc = rpmdsNSAdd(pool, dsp, NS, f, g, RPMSENSE_EQUAL);
201 + case 2: /* Provides: cpuinfo(g) */
202 + for (t = g; *t != '\0'; t++) {
203 + if (isspace(*t) || *t == '(' || *t == ')')
206 + rc = rpmdsNSAdd(pool, dsp, NS, g, "", RPMSENSE_ANY);
210 + case 3: /* if ("yes") Provides: cpuinfo(f) */
211 + if (!strcmp(g, "yes")) {
212 + rc = rpmdsNSAdd(pool, dsp, NS, f, "", RPMSENSE_ANY);
217 + case 4: /* Provides: cpuinfo(g[i]) */
218 + { char ** av = NULL;
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);
235 + _free(cpuinfo_path);
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;
243 +int rpmdsCpuinfo(rpmds * dsp)
245 + return rpmdsCpuinfoPool(NULL, dsp);
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
252 int rpmdsUname(rpmds * dsp);
255 + * Load cpuinfo provides into a dependency set.
256 + * @retval *dsp (loaded) dependency set
257 + * @return 0 on success
259 +int rpmdsCpuinfo(rpmds * dsp);
262 * Create and load a dependency set.
263 * @param pool shared string pool (or NULL for private pool)
266 int rpmdsUnamePool(rpmstrPool pool, rpmds * dsp);
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
274 +int rpmdsCpuinfoPool(rpmstrPool pool, rpmds * dsp);
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
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. */