From 8e2ecbc7ac68571f972d8674e4c59b02d92b6ea9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 May 2021 12:12:15 -0400 Subject: [PATCH] detect Linux distribution, if possible and include in OS info output --- src/info.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/info.cpp b/src/info.cpp index 099a4582dc..512858b9f2 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -39,6 +39,7 @@ #include "pair.h" #include "pair_hybrid.h" #include "region.h" +#include "text_file_reader.h" #include "update.h" #include "variable.h" @@ -1261,7 +1262,25 @@ std::string Info::get_os_info() #else struct utsname ut; uname(&ut); - buf = fmt::format("{} {} on {}", ut.sysname, ut.release, ut.machine); + + // try to get OS distribution name, if available + std::string distro = ut.sysname; + if (utils::file_is_readable("/etc/os-release")) { + try { + TextFileReader reader("/etc/os-release",""); + while (1) { + auto words = reader.next_values(0,"="); + if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) { + distro += " " + utils::trim(words.next_string()); + break; + } + } + } catch (std::exception &e) { + ; // EOF but keyword not found + } + } + + buf = fmt::format("{} {} on {}", distro, ut.release, ut.machine); #endif return buf; }