mirror of https://github.com/Icinga/icinga2.git
parent
dcc8704e2d
commit
b30069c282
|
@ -34,6 +34,7 @@
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <boost/exception/errinfo_api_function.hpp>
|
#include <boost/exception/errinfo_api_function.hpp>
|
||||||
#include <boost/exception/errinfo_errno.hpp>
|
#include <boost/exception/errinfo_errno.hpp>
|
||||||
#include <boost/exception/errinfo_file_name.hpp>
|
#include <boost/exception/errinfo_file_name.hpp>
|
||||||
|
@ -487,42 +488,58 @@ static String UnameHelper(char type)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String LsbReleaseHelper(void)
|
int ReleaseHelper(std::string &result)
|
||||||
{
|
{
|
||||||
String result = "Could not get release string";
|
/* You are useing *some* distribution */
|
||||||
FILE *fp = popen("lsb_release -s -d 2>&1", "r");
|
FILE *fp = popen("lsb_release -s -d 2>&1", "r");
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), fp) != NULL)
|
while (fgets(line, sizeof(line), fp) != NULL)
|
||||||
msgbuf << line;
|
msgbuf << line;
|
||||||
|
|
||||||
int status = pclose(fp);
|
int status = pclose(fp);
|
||||||
|
|
||||||
if (WEXITSTATUS(status) == 0) {
|
if (WEXITSTATUS(status) == 0) {
|
||||||
result = msgbuf.str();
|
result = msgbuf.str();
|
||||||
result.Trim();
|
boost::trim(result);
|
||||||
return result;
|
return result.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* You have systemd or Ubuntu etc. */
|
||||||
std::ifstream release("/etc/os-release");
|
std::ifstream release("/etc/os-release");
|
||||||
if (!release.is_open())
|
|
||||||
return result;
|
|
||||||
std::string release_line;
|
std::string release_line;
|
||||||
|
if (release.is_open()) {
|
||||||
while (getline(release, release_line)) {
|
while (getline(release, release_line)) {
|
||||||
if (release_line.find("PRETTY_NAME") != std::string::npos) {
|
if (release_line.find("PRETTY_NAME") != std::string::npos) {
|
||||||
result = release_line.substr(13, release_line.length() - 14);
|
result = release_line.substr(13, release_line.length() - 14);
|
||||||
break;
|
return result.length();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
release.close();
|
|
||||||
|
|
||||||
return result;
|
/* Centos < 7 */
|
||||||
|
release.close();
|
||||||
|
release.open("/etc/redhat-release");
|
||||||
|
if (release.is_open()) {
|
||||||
|
getline(release, release_line);
|
||||||
|
result = release_line;
|
||||||
|
return result.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sles 11 sp3, opensuse w/e */
|
||||||
|
release.close();
|
||||||
|
release.open("etc/SuSE-release");
|
||||||
|
if (release.is_open()) {
|
||||||
|
getline(release, release_line);
|
||||||
|
result = release_line;
|
||||||
|
return result.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Just give up */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -554,7 +571,9 @@ void Application::DisplayInfoMessage(std::ostream& os, bool skipVersion)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
os << " Distribution: " << LsbReleaseHelper() << "\n";
|
std::string release;
|
||||||
|
if (ReleaseHelper(release))
|
||||||
|
os << " Distribution: " << release << "\n";
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue