From 7cc1c8cfcc620dec284204be0ae4416fd9fed95d Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex.kanavin@gmail.com>
Date: Fri, 20 Jan 2017 13:33:05 +0200
Subject: [PATCH] Add support for prefixing /etc from RPM_ETCCONFIGDIR
 environment variable

This is needed so that rpm can pick up target-specific configuration
from target rootfs instead of its own native sysroot.

Upstream-Status: Inappropriate [oe-core specific]
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
---
 lib/rpmrc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/rpmrc.c b/lib/rpmrc.c
index dc8d42aeb..3f2996850 100644
--- a/lib/rpmrc.c
+++ b/lib/rpmrc.c
@@ -481,11 +481,14 @@ static void setDefaults(void)
 	    userrc = xstrdup(oldrc);
 	}
     }
+    const char *etcconfdir = getenv("RPM_ETCCONFIGDIR");
+    if (etcconfdir == NULL)
+        etcconfdir = "";
 
     if (!defrcfiles) {
 	defrcfiles = rstrscat(NULL, confdir, "/rpmrc", ":",
 				confdir, "/" RPM_VENDOR "/rpmrc", ":",
-				SYSCONFDIR "/rpmrc", NULL);
+				etcconfdir, SYSCONFDIR "/rpmrc", NULL);
     }
 
     /* macrofiles may be pre-set from --macros */
@@ -495,9 +498,9 @@ static void setDefaults(void)
 				confdir, "/platform/%{_target}/macros", ":",
 				confdir, "/fileattrs/*.attr", ":",
 				confdir, "/" RPM_VENDOR "/macros", ":",
-				SYSCONFDIR "/rpm/macros.*", ":",
-				SYSCONFDIR "/rpm/macros", ":",
-				SYSCONFDIR "/rpm/%{_target}/macros", NULL);
+				etcconfdir, SYSCONFDIR "/rpm/macros.*", ":",
+				etcconfdir, SYSCONFDIR "/rpm/macros", ":",
+				etcconfdir, SYSCONFDIR "/rpm/%{_target}/macros", NULL);
     }
 
     free(usermacros);
@@ -1142,7 +1145,11 @@ static void read_auxv(void)
  */
 static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
 {
-    const char * const platform_path = SYSCONFDIR "/rpm/platform";
+    const char *etcconfdir = getenv("RPM_ETCCONFIGDIR");
+    if (etcconfdir == NULL)
+        etcconfdir = "";
+
+    const char * const platform_path = rstrscat(NULL, etcconfdir, SYSCONFDIR "/rpm/platform", NULL);
     static struct utsname un;
     char * chptr;
     canonEntry canon;
@@ -1462,6 +1469,7 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
 
     if (arch) *arch = un.machine;
     if (os) *os = un.sysname;
+    free(platform_path);
 }
 
 static
