MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ReleaseHelper

Function ReleaseHelper

lib/base/utility.cpp:1628–1733  ·  view source on GitHub ↗

_WIN32 */

Source from the content-addressed store, hash-verified

1626}
1627#endif /* _WIN32 */
1628static bool ReleaseHelper(String *platformName, String *platformVersion)
1629{
1630#ifdef _WIN32
1631 if (platformName)
1632 *platformName = "Windows";
1633
1634 if (platformVersion) {
1635 *platformVersion = "Vista";
1636 if (IsWindowsVistaSP1OrGreater())
1637 *platformVersion = "Vista SP1";
1638 if (IsWindowsVistaSP2OrGreater())
1639 *platformVersion = "Vista SP2";
1640 if (IsWindows7OrGreater())
1641 *platformVersion = "7";
1642 if (IsWindows7SP1OrGreater())
1643 *platformVersion = "7 SP1";
1644 if (IsWindows8OrGreater())
1645 *platformVersion = "8";
1646 if (IsWindows8Point1OrGreater())
1647 *platformVersion = "8.1 or greater";
1648 if (IsWindowsServer())
1649 *platformVersion += " (Server)";
1650 }
1651
1652 return true;
1653#else /* _WIN32 */
1654 if (platformName)
1655 *platformName = "Unknown";
1656
1657 if (platformVersion)
1658 *platformVersion = "Unknown";
1659
1660 /* You have systemd or Ubuntu etc. */
1661 std::ifstream release("/etc/os-release");
1662 if (release.is_open()) {
1663 std::string release_line;
1664 while (getline(release, release_line)) {
1665 std::string::size_type pos = release_line.find("=");
1666
1667 if (pos == std::string::npos)
1668 continue;
1669
1670 std::string key = release_line.substr(0, pos);
1671 std::string value = release_line.substr(pos + 1);
1672
1673 std::string::size_type firstQuote = value.find("\"");
1674
1675 if (firstQuote != std::string::npos)
1676 value.erase(0, firstQuote + 1);
1677
1678 std::string::size_type lastQuote = value.rfind("\"");
1679
1680 if (lastQuote != std::string::npos)
1681 value.erase(lastQuote);
1682
1683 if (platformName && key == "NAME")
1684 *platformName = value;
1685

Callers 2

GetPlatformNameMethod · 0.85
GetPlatformVersionMethod · 0.85

Calls 3

findMethod · 0.80
TrimMethod · 0.80
eraseMethod · 0.45

Tested by

no test coverage detected