rpm  5.4.10
rpmrc.c
Go to the documentation of this file.
1 #include "system.h"
2 
3 #include <stdarg.h>
4 
5 #if defined(HAVE_SYS_SYSTEMCFG_H)
6 #include <sys/systemcfg.h>
7 #else
8 #define __power_pc() 0
9 #endif
10 
11 #define _RPMIOB_INTERNAL /* XXX for rpmiobSlurp */
12 #include <rpmio.h>
13 #include <rpmcb.h>
14 #define _MIRE_INTERNAL
15 #include <mire.h>
16 #include <argv.h>
17 #include <rpmlua.h>
18 #include <rpmluaext.h>
19 #include <rpmmacro.h>
20 
21 #include <rpmtypes.h>
22 #include <rpmtag.h>
23 #define _RPMEVR_INTERNAL
24 #include <rpmevr.h>
25 
26 #define _RPMDS_INTERNAL
27 #include <rpmds.h>
28 
29 #include <rpmcli.h>
30 
31 #include <rpmsyck.h>
32 
33 #include "debug.h"
34 
35 /*@access miRE@*/
36 
37 /*@unchecked@*/ /*@null@*/
38 static const char * configTarget = NULL;
39 
40 /*@observer@*/ /*@unchecked@*/
41 static const char * platform = SYSCONFIGDIR "/platform";
42 
43 /*@only@*/ /*@relnull@*/ /*@unchecked@*/
44 void * platpat = NULL;
45 /*@unchecked@*/
46 int nplatpat = 0;
47 
48 extern rpmds cpuinfoP;
49 
60 };
61 #define RPM_MACHTABLE_COUNT 4
63 typedef /*@owned@*/ const char * cptr_t;
64 
65 typedef struct machCacheEntry_s {
66  const char * name;
67  int count;
69  int visited;
70 } * machCacheEntry;
71 
72 typedef struct machCache_s {
74  int size;
75 } * machCache;
76 
77 typedef struct machEquivInfo_s {
78  const char * name;
79  int score;
80 } * machEquivInfo;
81 
82 typedef struct machEquivTable_s {
83  int count;
85 } * machEquivTable;
86 
87 typedef struct defaultEntry_s {
88 /*@owned@*/ /*@null@*/ const char * name;
89 /*@owned@*/ /*@null@*/ const char * defName;
90 } * defaultEntry;
91 
92 typedef struct canonEntry_s {
93 /*@owned@*/ const char * name;
94 /*@owned@*/ const char * short_name;
95  short num;
96 } * canonEntry;
97 
98 /* tags are 'key'canon, 'key'translate, 'key'compat
99  *
100  * for giggles, 'key'_canon, 'key'_compat, and 'key'_canon will also work
101  */
102 typedef struct tableType_s {
103 /*@observer@*/ const char * const key;
104  const int hasCanon;
105  const int hasTranslate;
106  struct machEquivTable_s equiv;
112 } * tableType;
113 
114 /*@-fullinitblock@*/
115 /*@unchecked@*/
117  { "arch", 1, 0 },
118  { "os", 1, 0 },
119  { "buildarch", 0, 1 },
120  { "buildos", 0, 1 }
121 };
122 /*@=fullinitblock@*/
123 
124 #define OS 0
125 #define ARCH 1
126 
127 /*@unchecked@*/
128 static cptr_t current[2];
129 
130 /*@unchecked@*/
132 
133 /*@unchecked@*/
134 static int defaultsInitialized = 0;
135 
136 #ifdef __cplusplus
137 GENfree(canonEntry)
138 GENfree(defaultEntry)
139 GENfree(machCacheEntry)
140 GENfree(machEquivInfo)
141 #endif /* __cplusplus */
142 
143 /* prototypes */
144 static void rpmRebuildTargetVars(/*@null@*/ const char **target, /*@null@*/ const char ** canontarget)
145  /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
146  /*@modifies *canontarget, rpmGlobalMacroContext,
147  fileSystem, internalState @*/;
148 
149 static /*@observer@*/ /*@null@*/ machCacheEntry
150 machCacheFindEntry(const machCache cache, const char * key)
151  /*@*/
152 {
153  int i;
154 
155  for (i = 0; i < cache->size; i++)
156  if (!strcmp(cache->cache[i].name, key)) return cache->cache + i;
157 
158  return NULL;
159 }
160 
161 static void machAddEquiv(machEquivTable table, const char * name,
162  int distance)
163  /*@modifies table->list, table->count @*/
164 {
166 
167  { int i;
168  equiv = NULL;
169  for (i = 0; i < table->count; i++) {
170  if (xstrcasecmp(table->list[i].name, name))
171  continue;
172  equiv = table->list + i;
173  break;
174  }
175  }
176 
177  if (!equiv) {
178  if (table->count)
179  table->list = (machEquivInfo)
180  xrealloc(table->list, (table->count + 1) * sizeof(*table->list));
181  else
182  table->list = (machEquivInfo) xmalloc(sizeof(*table->list));
183 
184  table->list[table->count].name = xstrdup(name);
185  table->list[table->count++].score = distance;
186  }
187 }
188 
190  machEquivTable table, const char * name, int distance)
191  /*@modifies table->list, table->count @*/
192 {
193  machCacheEntry entry;
194  int i;
195 
196  entry = machCacheFindEntry(cache, name);
197  if (!entry || entry->visited) return;
198 
199  entry->visited = 1;
200 
201  for (i = 0; i < entry->count; i++) {
202  machAddEquiv(table, entry->equivs[i], distance);
203  }
204 
205  for (i = 0; i < entry->count; i++) {
206  machCacheEntryVisit(cache, table, entry->equivs[i], distance + 1);
207  }
208 }
209 
210 static void rebuildCompatTables(int type, const char * name)
211  /*@globals tables, internalState @*/
212  /*@modifies tables, internalState @*/
213 {
214  machCache cache = &tables[currTables[type]].cache;
215  machEquivTable table = &tables[currTables[type]].equiv;
216  const char * key = name;
217  int i;
218 
219  for (i = 0; i < cache->size; i++)
220  cache->cache[i].visited = 0;
221 
222  while (table->count > 0) {
223  --table->count;
224  table->list[table->count].name = _free(table->list[table->count].name);
225  }
226  table->count = 0;
227  table->list = _free(table->list);
228 
229  /*
230  * We have a general graph built using strings instead of pointers.
231  * Yuck. We have to start at a point at traverse it, remembering how
232  * far away everything is.
233  */
234  /*@-nullstate@*/ /* FIX: table->list may be NULL. */
235  machAddEquiv(table, key, 1);
236  machCacheEntryVisit(cache, table, key, 2);
237  return;
238  /*@=nullstate@*/
239 }
240 
241 static /*@null@*/ canonEntry lookupInCanonTable(const char * name,
242  const canonEntry table, int tableLen)
243  /*@*/
244 {
245  while (tableLen) {
246  tableLen--;
247  if (strcmp(name, table[tableLen].name))
248  continue;
249  /*@-immediatetrans -retalias@*/
250  return &(table[tableLen]);
251  /*@=immediatetrans =retalias@*/
252  }
253 
254  return NULL;
255 }
256 
257 static /*@observer@*/ /*@null@*/
258 const char * lookupInDefaultTable(const char * name,
259  const defaultEntry table, int tableLen)
260  /*@*/
261 {
262  while (tableLen) {
263  tableLen--;
264  if (table[tableLen].name && !strcmp(name, table[tableLen].name))
265  return table[tableLen].defName;
266  }
267 
268  return name;
269 }
270 
271 static void addMacroDefault(const char * macroname,
272  const char * val, /*@null@*/ const char * body)
273  /*@globals rpmGlobalMacroContext, internalState @*/
274  /*@modifies rpmGlobalMacroContext, internalState @*/
275 {
276  if (body == NULL)
277  body = val;
278  addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
279 }
280 
281 static void setPathDefault(const char * macroname, const char * subdir)
282  /*@globals rpmGlobalMacroContext, internalState @*/
283  /*@modifies rpmGlobalMacroContext, internalState @*/
284 {
285  if (macroname != NULL) {
286 #define _TOPDIRMACRO "%{_topdir}/"
287  char *body = (char *) alloca(sizeof(_TOPDIRMACRO) + strlen(subdir));
288  strcpy(body, _TOPDIRMACRO);
289  strcat(body, subdir);
290  addMacro(NULL, macroname, NULL, body, RMIL_DEFAULT);
291 #undef _TOPDIRMACRO
292  }
293 }
294 
295 /*@observer@*/ /*@unchecked@*/
296 static const char * ___build_pre = "\n\
297 RPM_SOURCE_DIR=\"%{_sourcedir}\"\n\
298 RPM_BUILD_DIR=\"%{_builddir}\"\n\
299 RPM_OPT_FLAGS=\"%{optflags}\"\n\
300 RPM_ARCH=\"%{_arch}\"\n\
301 RPM_OS=\"%{_os}\"\n\
302 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\n\
303 RPM_DOC_DIR=\"%{_docdir}\"\n\
304 export RPM_DOC_DIR\n\
305 RPM_PACKAGE_NAME=\"%{name}\"\n\
306 RPM_PACKAGE_VERSION=\"%{version}\"\n\
307 RPM_PACKAGE_RELEASE=\"%{release}\"\n\
308 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\n\
309 %{?buildroot:RPM_BUILD_ROOT=\"%{buildroot}\"\n\
310 export RPM_BUILD_ROOT\n}\
311 ";
312 
313 #if defined(RPM_VENDOR_WINDRIVER)
314 /*@unchecked@*/
315 extern const char * __usrlibrpm;
316 /*@unchecked@*/
317 extern const char * __etcrpm;
318 #endif
319 
320 static void setDefaults(void)
321  /*@globals rpmGlobalMacroContext, internalState @*/
322  /*@modifies rpmGlobalMacroContext, internalState @*/
323 {
324 
325 #if defined(RPM_VENDOR_WINDRIVER)
326  addMacro(NULL, "_usrlibrpm", NULL, __usrlibrpm, RMIL_DEFAULT);
327  addMacro(NULL, "_etcrpm", NULL, __etcrpm, RMIL_DEFAULT);
328  addMacro(NULL, "_vendor", NULL, "%{?_host_vendor}%{!?_host_vendor:wrs}", RMIL_DEFAULT);
329 #endif
330 
331  addMacro(NULL, "_usr", NULL, USRPREFIX, RMIL_DEFAULT);
332  addMacro(NULL, "_var", NULL, VARPREFIX, RMIL_DEFAULT);
333  addMacro(NULL, "_prefix", NULL, "%{_usr}", RMIL_DEFAULT);
334 
335  addMacro(NULL, "___build_pre", NULL, ___build_pre, RMIL_DEFAULT);
336 
337  addMacroDefault("_topdir",
338  "%{_usr}/src/rpm", NULL);
339  addMacroDefault("_tmppath",
340  "%{_var}/tmp", NULL);
341  addMacroDefault("_dbpath",
342  "%{_var}/lib/rpm", NULL);
343  addMacroDefault("_defaultdocdir",
344  "%{_usr}/share/doc", NULL);
345 
346  addMacroDefault("_rpmfilename",
347  "%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm",NULL);
348 
349  addMacroDefault("optflags",
350  "-O2 -g", NULL);
351  addMacroDefault("sigtype",
352  "none", NULL);
353  addMacroDefault("_buildshell",
354  "/bin/sh", NULL);
355 
356  setPathDefault("_builddir", "BUILD");
357  setPathDefault("_rpmdir", "RPMS");
358  setPathDefault("_srcrpmdir", "SRPMS");
359  setPathDefault("_sourcedir", "SOURCES");
360  setPathDefault("_specdir", "SPECS");
361 
362 }
363 
364 typedef struct cpu_vendor_os_gnu {
365 /*@owned@*/
366  const char * str;
367 /*@observer@*/
368  const char * cpu;
369 /*@observer@*/
370  const char * vendor;
371 /*@observer@*/
372  const char * os;
373 /*@observer@*/
374  const char * gnu;
375 } * CVOG_t;
376 
377 #ifdef __cplusplus
378 GENfree(CVOG_t)
379 #endif /* __cplusplus */
380 
383 static int parseCVOG(const char * str, CVOG_t *cvogp)
384  /*@modifies *cvogp @*/
385 {
386  CVOG_t cvog = (CVOG_t) xcalloc(1, sizeof(*cvog));
387  char * p, * pe;
388 
389  cvog->str = p = xstrdup(str);
390  pe = p + strlen(p);
391  while (pe-- > p && isspace(*pe))
392  *pe = '\0';
393 
394  cvog->cpu = p;
395  cvog->vendor = "unknown";
396  cvog->os = "unknown";
397  cvog->gnu = "";
398  while (*p && !(*p == '-' || isspace(*p)))
399  p++;
400  if (*p != '\0') *p++ = '\0';
401 
402  cvog->vendor = p;
403  while (*p && !(*p == '-' || isspace(*p)))
404  p++;
405  if (*p != '-') {
406  if (*p != '\0') *p++ = '\0';
407  cvog->os = cvog->vendor;
408  cvog->vendor = "unknown";
409  } else {
410  if (*p != '\0') *p++ = '\0';
411 
412  cvog->os = p;
413  while (*p && !(*p == '-' || isspace(*p)))
414  p++;
415  if (*p == '-') {
416  *p++ = '\0';
417 
418  cvog->gnu = p;
419  while (*p && !(*p == '-' || isspace(*p)))
420  p++;
421  }
422  if (*p != '\0') *p++ = '\0';
423  }
424 
425  if (cvogp)
426  *cvogp = cvog;
427  else {
428  cvog->str = _free(cvog->str);
429  cvog = _free(cvog);
430  }
431  return 0;
432 }
433 
439 /*@-onlytrans@*/ /* XXX miRE array, not refcounted. */
440 static rpmRC rpmPlatform(const char * platform)
441  /*@globals nplatpat, platpat,
442  rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
443  /*@modifies nplatpat, platpat,
444  rpmGlobalMacroContext, fileSystem, internalState @*/
445 {
446  CVOG_t cvog = NULL;
447  rpmiob iob = NULL;
448  int init_platform = 0;
449  miRE mi_re = NULL;
450  int mi_nre = 0;
451  char * p, * pe;
452  rpmRC rc;
453  int xx;
454 
455  rc = (rpmRC) rpmiobSlurp(platform, &iob);
456 
457  if (rc || iob == NULL) {
458  rc = RPMRC_FAIL;
459  goto exit;
460  }
461 
462  p = (char *)iob->b;
463  for (pe = p; p && *p; p = pe) {
464  pe = strchr(p, '\n');
465  if (pe)
466  *pe++ = '\0';
467 
468  while (*p && xisspace(*p))
469  p++;
470  if (*p == '\0' || *p == '#')
471  continue;
472 
473  if (init_platform) {
474  char * t = p + strlen(p);
475  while (--t > p && xisspace(*t))
476  *t = '\0';
477  if (t > p) {
478  xx = mireAppend(RPMMIRE_REGEX, 0, p, NULL, &mi_re, &mi_nre);
479  }
480  continue;
481  }
482 
483  if (!parseCVOG(p, &cvog) && cvog != NULL) {
484  addMacro(NULL, "_host_cpu", NULL, cvog->cpu, -1);
485  addMacro(NULL, "_host_vendor", NULL, cvog->vendor, -1);
486  addMacro(NULL, "_host_os", NULL, cvog->os, -1);
487  }
488 
489 #if defined(RPM_VENDOR_OPENPKG) /* explicit-platform */
490  /* do not use vendor and GNU attribution */
491  p = rpmExpand("%{_host_cpu}-%{_host_os}", NULL);
492 #else
493  p = rpmExpand("%{_host_cpu}-%{_host_vendor}-%{_host_os}",
494  (cvog && *cvog->gnu ? "-" : NULL),
495  (cvog ? cvog->gnu : NULL), NULL);
496 #endif
497  xx = mireAppend(RPMMIRE_STRCMP, 0, p, NULL, &mi_re, &mi_nre);
498  p = _free(p);
499 
500  init_platform++;
501  }
502  rc = (init_platform ? RPMRC_OK : RPMRC_FAIL);
503 
504 exit:
505  if (cvog) {
506  cvog->str = _free(cvog->str);
507  cvog = _free(cvog);
508  }
509  iob = rpmiobFree(iob);
510  if (rc == RPMRC_OK) {
512  platpat = mi_re;
513  nplatpat = mi_nre;
514  }
515  return rc;
516 }
517 /*@=onlytrans@*/
518 
519 #if defined(WITH_CPUINFO) && defined(WITH_SYCK)
520 static inline int rpmCpuinfoMatch(const char * feature, const char * EVR, rpmds cpuinfo)
521 {
522  rpmds cpufeature = rpmdsSingle(RPMTAG_REQUIRENAME, feature, EVR, RPMSENSE_PROBE);
523  int ret = rpmdsMatch(cpufeature, cpuinfo);
524 
525  (void)rpmdsFree(cpufeature);
526  cpufeature = NULL;
527  return ret;
528 }
529 
530 static rpmRC rpmCpuinfo(void)
531 {
532  rpmRC rc = RPMRC_FAIL;
533  const char *cpu, *_cpuinfo_path;
534  miRE mi_re = NULL;
535  int mi_nre = 0, xx, i;
536  CVOG_t cvog = NULL;
537  struct stat st;
538  char *yaml;
539  rpmsyck_node *tmp, node;
540  rpmSyck cpuinfoYaml;
541  FD_t fd;
542 
543  _cpuinfo_path = rpmGetPath("%{?_rpmhome}%{!?_rpmhome:" USRLIBRPM "}/cpuinfo.yaml", NULL);
544  if(Stat(_cpuinfo_path, &st))
545  return rc;
546 
547  fd = Fopen(_cpuinfo_path, "r");
548  _cpuinfo_path = _free(_cpuinfo_path);
549  yaml = (char *) xcalloc(st.st_size+1, 1);
550  Fread(yaml, 1, st.st_size, fd);
551  Fclose(fd);
552 
553  xx = rpmdsCpuinfo(&cpuinfoP, NULL);
554  cpuinfoYaml = rpmSyckLoad(yaml);
555  yaml = _free(yaml);
556  htGetEntry(cpuinfoYaml->firstNode->value.map, "cpuinfo", &tmp, NULL, NULL);
557  node = tmp[0]->value.seq;
558 
559  /* TODO: cleanup.. */
560  for(i = 0; node[i].type != T_END; i++) {
561  if(node[i].type == T_MAP) {
562  rpmsyck_node *tmp;
563  if(htHasEntry(node[i].value.map, "Family")) {
564  htGetEntry(node[i].value.map, "Family", &tmp, NULL, NULL);
565  const char *family = tmp[0]->value.key;
566  int j;
567  hashTable cpus = NULL;
568  if(rpmCpuinfoMatch(family, "", cpuinfoP)) {
569  if(htHasEntry(node[i].value.map, "Arch")) {
570  htGetEntry(node[i].value.map, "Arch", &tmp, NULL, NULL);
571  rpmsyck_node arch = tmp[0]->value.seq;
572  for(j = 0; arch[j].type != T_END; j++);
573  cpus = htCreate(j*2, 0, 0, NULL, NULL);
574  for(j = 0; arch[j].type != T_END; j++) {
575  if(htHasEntry(arch[j].value.map, "Extends")) {
576  if(htGetEntry(arch[j].value.map, "Extends", &tmp, NULL, NULL) &&
577  tmp[0]->type == T_STR && !htHasEntry(cpus, tmp[0]->value.key))
578  continue;
579  }
580  if(htHasEntry(arch[j].value.map, "Features")) {
581  htGetEntry(arch[j].value.map, "Features", &tmp, NULL, NULL);
582  rpmsyck_node features = tmp[0]->value.seq;
583  int k, match = 0;
584  for(k = 0; features[k].type != T_END; k++)
585  if(features[k].type == T_STR && !(match = rpmCpuinfoMatch(features[k].value.key, "", cpuinfoP))) break;
586  if(!match) continue;
587  }
588  if(htHasEntry(arch[j].value.map, "Name")) {
589  htGetEntry(arch[j].value.map, "Name", &tmp, NULL, NULL);
590  if(tmp[0]->type != T_STR) continue;
591  const char *name = tmp[0]->value.key;
592  rpmsyck_node alias = NULL;
593  if(htHasEntry(arch[j].value.map, "Alias")) {
594  htGetEntry(arch[j].value.map, "Alias", &tmp, NULL, NULL);
595  alias = tmp[0]->value.seq;
596  }
597  htAddEntry(cpus, name, alias);
598  }
599  }
600  }
601  if(htHasEntry(node[i].value.map, "Priority")) {
602  htGetEntry(node[i].value.map, "Priority", &tmp, NULL, NULL);
603  rpmsyck_node priority = tmp[0]->value.seq;
604  int j;
605  for(j = 0; priority[j].type != T_END; j++)
606  if(htHasEntry(cpus, priority[j].value.key)) {
607  xx = mireAppend(RPMMIRE_REGEX, 0, priority[j].value.key, NULL, &mi_re, &mi_nre);
608  htGetEntry(cpus, priority[j].value.key, &tmp, NULL, NULL);
609  if(tmp[0]) {
610  rpmsyck_node alias = tmp[0];
611  int k;
612  for(k = 0; alias[k].type != T_END; k++)
613  xx = mireAppend(RPMMIRE_REGEX, 0, alias[k].value.key, NULL, &mi_re, &mi_nre);
614  }
615  }
616  }
617  }
618  if(cpus) cpus = htFree(cpus);
619  }
620  }
621  }
622 
623  cpuinfoYaml = rpmSyckFree(cpuinfoYaml);
624 
625  xx = mireAppend(RPMMIRE_REGEX, 0, "noarch", NULL, &mi_re, &mi_nre);
626 
627  cpu = mi_re[0].pattern;
628  if(cpu != NULL)
629  {
630  if (!parseCVOG(cpu, &cvog) && cvog != NULL) {
631  addMacro(NULL, "_host_cpu", NULL, cvog->cpu, -1);
632  addMacro(NULL, "_host_vendor", NULL, cvog->vendor, -1);
633  addMacro(NULL, "_host_os", NULL, cvog->os, -1);
634  }
635  if (cvog) {
636  cvog->str = _free(cvog->str);
637  cvog = _free(cvog);
638  }
639 
640  rc = RPMRC_OK;
641  if (rc == RPMRC_OK) {
643  platpat = mi_re;
644  nplatpat = mi_nre;
645  }
646 
647  }
648  return rc;
649 }
650 #endif
651 
652 /*@-onlytrans@*/ /* XXX miRE array, not refcounted. */
653 int rpmPlatformScore(const char * platform, void * mi_re, int mi_nre)
654 {
655  miRE mire;
656  int i;
657 
658  if (mi_re == NULL) {
659  mi_re = platpat;
660  mi_nre = nplatpat;
661  }
662 
663  if ((mire = (miRE) mi_re) != NULL)
664  for (i = 0; i < mi_nre; i++) {
665  if (mireRegexec(mire + i, platform, 0) >= 0)
666  return (i + 1);
667  }
668  return 0;
669 }
670 /*@=onlytrans@*/
671 
674 static void defaultMachine(/*@out@*/ const char ** arch,
675  /*@out@*/ const char ** os)
676  /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
677  /*@modifies *arch, *os, rpmGlobalMacroContext, fileSystem, internalState @*/
678 {
679 #if defined(RPM_VENDOR_OPENPKG) /* larger-utsname */
680  /* utsname fields on some platforms (like HP-UX) are very small
681  (just about 8 characters). This is too small for OpenPKG, so cheat! */
682  static struct utsname un_real;
683  static struct {
684  char sysname[32];
685  char nodename[32];
686  char release[32];
687  char version[32];
688  char machine[32];
689  } un;
690 #else
691  static struct utsname un;
692 #endif
693  static int gotDefaults = 0;
694  int rc;
695 
696  while (!gotDefaults) {
697 #if defined(RPM_VENDOR_WINDRIVER)
698  const char * _platform = rpmGetPath(__etcrpm, "/platform", NULL);
699 #else
700  const char * _platform = platform;
701 #endif
702  CVOG_t cvog = NULL;
703 #if defined(RPM_VENDOR_OPENPKG) /* larger-utsname */
704  const char *cp;
705 #endif
706 #if defined(RPM_VENDOR_OPENPKG) /* larger-utsname */
707  /* utsname fields on some platforms (like HP-UX) are very small
708  (just about 8 characters). This is too small for OpenPKG, so cheat! */
709  rc = uname(&un_real);
710  strncpy(un.sysname, un_real.sysname, sizeof(un.sysname)); un.sysname [sizeof(un.sysname) -1] = '\0';
711  strncpy(un.nodename, un_real.nodename, sizeof(un.nodename)); un.nodename[sizeof(un.nodename)-1] = '\0';
712  strncpy(un.release, un_real.release, sizeof(un.release)); un.release [sizeof(un.release) -1] = '\0';
713  strncpy(un.version, un_real.version, sizeof(un.version)); un.version [sizeof(un.version) -1] = '\0';
714  strncpy(un.machine, un_real.machine, sizeof(un.machine)); un.machine [sizeof(un.machine) -1] = '\0';
715 #else
716  rc = uname(&un);
717 #endif
718  if (rc < 0) return;
719 
720 #if defined(RPM_VENDOR_OPENPKG) /* platform-major-minor-only */
721  /* Reduce the platform version to major and minor version numbers */
722  {
723  char *cp;
724  char *cpR;
725  int n;
726  cpR = un.release;
727  if ((n = strcspn(cpR, "0123456789")) > 0)
728  cpR += n;
729  if ((n = strspn(cpR, "0123456789.")) > 0) {
730  /* terminate after "N.N.N...." prefix */
731  cpR[n] = '\0';
732  /* shorten to "N.N" if longer */
733  if ((cp = strchr(cpR, '.')) != NULL) {
734  if ((cp = strchr(cp+1, '.')) != NULL)
735  *cp = '\0';
736  }
737  strcat(un.sysname, cpR);
738  }
739  /* fix up machine hardware name containing white-space as it
740  happens to be on Power Macs running MacOS X */
741  if (!strncmp(un.machine, "Power Macintosh", 15))
742  sprintf(un.machine, "powerpc");
743  }
744 #endif
745 
746  if (!strncmp(un.machine, "Power Macintosh", 15)) {
747  sprintf(un.machine, "ppc");
748  }
749 
750 #if defined(RPM_VENDOR_OPENPKG) /* explicit-platform */
751  /* allow the path to the "platforms" file be overridden under run-time */
752  cp = rpmExpand("%{?__platform}", NULL);
753  if (cp == NULL || cp[0] == '\0')
754  cp = _platform;
755  if (rpmPlatform(cp) == RPMRC_OK) {
756 #elif defined(WITH_CPUINFO) && defined(WITH_SYCK)
757  if (rpmPlatform(_platform) == RPMRC_OK || rpmCpuinfo() == RPMRC_OK)
758 #else
759  if (rpmPlatform(_platform) == RPMRC_OK)
760 #endif
761  {
762  const char * s;
763  gotDefaults = 1;
764  s = rpmExpand("%{?_host_cpu}", NULL);
765  if (s && *s != '\0') {
766  strncpy(un.machine, s, sizeof(un.machine));
767  un.machine[sizeof(un.machine)-1] = '\0';
768  }
769  s = _free(s);
770  s = rpmExpand("%{?_host_os}", NULL);
771  if (s && *s != '\0') {
772  strncpy(un.sysname, s, sizeof(un.sysname));
773  un.sysname[sizeof(un.sysname)-1] = '\0';
774  }
775  s = _free(s);
776  }
777 
778 #if defined(RPM_VENDOR_OPENPKG) /* explicit-platform */
779  /* cleanup after above processing */
780  if (cp != NULL && cp != _platform)
781  cp = _free(cp);
782 #endif
783 #if defined(RPM_VENDOR_WINDRIVER)
784  _platform = _free(_platform);
785 #endif
786 
787  if (configTarget && !parseCVOG(configTarget, &cvog) && cvog != NULL) {
788  gotDefaults = 1;
789  if (cvog->cpu && cvog->cpu[0] != '\0') {
790  strncpy(un.machine, cvog->cpu, sizeof(un.machine));
791  un.machine[sizeof(un.machine)-1] = '\0';
792  }
793  if (cvog->os && cvog->os[0] != '\0') {
794  strncpy(un.sysname, cvog->os, sizeof(un.sysname));
795  un.sysname[sizeof(un.sysname)-1] = '\0';
796  }
797  cvog->str = _free(cvog->str);
798  cvog = _free(cvog);
799  }
800  if (gotDefaults)
801  break;
802  gotDefaults = 1;
803  break;
804  }
805 
806  if (arch) *arch = un.machine;
807  if (os) *os = un.sysname;
808 }
809 
817 static void rpmSetTables(int archTable, int osTable)
818  /*@globals currTables, rpmGlobalMacroContext, h_errno,
819  fileSystem, internalState @*/
820  /*@modifies currTables, rpmGlobalMacroContext,
821  fileSystem, internalState @*/
822 {
823  const char * arch, * os;
824 
825  defaultMachine(&arch, &os);
826 
827  if (currTables[ARCH] != archTable) {
828  currTables[ARCH] = archTable;
829  rebuildCompatTables(ARCH, arch);
830  }
831 
832  if (currTables[OS] != osTable) {
833  currTables[OS] = osTable;
834  rebuildCompatTables(OS, os);
835  }
836 }
837 
838 static void rpmSetMachine(const char * arch, const char * os)
839  /*@globals current, rpmGlobalMacroContext, h_errno,
840  fileSystem, internalState @*/
841  /*@modifies current, rpmGlobalMacroContext,
842  fileSystem, internalState @*/
843 {
844  if (arch == NULL) {
845 /*@i@*/ defaultMachine(&arch, NULL);
846  if (tables[currTables[ARCH]].hasTranslate)
847  arch = lookupInDefaultTable(arch,
848  tables[currTables[ARCH]].defaults,
849  tables[currTables[ARCH]].defaultsLength);
850  }
851 assert(arch != NULL);
852 
853  if (os == NULL) {
854 /*@i@*/ defaultMachine(NULL, &os);
855  if (tables[currTables[OS]].hasTranslate)
856  os = lookupInDefaultTable(os,
857  tables[currTables[OS]].defaults,
858  tables[currTables[OS]].defaultsLength);
859  }
860 assert(os != NULL);
861 
862 
863  if (!current[ARCH] || strcmp(arch, current[ARCH])) {
864  current[ARCH] = _free(current[ARCH]);
865  current[ARCH] = xstrdup(arch);
866  rebuildCompatTables(ARCH, arch);
867  }
868 
869  if (!current[OS] || strcmp(os, current[OS])) {
870  char * t = xstrdup(os);
871  current[OS] = _free(current[OS]);
872  if (!strcmp(t, "linux"))
873  *t = 'L';
874  current[OS] = t;
875  rebuildCompatTables(OS, os);
876  }
877 }
878 
879 static void getMachineInfo(int type, /*@null@*/ /*@out@*/ const char ** name,
880  /*@null@*/ /*@out@*/int * num)
881  /*@modifies *name, *num @*/
882 {
883  canonEntry canon;
884  int which = currTables[type];
885 
886  /* use the normal canon tables, even if we're looking up build stuff */
887  if (which >= 2) which -= 2;
888 
889  canon = lookupInCanonTable(current[type],
890  tables[which].canons,
891  tables[which].canonsLength);
892 
893  if (canon) {
894  if (num) *num = canon->num;
895  if (name) *name = canon->short_name;
896  } else {
897  if (num) *num = 255;
898 #if defined(WITH_CPUINFO)
899  if (name) {
900  if(type == ARCH) {
901  int i, j, n;
902  ARGV_t archs = NULL;
903  char *pref = rpmExpand("%{?_prefer_target_cpu}", NULL);
904 
905  (void) argvSplit(&archs, pref, " ");
906  for(i = 0, n = argvCount(archs); (i < n && !*name); i++)
907  if((j = rpmPlatformScore(archs[i], platpat, nplatpat)) > 0)
908  *name = ((miRE)platpat)[j-1].pattern;
909 
910  archs = argvFree(archs);
911  pref = _free(pref);
912  }
913  if(!*name) *name = current[type];
914  }
915 #else
916  if (name) *name = current[type];
917 #endif
918  }
919 }
920 
921 static void rpmRebuildTargetVars(const char ** target, const char ** canontarget)
922 {
923 
924  char *ca = NULL, *co = NULL, *ct = NULL;
925  int x;
926 
927  /* Rebuild the compat table to recalculate the current target arch. */
928 
929  rpmSetMachine(NULL, NULL);
932 
933  if (target && *target) {
934  char *c;
935  /* Set arch and os from specified build target */
936  ca = xstrdup(*target);
937  if ((c = strchr(ca, '-')) != NULL) {
938  *c++ = '\0';
939 
940  if ((co = strrchr(c, '-')) == NULL) {
941  co = c;
942  } else {
943  if (!xstrcasecmp(co, "-gnu"))
944  *co = '\0';
945  if ((co = strrchr(c, '-')) == NULL)
946  co = c;
947  else
948  co++;
949  }
950  if (co != NULL) co = xstrdup(co);
951  }
952  } else {
953  const char *a = NULL;
954  const char *o = NULL;
955  /* Set build target from rpm arch and os */
956  getMachineInfo(ARCH, &a, NULL);
957  ca = (a) ? xstrdup(a) : NULL;
958  getMachineInfo(OS, &o, NULL);
959  co = (o) ? xstrdup(o) : NULL;
960  }
961 
962  /* If still not set, Set target arch/os from default uname(2) values */
963  if (ca == NULL) {
964  const char *a = NULL;
965  defaultMachine(&a, NULL);
966  ca = (a) ? xstrdup(a) : NULL;
967  }
968  if (ca != NULL)
969  for (x = 0; ca[x] != '\0'; x++)
970  ca[x] = (char)xtolower(ca[x]);
971 
972  if (co == NULL) {
973  const char *o = NULL;
974  defaultMachine(NULL, &o);
975  co = (o) ? xstrdup(o) : NULL;
976  }
977  if (co != NULL)
978  for (x = 0; co[x] != '\0'; x++)
979  co[x] = (char)xtolower(co[x]);
980 
981  /* XXX For now, set canonical target to arch-os */
982  if (ct == NULL) {
983  ct = (char *) xmalloc(strlen(ca) + sizeof("-") + strlen(co));
984  sprintf(ct, "%s-%s", ca, co);
985  }
986 
987 /*
988  * XXX All this macro pokery/jiggery could be achieved by doing a delayed
989  * rpmInitMacros(NULL, PER-PLATFORM-MACRO-FILE-NAMES);
990  */
991  delMacro(NULL, "_target");
992  addMacro(NULL, "_target", NULL, ct, RMIL_RPMRC);
993  delMacro(NULL, "_target_cpu");
994  addMacro(NULL, "_target_cpu", NULL, ca, RMIL_RPMRC);
995  delMacro(NULL, "_target_os");
996  addMacro(NULL, "_target_os", NULL, co, RMIL_RPMRC);
997 
998  if (canontarget)
999  *canontarget = ct;
1000  else
1001  ct = _free(ct);
1002  ca = _free(ca);
1003  /*@-usereleased@*/
1004  co = _free(co);
1005  /*@=usereleased@*/
1006 }
1007 
1008 void rpmFreeRpmrc(void)
1009  /*@globals current, tables, defaultsInitialized @*/
1010  /*@modifies current, tables, defaultsInitialized @*/
1011 {
1012  int i, j, k;
1013 
1014  (void)mireFreeAll((miRE)platpat, nplatpat);
1015  platpat = NULL;
1016  nplatpat = 0;
1017 
1018  for (i = 0; i < RPM_MACHTABLE_COUNT; i++) {
1019  tableType t;
1020  t = tables + i;
1021  if (t->equiv.list) {
1022  for (j = 0; j < t->equiv.count; j++)
1023  t->equiv.list[j].name = _free(t->equiv.list[j].name);
1024  t->equiv.list = _free(t->equiv.list);
1025  t->equiv.count = 0;
1026  }
1027  if (t->cache.cache) {
1028  for (j = 0; j < t->cache.size; j++) {
1029  machCacheEntry e;
1030  e = t->cache.cache + j;
1031  if (e == NULL)
1032  /*@innercontinue@*/ continue;
1033  e->name = _free(e->name);
1034  if (e->equivs) {
1035  for (k = 0; k < e->count; k++)
1036  e->equivs[k] = _free(e->equivs[k]);
1037  e->equivs = _free(e->equivs);
1038  }
1039  }
1040  t->cache.cache = _free(t->cache.cache);
1041  t->cache.size = 0;
1042  }
1043  if (t->defaults) {
1044  for (j = 0; j < t->defaultsLength; j++) {
1045  t->defaults[j].name = _free(t->defaults[j].name);
1046  t->defaults[j].defName = _free(t->defaults[j].defName);
1047  }
1048  t->defaults = _free(t->defaults);
1049  t->defaultsLength = 0;
1050  }
1051  if (t->canons) {
1052  for (j = 0; j < t->canonsLength; j++) {
1053  t->canons[j].name = _free(t->canons[j].name);
1054  t->canons[j].short_name = _free(t->canons[j].short_name);
1055  }
1056  t->canons = _free(t->canons);
1057  t->canonsLength = 0;
1058  }
1059  }
1060 
1061  current[OS] = _free(current[OS]);
1062  current[ARCH] = _free(current[ARCH]);
1063  defaultsInitialized = 0;
1064 /*@-globstate -nullstate@*/ /* FIX: platpat/current may be NULL */
1065  return;
1066 /*@=globstate =nullstate@*/
1067 }
1068 
1073 static int rpmReadRC(const char *macrofiles)
1074  /*@globals defaultsInitialized,
1075  rpmGlobalMacroContext, rpmCLIMacroContext, h_errno,
1076  fileSystem, internalState @*/
1077  /*@modifies defaultsInitialized, rpmGlobalMacroContext,
1078  fileSystem, internalState @*/
1079 {
1080  int rc = 0;
1081 
1082  if (!defaultsInitialized) {
1083  setDefaults();
1084  defaultsInitialized = 1;
1085  }
1086 
1087  /* Read macro files. */
1088  { const char *mfpath = rpmExpand(macrofiles, NULL);
1089 
1090  if (mfpath != NULL) {
1091  rpmInitMacros(NULL, mfpath);
1092  mfpath = _free(mfpath);
1093  }
1094  }
1095 
1096  return rc;
1097 }
1098 
1099 int rpmReadConfigFiles(/*@unused@*/ const char * file,
1100  const char * target)
1101  /*@globals configTarget, rpmMacrofiles @*/
1102  /*@modifies configTarget @*/
1103 {
1104  mode_t mode = 0022;
1105 
1106 #ifdef PREMACROFILES
1107  if (rpmReadRC(PREMACROFILES)) return -1;
1108 #endif
1109 
1110  /* Reset umask to its default umask(2) value. */
1111  mode = umask(mode);
1112 
1113  configTarget = target;
1114 
1115  /* Preset target macros */
1116  /*@-nullstate@*/ /* FIX: target can be NULL */
1117  rpmRebuildTargetVars(&target, NULL);
1118 
1119  /* Read the files */
1120 /*@-globs@*/
1121  if (rpmReadRC(rpmMacrofiles)) return -1;
1122 /*@=globs@*/
1123 
1124  /* Reset target macros */
1125  rpmRebuildTargetVars(&target, NULL);
1126  /*@=nullstate@*/
1127 
1128  /* Finally set target platform */
1129  { const char *cpu = rpmExpand("%{_target_cpu}", NULL);
1130  const char *os = rpmExpand("%{_target_os}", NULL);
1131  rpmSetMachine(cpu, os);
1132 
1133  cpu = _free(cpu);
1134  os = _free(os);
1135  }
1136  configTarget = NULL;
1137 
1138  /* Force Lua state initialization */
1139 #ifdef WITH_LUA
1140  (void)rpmluaGetPrintBuffer(NULL);
1141 #if defined(RPM_VENDOR_OPENPKG) /* rpm-lua-extensions-based-on-rpm-lib-functionality */
1142  (void)rpmluaextActivate(rpmluaGetGlobalState());
1143 #endif /* RPM_VENDOR_OPENPKG */
1144 #endif
1145 
1146  return 0;
1147 }
1148 
1149 int rpmShowRC(FILE * fp)
1150 {
1151  rpmds ds = NULL;
1152  int i;
1153  machEquivTable equivTable;
1154  int xx;
1155  miRE mire;
1156 
1157  /* the caller may set the build arch which should be printed here */
1158  fprintf(fp, "ARCHITECTURE AND OS:\n");
1159  fprintf(fp, "build arch : %s\n", current[ARCH]);
1160 
1161  fprintf(fp, "compatible build archs:");
1162  equivTable = &tables[RPM_MACHTABLE_BUILDARCH].equiv;
1163  for (i = 0; i < equivTable->count; i++)
1164  fprintf(fp," %s", equivTable->list[i].name);
1165  fprintf(fp, "\n");
1166 
1167  fprintf(fp, "build os : %s\n", current[OS]);
1168 
1169  fprintf(fp, "compatible build os's :");
1170  equivTable = &tables[RPM_MACHTABLE_BUILDOS].equiv;
1171  for (i = 0; i < equivTable->count; i++)
1172  fprintf(fp," %s", equivTable->list[i].name);
1173  fprintf(fp, "\n");
1174 
1175  fprintf(fp, "install arch : %s\n", current[ARCH]);
1176  fprintf(fp, "install os : %s\n", current[OS]);
1177 
1178  fprintf(fp, "compatible archs :");
1179  for (mire = (miRE) platpat, i = 0; i < nplatpat; i++)
1180  fprintf(fp, " %s", mire[i].pattern);
1181  fprintf(fp, "\n");
1182 
1183  fprintf(fp, "compatible os's :");
1184  equivTable = &tables[RPM_MACHTABLE_INSTOS].equiv;
1185  for (i = 0; i < equivTable->count; i++)
1186  fprintf(fp," %s", equivTable->list[i].name);
1187  fprintf(fp, "\n");
1188 
1189  { const char * s = rpmExpand("%{?optflags}", NULL);
1190  fprintf(fp, "%-21s : %s\n", "optflags", ((s && *s) ? s : "(not set)"));
1191  s = _free(s);
1192 
1193 #ifdef WITH_LUA
1194  fprintf(fp, "\nLUA MODULES:\n");
1195 /*@-globs@*/
1196  s = rpmExpand(rpmluaFiles, NULL);
1197 /*@=globs@*/
1198  fprintf(fp, "%-21s : %s\n", "luafiles", ((s && *s) ? s : "(not set)"));
1199  s = _free(s);
1200 /*@-globs@*/
1201  s = rpmExpand(rpmluaPath, NULL);
1202 /*@=globs@*/
1203  fprintf(fp, "%-21s : %s\n", "luapath", ((s && *s) ? s : "(not set)"));
1204  s = _free(s);
1205 #endif
1206 
1207  fprintf(fp, "\nMACRO DEFINITIONS:\n");
1208 /*@-globs@*/
1209  s = rpmExpand(rpmMacrofiles, NULL);
1210 /*@=globs@*/
1211  fprintf(fp, "%-21s : %s\n", "macrofiles", ((s && *s) ? s : "(not set)"));
1212  s = _free(s);
1213  }
1214 
1215  if (rpmIsVerbose()) {
1216  rpmPRCO PRCO = rpmdsNewPRCO(NULL);
1217  xx = rpmdsSysinfo(PRCO, NULL);
1218  ds = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), "PRCO");
1219  if (ds != NULL) {
1220  const char * fn = (_sysinfo_path ? _sysinfo_path : "/etc/rpm/sysinfo");
1221  fprintf(fp, _("Configured system provides (from %s):\n"), fn);
1222  ds = rpmdsInit(ds);
1223  while (rpmdsNext(ds) >= 0) {
1224  const char * DNEVR = rpmdsDNEVR(ds);
1225  if (DNEVR != NULL)
1226  fprintf(fp, " %s\n", DNEVR+2);
1227  }
1228  (void)rpmdsFree(ds);
1229  ds = NULL;
1230  fprintf(fp, "\n");
1231  }
1232  PRCO = rpmdsFreePRCO(PRCO);
1233  }
1234 
1235  if (rpmIsVerbose()) {
1236  fprintf(fp, _("Features provided by rpmlib installer:\n"));
1237  xx = rpmdsRpmlib(&ds, NULL);
1238  ds = rpmdsInit(ds);
1239  while (rpmdsNext(ds) >= 0) {
1240  const char * DNEVR = rpmdsDNEVR(ds);
1241  if (DNEVR != NULL)
1242  fprintf(fp, " %s\n", DNEVR+2);
1243  }
1244  (void)rpmdsFree(ds);
1245  ds = NULL;
1246  fprintf(fp, "\n");
1247 
1248  if(cpuinfoP == NULL)
1249  xx = rpmdsCpuinfo(&cpuinfoP, NULL);
1250  if (cpuinfoP != NULL) {
1251 #if defined(WITH_CPUINFO)
1252  const char * fn = "libcpuinfo";
1253 #else
1254  const char * fn = (_cpuinfo_path ? _cpuinfo_path : "/proc/cpuinfo");
1255 #endif
1256  fprintf(fp,
1257  _("Features provided by current cpuinfo (from %s):\n"), fn);
1258 /*@-mods@*/
1260  while (rpmdsNext(cpuinfoP) >= 0) {
1261  const char * DNEVR = rpmdsDNEVR(cpuinfoP);
1262  if (DNEVR != NULL)
1263  fprintf(fp, " %s\n", DNEVR+2);
1264  }
1265  (void)rpmdsFree(cpuinfoP);
1266  cpuinfoP = NULL;
1267 /*@=mods@*/
1268 
1269  fprintf(fp, "\n");
1270  }
1271  }
1272 
1273  if (rpmIsDebug()) {
1274  xx = rpmdsGetconf(&ds, NULL);
1275  if (ds != NULL) {
1276  fprintf(fp,
1277  _("Features provided by current getconf:\n"));
1278  ds = rpmdsInit(ds);
1279  while (rpmdsNext(ds) >= 0) {
1280  const char * DNEVR = rpmdsDNEVR(ds);
1281  if (DNEVR != NULL)
1282  fprintf(fp, " %s\n", DNEVR+2);
1283  }
1284  (void)rpmdsFree(ds);
1285  ds = NULL;
1286  fprintf(fp, "\n");
1287  }
1288 
1289  xx = rpmdsUname(&ds, NULL);
1290  if (ds != NULL) {
1291  fprintf(fp,
1292  _("Features provided by current uname:\n"));
1293  ds = rpmdsInit(ds);
1294  while (rpmdsNext(ds) >= 0) {
1295  const char * DNEVR = rpmdsDNEVR(ds);
1296  if (DNEVR != NULL)
1297  fprintf(fp, " %s\n", DNEVR+2);
1298  }
1299  (void)rpmdsFree(ds);
1300  ds = NULL;
1301  fprintf(fp, "\n");
1302  }
1303  }
1304 
1305  rpmDumpMacroTable(NULL, fp);
1306 
1307  return 0;
1308 }
rpmds rpmdsSingle(rpmTag tagN, const char *N, const char *EVR, evrFlags Flags)
Create, load and initialize a dependency set of size 1.
Definition: rpmds.c:609
void rpmInitMacros(MacroContext mc, const char *macrofiles)
Initialize macro context from set of macrofile(s).
Definition: macro.c:2880
int defaultsLength
Definition: rpmrc.c:110
rpm_machtable_e
Build and install arch/os table identifiers.
Definition: rpmrc.c:55
rpmds rpmdsInit(rpmds ds)
Initialize dependency set iterator.
Definition: rpmds.c:943
rpmPRCO rpmdsFreePRCO(rpmPRCO PRCO)
Free dependency set(s) container.
Definition: rpmds.c:2853
static void defaultMachine(const char **arch, const char **os)
Definition: rpmrc.c:674
const int hasCanon
Definition: rpmrc.c:104
const char * name
Definition: rpmrc.c:88
int htHasEntry(hashTable ht, const void *key)
Check for key in hash table.
Definition: rpmhash.c:181
void * mireFreeAll(miRE mire, int nmire)
Destroy compiled patterns.
Definition: mire.c:96
const char * rpmluaPath
struct cpu_vendor_os_gnu * CVOG_t
char * xstrdup(const char *str)
Definition: rpmmalloc.c:322
static const char * ___build_pre
Definition: rpmrc.c:296
cptr_t * equivs
Definition: rpmrc.c:68
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
Definition: rpmio.c:2833
const int hasTranslate
Definition: rpmrc.c:105
int rpmReadConfigFiles(const char *file, const char *target)
Definition: rpmrc.c:1099
char * rpmGetPath(const char *path,...)
Return (malloc&#39;ed) expanded, canonicalized, file path.
Definition: macro.c:3310
int rpmdsGetconf(rpmds *dsp, const char *path)
Load getconf provides into a dependency set.
Definition: rpmds.c:2718
struct machEquivTable_s equiv
Definition: rpmrc.c:106
int rpmPlatformScore(const char *platform, void *mi_re, int mi_nre)
Definition: rpmrc.c:653
machCacheEntry cache
Definition: rpmrc.c:73
int nplatpat
Definition: rpmrc.c:46
const char * cpu
Definition: rpmrc.c:368
rpmlua rpmluaGetGlobalState(void)
int Stat(const char *path, struct stat *st)
stat(2) clone.
Definition: rpmrpc.c:1361
const char * name
Definition: rpmrc.c:78
#define _TOPDIRMACRO
static const char * configTarget
Definition: rpmrc.c:38
void addMacro(MacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
Definition: macro.c:2684
rpmds cpuinfoP
Definition: depends.c:857
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
const char * rpmdsDNEVR(const rpmds ds)
Return current formatted dependency string.
Definition: rpmds.c:657
struct rpmds_s * rpmds
Dependency tag sets from a header, so that a header can be discarded early.
Definition: rpmtypes.h:28
static void rebuildCompatTables(int type, const char *name)
Definition: rpmrc.c:210
struct rpmPRCO_s * rpmPRCO
Container for commonly extracted dependency set(s).
Definition: rpmtypes.h:33
rpmds rpmdsFree(rpmds ds)
Destroy a dependency set.
#define USRPREFIX
Definition: config.h:1264
canonEntry canons
Definition: rpmrc.c:109
const char * gnu
Definition: rpmrc.c:374
static machCacheEntry machCacheFindEntry(const machCache cache, const char *key)
Definition: rpmrc.c:150
int rpmiobSlurp(const char *fn, rpmiob *iobp)
Definition: rpmiob.c:130
int htGetEntry(hashTable ht, const void *key, const void *data, int *dataCount, const void *tableKey)
Retrieve item from hash table.
Definition: rpmhash.c:188
static int xtolower(int c)
Definition: rpmiotypes.h:465
char * alloca()
rpmPRCO rpmdsNewPRCO(Header h)
Create dependency set(s) container.
Definition: rpmds.c:2878
static void rpmRebuildTargetVars(const char **target, const char **canontarget)
Definition: rpmrc.c:921
void delMacro(MacroContext mc, const char *n)
Delete macro from context.
Definition: macro.c:2723
void * xcalloc(size_t nmemb, size_t size)
Definition: rpmmalloc.c:301
short num
Definition: rpmrc.c:95
int rpmdsSysinfo(rpmPRCO PRCO, const char *fn)
Load sysinfo dependencies into a dependency set.
Definition: rpmds.c:1758
static void rpmSetMachine(const char *arch, const char *os)
Definition: rpmrc.c:838
#define VARPREFIX
Definition: config.h:1267
static void machCacheEntryVisit(machCache cache, machEquivTable table, const char *name, int distance)
Definition: rpmrc.c:189
int rpmdsRpmlib(rpmds *dsp, void *tblp)
Load rpmlib provides into a dependency set.
Definition: rpmds.c:1589
RPM pattern matching.
int argvCount(const ARGV_t argv)
Return no.
Definition: argv.c:71
static int xisspace(int c)
Definition: rpmiotypes.h:446
hashTable htFree(hashTable ht)
Destroy hash table.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
struct miRE_s * miRE
Definition: mire.h:60
const char * rpmluaGetPrintBuffer(rpmlua _lua)
static void setPathDefault(const char *macroname, const char *subdir)
Definition: rpmrc.c:281
static void getMachineInfo(int type, const char **name, int *num)
Definition: rpmrc.c:879
static const char * file
Definition: parseFiles.c:20
struct machEquivInfo_s * machEquivInfo
const char * rpmluaFiles
int rpmdsNext(rpmds ds)
Return next dependency set iterator index.
Definition: rpmds.c:912
Structure(s) used for dependency tag sets.
struct machCache_s * machCache
const char * defName
Definition: rpmrc.c:89
The FD_t File Handle data structure.
const char * rpmMacrofiles
List of macro files to read when configuring rpm.
Definition: macro.c:62
const char * name
Definition: rpmrc.c:93
void rpmDumpMacroTable(MacroContext mc, FILE *fp)
Print macros to file stream.
Definition: macro.c:285
int mireRegexec(miRE mire, const char *val, size_t vallen)
Execute pattern match.
Definition: mire.c:398
struct machCacheEntry_s * machCacheEntry
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
Definition: strcasecmp.c:9
int size
Definition: rpmrc.c:74
static void addMacroDefault(const char *macroname, const char *val, const char *body)
Definition: rpmrc.c:271
char * rpmExpand(const char *arg,...)
Return (malloc&#39;ed) concatenated macro expansion(s).
Definition: macro.c:3117
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
Definition: rpmio.c:2412
static int parseCVOG(const char *str, CVOG_t *cvogp)
Definition: rpmrc.c:383
const char * os
Definition: rpmrc.c:372
static canonEntry lookupInCanonTable(const char *name, const canonEntry table, int tableLen)
Definition: rpmrc.c:241
const char * short_name
Definition: rpmrc.c:94
static void rpmSetTables(int archTable, int osTable)
Definition: rpmrc.c:817
#define SYSCONFIGDIR
Definition: config.h:1212
int Fclose(FD_t fd)
fclose(3) clone.
Definition: rpmio.c:2534
#define USRLIBRPM
Definition: config.h:1261
struct defaultEntry_s * defaultEntry
#define PREMACROFILES
Definition: config.h:1510
struct machCache_s cache
Definition: rpmrc.c:107
const char * name
Definition: rpmrc.c:66
const char * _sysinfo_path
Definition: rpmds.c:1743
enum rpmRC_e rpmRC
RPM return codes.
const char * _cpuinfo_path
Definition: rpmds.c:1321
void htAddEntry(hashTable ht, const void *key, const void *data)
Add item to hash table.
Definition: rpmhash.c:150
machEquivInfo list
Definition: rpmrc.c:84
void * platpat
Definition: rpmrc.c:44
static const char * lookupInDefaultTable(const char *name, const defaultEntry table, int tableLen)
Definition: rpmrc.c:258
rpmds rpmdsLink(rpmds ds, const char *msg)
Reference a dependency set instance.
const char * str
Definition: rpmrc.c:366
int canonsLength
Definition: rpmrc.c:111
#define RMIL_RPMRC
Definition: rpmmacro.h:52
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:57
int rpmShowRC(FILE *fp)
Definition: rpmrc.c:1149
int rpmdsCpuinfo(rpmds *dsp, const char *fn)
Load /proc/cpuinfo provides into a dependency set.
Definition: rpmds.c:1323
int rpmdsUname(rpmds *dsp, const struct utsname *un)
Definition: rpmds.c:4120
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
Definition: argv.c:233
#define rpmIsVerbose()
Definition: rpmcb.h:21
static void setDefaults(void)
Definition: rpmrc.c:320
#define OS
Definition: rpmrc.c:124
int rpmdsMatch(const rpmds A, rpmds B)
Compare A against every member of B, looking for 1st match.
Definition: rpmds.c:4485
static int defaultsInitialized
Definition: rpmrc.c:134
#define RMIL_DEFAULT
Markers for sources of macros added throughout rpm.
Definition: rpmmacro.h:50
struct machEquivTable_s * machEquivTable
#define rpmIsDebug()
Definition: rpmcb.h:23
defaultEntry defaults
Definition: rpmrc.c:108
int mireAppend(rpmMireMode mode, int tag, const char *pattern, const unsigned char *table, miRE *mirep, int *nmirep)
Append pattern to array.
Definition: mire.c:499
#define _(Text)
Definition: system.h:30
#define xmalloc
Definition: system.h:33
const char * cptr_t
Definition: rpmrc.c:63
#define ARCH
Definition: rpmrc.c:125
static int rpmReadRC(const char *macrofiles)
Read macro configuration file(s).
Definition: rpmrc.c:1073
ARGstr_t * ARGV_t
Definition: argv.h:9
const char * vendor
Definition: rpmrc.c:370
static cptr_t current[2]
Definition: rpmrc.c:128
hashTable htCreate(int numBuckets, size_t keySize, int freeData, hashFunctionType fn, hashEqualityType eq)
Create hash table.
Definition: rpmhash.c:277
struct canonEntry_s * canonEntry
static const char * platform
Definition: rpmrc.c:41
static struct tableType_s tables[4]
Definition: rpmrc.c:116
static void machAddEquiv(machEquivTable table, const char *name, int distance)
Definition: rpmrc.c:161
static rpmRC rpmPlatform(const char *platform)
Read and configure /etc/rpm/platform patterns.
Definition: rpmrc.c:440
#define xrealloc
Definition: system.h:36
void rpmFreeRpmrc(void)
Definition: rpmrc.c:1008
struct tableType_s * tableType
#define RPM_MACHTABLE_COUNT
Definition: rpmrc.c:61
const char *const key
Definition: rpmrc.c:103
rpmds rpmdsFromPRCO(rpmPRCO PRCO, rpmTag tagN)
Retrieve a dependency set from container.
Definition: rpmds.c:2903
static int currTables[2]
Definition: rpmrc.c:131