| 79 | |
| 80 | |
| 81 | const std::string PlatformInfo::str() const |
| 82 | { |
| 83 | std::string os_name{}; |
| 84 | |
| 85 | if (proxy) |
| 86 | { |
| 87 | try |
| 88 | { |
| 89 | os_name = proxy->GetProperty<std::string>(hostname1_tgt, |
| 90 | "OperatingSystemCPEName"); |
| 91 | } |
| 92 | catch (const DBus::Exception &) |
| 93 | { |
| 94 | // Ignore errors; os_name will be empty |
| 95 | } |
| 96 | |
| 97 | if (os_name.empty()) |
| 98 | { |
| 99 | try |
| 100 | { |
| 101 | os_name = proxy->GetProperty<std::string>(hostname1_tgt, |
| 102 | "OperatingSystemPrettyName"); |
| 103 | } |
| 104 | catch (const DBus::Exception &) |
| 105 | { |
| 106 | // Ignore errors, os_name will be empty in this case |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // uname() fallback when D-Bus calls fails |
| 112 | if (os_name.empty()) |
| 113 | { |
| 114 | struct utsname info = {}; |
| 115 | if (uname(&info) < 0) |
| 116 | { |
| 117 | throw PlatformInfoException( |
| 118 | "Error retrieving platform information"); |
| 119 | } |
| 120 | |
| 121 | os_name = std::string("generic:") + std::string(info.sysname) + "/" |
| 122 | + std::string(info.release) + "/" + std::string(info.version) |
| 123 | + "/" + std::string(info.machine); |
| 124 | } |
| 125 | return os_name; |
| 126 | } |
no test coverage detected