Blob Blame History Raw
From 27a8e7be662b9fca6badc8925d5991d5d7abfcfc Mon Sep 17 00:00:00 2001
From: Jonathan Lebon <jonathan@jlebon.com>
Date: Wed, 16 Jun 2021 09:11:43 -0400
Subject: [PATCH] os-release.cpp: make initLibRpm call dnf_context_globals_init

We shouldn't have our separate static var here. Otherwise clients will
incur `rpmReadConfigFiles` twice which breaks their ability to
consistently override macros.

Reported-by: Luca Bruno <lbruno@redhat.com>
Reported-by: Christian Kellner <ckellner@redhat.com>

Fixes: #1273
---
 libdnf/utils/os-release.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libdnf/libdnf/utils/os-release.cpp b/libdnf/libdnf/utils/os-release.cpp
index 1d8a95be65..e2f3d06dd0 100644
--- a/libdnf/libdnf/utils/os-release.cpp
+++ b/libdnf/libdnf/utils/os-release.cpp
@@ -80,12 +80,10 @@ std::map<std::string, std::string> getOsReleaseData()
 
 static void initLibRpm()
 {
-    static bool libRpmInitiated{false};
-    if (libRpmInitiated) return;
-    if (rpmReadConfigFiles(NULL, NULL) != 0) {
-        throw std::runtime_error("failed to read rpm config files\n");
-    }
-    libRpmInitiated = true;
+    // call dnf_context_globals_init to ensure this only happens once
+    g_autoptr(GError) local_error = NULL;
+    if (!dnf_context_globals_init(&local_error))
+        throw std::runtime_error(local_error->message);
 }
 
 static std::string getBaseArch()