Fix incorrect --version information

fixes #10784
This commit is contained in:
Michael Friedrich 2016-01-26 15:16:59 +01:00 committed by Gunnar Beutner
parent a2cbe1a0d5
commit 9141855454
1 changed files with 37 additions and 24 deletions

View File

@ -1466,6 +1466,39 @@ static bool ReleaseHelper(String *platformName, String *platformVersion)
if (platformVersion)
*platformVersion = "Unknown";
/* You have systemd or Ubuntu etc. */
std::ifstream release("/etc/os-release");
if (release.is_open()) {
std::string release_line;
while (getline(release, release_line)) {
std::string::size_type pos = release_line.find("=");
if (pos == std::string::npos)
continue;
std::string key = release_line.substr(0, pos);
std::string value = release_line.substr(pos + 1);
std::string::size_type firstQuote = value.find("\"");
if (firstQuote != std::string::npos)
value.erase(0, firstQuote + 1);
std::string::size_type lastQuote = value.rfind("\"");
if (lastQuote != std::string::npos)
value.erase(lastQuote);
if (platformName && key == "NAME")
*platformName = value;
if (platformVersion && key == "VERSION")
*platformVersion = value;
}
return true;
}
/* You are using a distribution which supports LSB. */
FILE *fp = popen("lsb_release -s -i 2>&1", "r");
@ -1532,28 +1565,7 @@ static bool ReleaseHelper(String *platformName, String *platformVersion)
}
}
/* You have systemd or Ubuntu etc. */
std::ifstream release("/etc/os-release");
if (release.is_open()) {
std::string release_line;
while (getline(release, release_line)) {
if (platformName) {
if (release_line.find("NAME") != std::string::npos) {
*platformName = release_line.substr(6, release_line.length() - 7);
}
}
if (platformVersion) {
if (release_line.find("VERSION") != std::string::npos) {
*platformVersion = release_line.substr(8, release_line.length() - 9);
}
}
}
return true;
}
/* Centos < 7 */
/* Centos/RHEL < 7 */
release.close();
release.open("/etc/redhat-release");
if (release.is_open()) {
@ -1562,11 +1574,12 @@ static bool ReleaseHelper(String *platformName, String *platformVersion)
String info = release_line;
/* example: Red Hat Enterprise Linux Server release 6.7 (Santiago) */
if (platformName)
*platformName = info.SubStr(0, info.FindFirstOf(" "));
*platformName = info.SubStr(0, info.Find("release") - 1);
if (platformVersion)
*platformVersion = info.SubStr(info.FindFirstOf(" ") + 1);
*platformVersion = info.SubStr(info.Find("release") + 8);
return true;
}