]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactor code so we can choose to send the version and build info to a specific stream
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 10 Jul 2024 14:32:09 +0000 (16:32 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 23 Jul 2024 11:15:16 +0000 (13:15 +0200)
pdns/auth-main.cc
pdns/recursordist/rec-main.cc
pdns/version.cc
pdns/version.hh

index 42b00b77926440d3d7ab7fd250c0d8b3d83fce89..94741ff3f27a2252a446957505b8aa58e8ff636b 100644 (file)
@@ -1226,8 +1226,8 @@ int main(int argc, char** argv)
     ::arg().laxParse(argc, argv); // do a lax parse
 
     if (::arg().mustDo("version")) {
-      showProductVersion();
-      showBuildConfiguration();
+      cout << getProductVersion();
+      cout << getBuildConfiguration();
       return 0;
     }
 
@@ -1501,7 +1501,9 @@ int main(int argc, char** argv)
 
   DLOG(g_log << Logger::Warning << "Verbose logging in effect" << endl);
 
-  showProductVersion();
+  for (const string& line : getProductVersionLines()) {
+    g_log << Logger::Info << line << endl;
+  }
 
   try {
     mainthread();
index 7cc45c4308e7812f70cb438282efae16327f9300..f2262f8b3cd9c48f403c368d109699c10d551697 100644 (file)
@@ -3153,8 +3153,8 @@ int main(int argc, char** argv)
     ::arg().laxParse(argc, argv); // do a lax parse
 
     if (::arg().mustDo("version")) {
-      showProductVersion();
-      showBuildConfiguration();
+      cout << getProductVersion();
+      cout << getBuildConfiguration();
       return 0;
     }
     if (::arg().mustDo("help")) {
@@ -3174,7 +3174,10 @@ int main(int argc, char** argv)
     }
     g_log.setLoglevel(s_logUrgency);
     g_log.toConsole(s_logUrgency);
-    showProductVersion();
+
+    for (const string& line : getProductVersionLines()) {
+      g_log << Logger::Info << line << endl;
+    }
     if (!::arg().mustDo("structured-logging")) {
       g_log << Logger::Error << "Disabling structured logging is not supported anymore" << endl;
     }
index d17ac15f18eebba006c1395783692944f4a3f4c1..53c76fd13fc9f3908657fc6e3be9ea411c393da3 100644 (file)
  */
 
 #include "config.h"
-
-#include "logger.hh"
 #include "version.hh"
+#include "namespaces.hh"
+
+#ifdef PDNS_MODULES
 #include "dnsbackend.hh"
+#endif
 
+#include <sstream>
 #include <boost/algorithm/string/join.hpp>
 
 static ProductType productType;
@@ -70,27 +73,40 @@ string productTypeApiType()
   return "unknown";
 }
 
-void showProductVersion()
+vector<string> getProductVersionLines()
 {
-  g_log << Logger::Warning << productName() << " " << VERSION << " (C) "
+  vector<string> ret;
+  std::istringstream istr(getProductVersion());
+  for (string line; std::getline(istr, line);) {
+    ret.emplace_back(line);
+  }
+  return ret;
+}
+
+string getProductVersion()
+{
+  ostringstream ret;
+  ret << productName() << " " << VERSION << " (C) "
                                                                  "PowerDNS.COM BV"
         << endl;
-  g_log << Logger::Warning << "Using " << (sizeof(unsigned long) * 8) << "-bits mode. "
+  ret << "Using " << (sizeof(unsigned long) * 8) << "-bits mode. "
                                                                          "Built using "
         << compilerVersion()
 #ifndef REPRODUCIBLE
         << " on " __DATE__ " " __TIME__ " by " BUILD_HOST
 #endif
         << "." << endl;
-  g_log << Logger::Warning << "PowerDNS comes with ABSOLUTELY NO WARRANTY. "
+  ret << "PowerDNS comes with ABSOLUTELY NO WARRANTY. "
                               "This is free software, and you are welcome to redistribute it "
                               "according to the terms of the GPL version 2."
         << endl;
+  return ret.str();
 }
 
-void showBuildConfiguration()
+string getBuildConfiguration()
 {
-  g_log << Logger::Warning << "Features: "
+  ostringstream ret;
+  ret << "Features: "
         <<
 #ifdef HAVE_LIBDECAF
     "decaf "
@@ -184,19 +200,20 @@ void showBuildConfiguration()
     endl;
 #ifdef PDNS_MODULES
   // Auth only
-  g_log << Logger::Warning << "Built-in modules: " << PDNS_MODULES << endl;
+  ret << "Built-in modules: " << PDNS_MODULES << endl;
   const auto& modules = BackendMakers().getModules();
-  g_log << Logger::Warning << "Loaded modules: " << boost::join(modules, " ") << endl;
+  ret << "Loaded modules: " << boost::join(modules, " ") << endl;
 #endif
 // NOLINTBEGIN(cppcoreguidelines-macro-usage)
 #ifdef PDNS_CONFIG_ARGS
 #define double_escape(s) #s
 #define escape_quotes(s) double_escape(s)
 // NOLINTEND(cppcoreguidelines-macro-usage)
-  g_log << Logger::Warning << "Configured with: " << escape_quotes(PDNS_CONFIG_ARGS) << endl;
+  ret << "Configured with: " << escape_quotes(PDNS_CONFIG_ARGS) << endl;
 #undef escape_quotes
 #undef double_escape
 #endif
+  return ret.str();
 }
 
 string fullVersionString()
index 9d5ef1966af76998c89c6f49ff47620e7953ec9e..c0b63c0a5d1bbc0df789412b43af697141515e7f 100644 (file)
@@ -20,7 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #pragma once
-#include <string>
+#include "namespaces.hh"
 
 enum ProductType
 {
@@ -28,12 +28,13 @@ enum ProductType
   ProductRecursor
 };
 
-std::string compilerVersion();
-void showProductVersion();
-void showBuildConfiguration();
-std::string fullVersionString();
-std::string getPDNSVersion();
-std::string productName();
-std::string productTypeApiType();
+[[nodiscard]] std::string compilerVersion();
+[[nodiscard]] std::vector<std::string> getProductVersionLines();
+[[nodiscard]] std::string getProductVersion();
+[[nodiscard]] std::string getBuildConfiguration();
+[[nodiscard]] std::string fullVersionString();
+[[nodiscard]] std::string getPDNSVersion();
+[[nodiscard]] std::string productName();
+[[nodiscard]] std::string productTypeApiType();
 void versionSetProduct(ProductType productType_);
-ProductType versionGetProduct();
+[[nodiscard]] ProductType versionGetProduct();