Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "log_manager.hpp" |
| 4 | |
| 5 | #include "elog_entry.hpp" |
| 6 | #include "elog_meta.hpp" |
| 7 | #include "elog_serialize.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 8 | #include "extensions.hpp" |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 9 | #include "util.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 10 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 11 | #include <poll.h> |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 12 | #include <sys/inotify.h> |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 13 | #include <systemd/sd-bus.h> |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 14 | #include <systemd/sd-journal.h> |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 15 | #include <unistd.h> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 16 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 17 | #include <cassert> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 18 | #include <chrono> |
| 19 | #include <cstdio> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 20 | #include <cstring> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 21 | #include <fstream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 22 | #include <functional> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 23 | #include <future> |
| 24 | #include <iostream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 25 | #include <map> |
Saqib Khan | 2bb1519 | 2017-02-13 13:19:55 -0600 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | #include <sdbusplus/vtable.hpp> |
| 28 | #include <set> |
| 29 | #include <string> |
| 30 | #include <vector> |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 31 | #include <xyz/openbmc_project/State/Host/server.hpp> |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 32 | |
| 33 | using namespace phosphor::logging; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 34 | using namespace std::chrono; |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 35 | using sdbusplus::exception::SdBusError; |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 36 | extern const std::map<metadata::Metadata, |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 37 | std::function<metadata::associations::Type>> |
| 38 | meta; |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 39 | |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 40 | namespace phosphor |
| 41 | { |
| 42 | namespace logging |
| 43 | { |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 44 | namespace internal |
| 45 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 46 | inline auto getLevel(const std::string& errMsg) |
| 47 | { |
| 48 | auto reqLevel = Entry::Level::Error; // Default to Error |
| 49 | |
| 50 | auto levelmap = g_errLevelMap.find(errMsg); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 51 | if (levelmap != g_errLevelMap.end()) |
Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 52 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 53 | reqLevel = static_cast<Entry::Level>(levelmap->second); |
Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 56 | return reqLevel; |
| 57 | } |
| 58 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 59 | int Manager::getRealErrSize() |
| 60 | { |
| 61 | return realErrors.size(); |
| 62 | } |
| 63 | |
| 64 | int Manager::getInfoErrSize() |
| 65 | { |
| 66 | return infoErrors.size(); |
| 67 | } |
| 68 | |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 69 | void Manager::commit(uint64_t transactionId, std::string errMsg) |
| 70 | { |
| 71 | auto level = getLevel(errMsg); |
| 72 | _commit(transactionId, std::move(errMsg), level); |
| 73 | } |
| 74 | |
| 75 | void Manager::commitWithLvl(uint64_t transactionId, std::string errMsg, |
| 76 | uint32_t errLvl) |
| 77 | { |
| 78 | _commit(transactionId, std::move(errMsg), |
| 79 | static_cast<Entry::Level>(errLvl)); |
| 80 | } |
| 81 | |
| 82 | void Manager::_commit(uint64_t transactionId, std::string&& errMsg, |
| 83 | Entry::Level errLvl) |
| 84 | { |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 85 | constexpr const auto transactionIdVar = "TRANSACTION_ID"; |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 86 | // Length of 'TRANSACTION_ID' string. |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 87 | constexpr const auto transactionIdVarSize = std::strlen(transactionIdVar); |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 88 | // Length of 'TRANSACTION_ID=' string. |
| 89 | constexpr const auto transactionIdVarOffset = transactionIdVarSize + 1; |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 90 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 91 | // Flush all the pending log messages into the journal |
| 92 | journalSync(); |
Adriana Kobylak | cfd9a7d | 2017-06-07 11:57:31 -0500 | [diff] [blame] | 93 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 94 | sd_journal* j = nullptr; |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 95 | int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 96 | if (rc < 0) |
| 97 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 98 | logging::log<logging::level::ERR>( |
| 99 | "Failed to open journal", |
| 100 | logging::entry("DESCRIPTION=%s", strerror(-rc))); |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 101 | return; |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 104 | std::string transactionIdStr = std::to_string(transactionId); |
Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 105 | std::set<std::string> metalist; |
| 106 | auto metamap = g_errMetaMap.find(errMsg); |
| 107 | if (metamap != g_errMetaMap.end()) |
| 108 | { |
| 109 | metalist.insert(metamap->second.begin(), metamap->second.end()); |
| 110 | } |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 111 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 112 | // Add _PID field information in AdditionalData. |
Jayanth Othayoth | db18ebe | 2017-09-04 00:48:02 -0500 | [diff] [blame] | 113 | metalist.insert("_PID"); |
| 114 | |
Tom Joseph | 7a33ee4 | 2017-07-25 00:04:20 +0530 | [diff] [blame] | 115 | std::vector<std::string> additionalData; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 116 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 117 | // Read the journal from the end to get the most recent entry first. |
| 118 | // The result from the sd_journal_get_data() is of the form VARIABLE=value. |
| 119 | SD_JOURNAL_FOREACH_BACKWARDS(j) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 120 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 121 | const char* data = nullptr; |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 122 | size_t length = 0; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 123 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 124 | // Look for the transaction id metadata variable |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 125 | rc = sd_journal_get_data(j, transactionIdVar, (const void**)&data, |
| 126 | &length); |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 127 | if (rc < 0) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 128 | { |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 129 | // This journal entry does not have the TRANSACTION_ID |
| 130 | // metadata variable. |
| 131 | continue; |
| 132 | } |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 133 | |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 134 | // journald does not guarantee that sd_journal_get_data() returns NULL |
| 135 | // terminated strings, so need to specify the size to use to compare, |
| 136 | // use the returned length instead of anything that relies on NULL |
| 137 | // terminators like strlen(). |
| 138 | // The data variable is in the form of 'TRANSACTION_ID=1234'. Remove |
| 139 | // the TRANSACTION_ID characters plus the (=) sign to do the comparison. |
| 140 | // 'data + transactionIdVarOffset' will be in the form of '1234'. |
| 141 | // 'length - transactionIdVarOffset' will be the length of '1234'. |
| 142 | if ((length <= (transactionIdVarOffset)) || |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 143 | (transactionIdStr.compare(0, transactionIdStr.size(), |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 144 | data + transactionIdVarOffset, |
| 145 | length - transactionIdVarOffset) != 0)) |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 146 | { |
| 147 | // The value of the TRANSACTION_ID metadata is not the requested |
| 148 | // transaction id number. |
| 149 | continue; |
| 150 | } |
| 151 | |
| 152 | // Search for all metadata variables in the current journal entry. |
| 153 | for (auto i = metalist.cbegin(); i != metalist.cend();) |
| 154 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 155 | rc = sd_journal_get_data(j, (*i).c_str(), (const void**)&data, |
| 156 | &length); |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 157 | if (rc < 0) |
| 158 | { |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 159 | // Metadata variable not found, check next metadata variable. |
| 160 | i++; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 161 | continue; |
| 162 | } |
| 163 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 164 | // Metadata variable found, save it and remove it from the set. |
| 165 | additionalData.emplace_back(data, length); |
| 166 | i = metalist.erase(i); |
| 167 | } |
| 168 | if (metalist.empty()) |
| 169 | { |
| 170 | // All metadata variables found, break out of journal loop. |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 171 | break; |
| 172 | } |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 173 | } |
| 174 | if (!metalist.empty()) |
| 175 | { |
| 176 | // Not all the metadata variables were found in the journal. |
| 177 | for (auto& metaVarStr : metalist) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 178 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 179 | logging::log<logging::level::INFO>( |
| 180 | "Failed to find metadata", |
| 181 | logging::entry("META_FIELD=%s", metaVarStr.c_str())); |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 185 | sd_journal_close(j); |
| 186 | |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 187 | createEntry(errMsg, errLvl, additionalData); |
| 188 | } |
| 189 | |
| 190 | void Manager::createEntry(std::string errMsg, Entry::Level errLvl, |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 191 | std::vector<std::string> additionalData, |
| 192 | const FFDCEntries& ffdc) |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 193 | { |
| 194 | if (!Extensions::disableDefaultLogCaps()) |
| 195 | { |
| 196 | if (errLvl < Entry::sevLowerLimit) |
| 197 | { |
| 198 | if (realErrors.size() >= ERROR_CAP) |
| 199 | { |
| 200 | erase(realErrors.front()); |
| 201 | } |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | if (infoErrors.size() >= ERROR_INFO_CAP) |
| 206 | { |
| 207 | erase(infoErrors.front()); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 212 | entryId++; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 213 | if (errLvl >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 214 | { |
| 215 | infoErrors.push_back(entryId); |
| 216 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 217 | else |
| 218 | { |
| 219 | realErrors.push_back(entryId); |
| 220 | } |
Adriana Kobylak | c5f0bbd | 2017-01-22 14:56:04 -0600 | [diff] [blame] | 221 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 222 | std::chrono::system_clock::now().time_since_epoch()) |
| 223 | .count(); |
| 224 | auto objPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 225 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 226 | AssociationList objects{}; |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 227 | processMetadata(errMsg, additionalData, objects); |
| 228 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 229 | auto e = std::make_unique<Entry>(busLog, objPath, entryId, |
| 230 | ms, // Milliseconds since 1970 |
| 231 | errLvl, std::move(errMsg), |
| 232 | std::move(additionalData), |
| 233 | std::move(objects), fwVersion, *this); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 234 | serialize(*e); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 235 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 236 | if (isQuiesceOnErrorEnabled()) |
| 237 | { |
| 238 | checkQuiesceOnError(*e); |
| 239 | } |
| 240 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 241 | doExtensionLogCreate(*e, ffdc); |
| 242 | |
| 243 | // Note: No need to close the file descriptors in the FFDC. |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 244 | |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 245 | entries.insert(std::make_pair(entryId, std::move(e))); |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 246 | } |
| 247 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 248 | bool Manager::isQuiesceOnErrorEnabled() |
| 249 | { |
| 250 | std::variant<bool> property; |
| 251 | |
| 252 | auto method = this->busLog.new_method_call( |
| 253 | "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings", |
| 254 | "org.freedesktop.DBus.Properties", "Get"); |
| 255 | |
| 256 | method.append("xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError"); |
| 257 | |
| 258 | try |
| 259 | { |
| 260 | auto reply = this->busLog.call(method); |
| 261 | reply.read(property); |
| 262 | } |
| 263 | catch (const SdBusError& e) |
| 264 | { |
| 265 | log<level::ERR>("Error reading QuiesceOnHwError property", |
| 266 | entry("ERROR=%s", e.what())); |
| 267 | throw; |
| 268 | } |
| 269 | |
| 270 | return std::get<bool>(property); |
| 271 | } |
| 272 | |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 273 | bool Manager::isCalloutPresent(const Entry& entry) |
| 274 | { |
| 275 | for (const auto& c : entry.additionalData()) |
| 276 | { |
| 277 | if (c.find("CALLOUT_") != std::string::npos) |
| 278 | { |
| 279 | return true; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return false; |
| 284 | } |
| 285 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 286 | void Manager::findAndRemoveResolvedBlocks() |
| 287 | { |
| 288 | for (auto& entry : entries) |
| 289 | { |
| 290 | if (entry.second->resolved()) |
| 291 | { |
| 292 | checkAndRemoveBlockingError(entry.first); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | void Manager::onEntryResolve(sdbusplus::message::message& msg) |
| 298 | { |
| 299 | using Interface = std::string; |
| 300 | using Property = std::string; |
| 301 | using Value = std::string; |
Patrick Williams | 25acc6c | 2020-06-02 11:05:34 -0500 | [diff] [blame] | 302 | using Properties = std::map<Property, std::variant<Value>>; |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 303 | |
| 304 | Interface interface; |
| 305 | Properties properties; |
| 306 | |
| 307 | msg.read(interface, properties); |
| 308 | |
| 309 | for (const auto& p : properties) |
| 310 | { |
| 311 | if (p.first == "Resolved") |
| 312 | { |
| 313 | findAndRemoveResolvedBlocks(); |
| 314 | return; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 319 | void Manager::checkAndQuiesceHost() |
| 320 | { |
| 321 | // First check host state |
| 322 | std::variant<std::string> property; |
| 323 | |
| 324 | auto method = this->busLog.new_method_call( |
| 325 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", |
| 326 | "org.freedesktop.DBus.Properties", "Get"); |
| 327 | |
| 328 | method.append("xyz.openbmc_project.State.Host", "CurrentHostState"); |
| 329 | |
| 330 | try |
| 331 | { |
| 332 | auto reply = this->busLog.call(method); |
| 333 | reply.read(property); |
| 334 | } |
| 335 | catch (const SdBusError& e) |
| 336 | { |
| 337 | // Quiescing the host is a "best effort" type function. If unable to |
| 338 | // read the host state or it comes back empty, just return. |
| 339 | // The boot block object will still be created and the associations to |
| 340 | // find the log will be present. Don't want a dependency with |
| 341 | // phosphor-state-manager service |
| 342 | log<level::INFO>("Error reading QuiesceOnHwError property", |
| 343 | entry("ERROR=%s", e.what())); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | std::string hostState = std::get<std::string>(property); |
| 348 | |
| 349 | // If host state is empty, do nothing |
| 350 | if (hostState.empty()) |
| 351 | { |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | using Host = sdbusplus::xyz::openbmc_project::State::server::Host; |
| 356 | auto state = Host::convertHostStateFromString(hostState); |
| 357 | if (state != Host::HostState::Running) |
| 358 | { |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | auto quiesce = this->busLog.new_method_call( |
| 363 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 364 | "org.freedesktop.systemd1.Manager", "StartUnit"); |
| 365 | |
| 366 | quiesce.append("obmc-host-quiesce@0.target"); |
| 367 | quiesce.append("replace"); |
| 368 | |
| 369 | this->busLog.call_noreply(quiesce); |
| 370 | } |
| 371 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 372 | void Manager::checkQuiesceOnError(const Entry& entry) |
| 373 | { |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 374 | |
| 375 | if (!isCalloutPresent(entry)) |
| 376 | { |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | logging::log<logging::level::INFO>( |
| 381 | "QuiesceOnError set and callout present"); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 382 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 383 | auto blockPath = |
| 384 | std::string(OBJ_LOGGING) + "/block" + std::to_string(entry.id()); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 385 | auto blockObj = |
| 386 | std::make_unique<Block>(this->busLog, blockPath, entry.id()); |
| 387 | this->blockingErrors.push_back(std::move(blockObj)); |
| 388 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 389 | // Register call back if log is resolved |
| 390 | using namespace sdbusplus::bus::match::rules; |
| 391 | auto entryPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entry.id()); |
| 392 | auto callback = std::make_unique<sdbusplus::bus::match::match>( |
| 393 | this->busLog, |
| 394 | propertiesChanged(entryPath, "xyz.openbmc_project.Logging.Entry"), |
| 395 | std::bind(std::mem_fn(&Manager::onEntryResolve), this, |
| 396 | std::placeholders::_1)); |
| 397 | |
| 398 | propChangedEntryCallback.insert( |
| 399 | std::make_pair(entry.id(), std::move(callback))); |
| 400 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 401 | checkAndQuiesceHost(); |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 404 | void Manager::doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 405 | { |
| 406 | // Make the association <endpointpath>/<endpointtype> paths |
| 407 | std::vector<std::string> assocs; |
| 408 | for (const auto& [forwardType, reverseType, endpoint] : |
| 409 | entry.associations()) |
| 410 | { |
| 411 | std::string e{endpoint}; |
| 412 | e += '/' + reverseType; |
| 413 | assocs.push_back(e); |
| 414 | } |
| 415 | |
| 416 | for (auto& create : Extensions::getCreateFunctions()) |
| 417 | { |
| 418 | try |
| 419 | { |
| 420 | create(entry.message(), entry.id(), entry.timestamp(), |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 421 | entry.severity(), entry.additionalData(), assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 422 | } |
| 423 | catch (std::exception& e) |
| 424 | { |
| 425 | log<level::ERR>("An extension's create function threw an exception", |
| 426 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 431 | void Manager::processMetadata(const std::string& errorName, |
| 432 | const std::vector<std::string>& additionalData, |
| 433 | AssociationList& objects) const |
| 434 | { |
| 435 | // additionalData is a list of "metadata=value" |
| 436 | constexpr auto separator = '='; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 437 | for (const auto& entryItem : additionalData) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 438 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 439 | auto found = entryItem.find(separator); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 440 | if (std::string::npos != found) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 441 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 442 | auto metadata = entryItem.substr(0, found); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 443 | auto iter = meta.find(metadata); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 444 | if (meta.end() != iter) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 445 | { |
| 446 | (iter->second)(metadata, additionalData, objects); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 452 | void Manager::checkAndRemoveBlockingError(uint32_t entryId) |
| 453 | { |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 454 | // First look for blocking object and remove |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 455 | auto it = find_if( |
| 456 | blockingErrors.begin(), blockingErrors.end(), |
| 457 | [&](std::unique_ptr<Block>& obj) { return obj->entryId == entryId; }); |
| 458 | if (it != blockingErrors.end()) |
| 459 | { |
| 460 | blockingErrors.erase(it); |
| 461 | } |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 462 | |
| 463 | // Now remove the callback looking for the error to be resolved |
| 464 | auto resolveFind = propChangedEntryCallback.find(entryId); |
| 465 | if (resolveFind != propChangedEntryCallback.end()) |
| 466 | { |
| 467 | propChangedEntryCallback.erase(resolveFind); |
| 468 | } |
| 469 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 473 | void Manager::erase(uint32_t entryId) |
| 474 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 475 | auto entryFound = entries.find(entryId); |
| 476 | if (entries.end() != entryFound) |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 477 | { |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 478 | for (auto& func : Extensions::getDeleteProhibitedFunctions()) |
| 479 | { |
| 480 | try |
| 481 | { |
| 482 | bool prohibited = false; |
| 483 | func(entryId, prohibited); |
| 484 | if (prohibited) |
| 485 | { |
| 486 | // Future work remains to throw an error here. |
| 487 | return; |
| 488 | } |
| 489 | } |
| 490 | catch (std::exception& e) |
| 491 | { |
| 492 | log<level::ERR>( |
| 493 | "An extension's deleteProhibited function threw " |
| 494 | "an exception", |
| 495 | entry("ERROR=%s", e.what())); |
| 496 | } |
| 497 | } |
| 498 | |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 499 | // Delete the persistent representation of this error. |
| 500 | fs::path errorPath(ERRLOG_PERSIST_PATH); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 501 | errorPath /= std::to_string(entryId); |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 502 | fs::remove(errorPath); |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 503 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 504 | auto removeId = [](std::list<uint32_t>& ids, uint32_t id) { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 505 | auto it = std::find(ids.begin(), ids.end(), id); |
| 506 | if (it != ids.end()) |
| 507 | { |
| 508 | ids.erase(it); |
| 509 | } |
| 510 | }; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 511 | if (entryFound->second->severity() >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 512 | { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 513 | removeId(infoErrors, entryId); |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | removeId(realErrors, entryId); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 518 | } |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 519 | entries.erase(entryFound); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 520 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 521 | checkAndRemoveBlockingError(entryId); |
| 522 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 523 | for (auto& remove : Extensions::getDeleteFunctions()) |
| 524 | { |
| 525 | try |
| 526 | { |
| 527 | remove(entryId); |
| 528 | } |
| 529 | catch (std::exception& e) |
| 530 | { |
| 531 | log<level::ERR>("An extension's delete function threw an " |
| 532 | "exception", |
| 533 | entry("ERROR=%s", e.what())); |
| 534 | } |
| 535 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 536 | } |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 537 | else |
| 538 | { |
| 539 | logging::log<level::ERR>("Invalid entry ID to delete", |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 540 | logging::entry("ID=%d", entryId)); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 541 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 542 | } |
| 543 | |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 544 | void Manager::restore() |
| 545 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 546 | auto sanity = [](const auto& id, const auto& restoredId) { |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 547 | return id == restoredId; |
| 548 | }; |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 549 | std::vector<uint32_t> errorIds; |
| 550 | |
| 551 | fs::path dir(ERRLOG_PERSIST_PATH); |
| 552 | if (!fs::exists(dir) || fs::is_empty(dir)) |
| 553 | { |
| 554 | return; |
| 555 | } |
| 556 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 557 | for (auto& file : fs::directory_iterator(dir)) |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 558 | { |
| 559 | auto id = file.path().filename().c_str(); |
| 560 | auto idNum = std::stol(id); |
| 561 | auto e = std::make_unique<Entry>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 562 | busLog, std::string(OBJ_ENTRY) + '/' + id, idNum, *this); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 563 | if (deserialize(file.path(), *e)) |
| 564 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 565 | // validate the restored error entry id |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 566 | if (sanity(static_cast<uint32_t>(idNum), e->id())) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 567 | { |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 568 | e->emit_object_added(); |
| 569 | if (e->severity() >= Entry::sevLowerLimit) |
| 570 | { |
| 571 | infoErrors.push_back(idNum); |
| 572 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 573 | else |
| 574 | { |
| 575 | realErrors.push_back(idNum); |
| 576 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 577 | |
| 578 | entries.insert(std::make_pair(idNum, std::move(e))); |
| 579 | errorIds.push_back(idNum); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 580 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 581 | else |
| 582 | { |
| 583 | logging::log<logging::level::ERR>( |
| 584 | "Failed in sanity check while restoring error entry. " |
| 585 | "Ignoring error entry", |
| 586 | logging::entry("ID_NUM=%d", idNum), |
| 587 | logging::entry("ENTRY_ID=%d", e->id())); |
| 588 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Vishwanatha Subbanna | 37af9ba | 2017-09-28 16:33:53 +0530 | [diff] [blame] | 592 | if (!errorIds.empty()) |
| 593 | { |
| 594 | entryId = *(std::max_element(errorIds.begin(), errorIds.end())); |
| 595 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 596 | } |
| 597 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 598 | void Manager::journalSync() |
| 599 | { |
| 600 | bool syncRequested = false; |
| 601 | auto fd = -1; |
| 602 | auto rc = -1; |
| 603 | auto wd = -1; |
| 604 | auto bus = sdbusplus::bus::new_default(); |
| 605 | |
| 606 | auto start = |
| 607 | duration_cast<microseconds>(steady_clock::now().time_since_epoch()) |
| 608 | .count(); |
| 609 | |
Matthew Barth | 5991389 | 2019-08-27 15:43:48 -0500 | [diff] [blame] | 610 | // Each time an error log is committed, a request to sync the journal |
| 611 | // must occur and block that error log commit until it completes. A 5sec |
| 612 | // block is done to allow sufficient time for the journal to be synced. |
| 613 | // |
| 614 | // Number of loop iterations = 3 for the following reasons: |
| 615 | // Iteration #1: Requests a journal sync by killing the journald service. |
| 616 | // Iteration #2: Setup an inotify watch to monitor the synced file that |
| 617 | // journald updates with the timestamp the last time the |
| 618 | // journal was flushed. |
| 619 | // Iteration #3: Poll to wait until inotify reports an event which blocks |
| 620 | // the error log from being commited until the sync completes. |
| 621 | constexpr auto maxRetry = 3; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 622 | for (int i = 0; i < maxRetry; i++) |
| 623 | { |
| 624 | // Read timestamp from synced file |
| 625 | constexpr auto syncedPath = "/run/systemd/journal/synced"; |
| 626 | std::ifstream syncedFile(syncedPath); |
| 627 | if (syncedFile.fail()) |
| 628 | { |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 629 | // If the synced file doesn't exist, a sync request will create it. |
| 630 | if (errno != ENOENT) |
| 631 | { |
| 632 | log<level::ERR>("Failed to open journal synced file", |
| 633 | entry("FILENAME=%s", syncedPath), |
| 634 | entry("ERRNO=%d", errno)); |
| 635 | return; |
| 636 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 637 | } |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 638 | else |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 639 | { |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 640 | // Only read the synced file if it exists. |
| 641 | // See if a sync happened by now |
| 642 | std::string timestampStr; |
| 643 | std::getline(syncedFile, timestampStr); |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 644 | auto timestamp = std::stoll(timestampStr); |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 645 | if (timestamp >= start) |
| 646 | { |
Troy Lee | b7f392a | 2019-11-19 14:34:56 +0800 | [diff] [blame] | 647 | break; |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 648 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // Let's ask for a sync, but only once |
| 652 | if (!syncRequested) |
| 653 | { |
| 654 | syncRequested = true; |
| 655 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 656 | constexpr auto JOURNAL_UNIT = "systemd-journald.service"; |
| 657 | auto signal = SIGRTMIN + 1; |
| 658 | |
| 659 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 660 | SYSTEMD_INTERFACE, "KillUnit"); |
| 661 | method.append(JOURNAL_UNIT, "main", signal); |
| 662 | bus.call(method); |
| 663 | if (method.is_method_error()) |
| 664 | { |
| 665 | log<level::ERR>("Failed to kill journal service"); |
Troy Lee | b7f392a | 2019-11-19 14:34:56 +0800 | [diff] [blame] | 666 | break; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 667 | } |
| 668 | continue; |
| 669 | } |
| 670 | |
| 671 | // Let's install the inotify watch, if we didn't do that yet. This watch |
| 672 | // monitors the syncedFile for when journald updates it with a newer |
| 673 | // timestamp. This means the journal has been flushed. |
| 674 | if (fd < 0) |
| 675 | { |
| 676 | fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); |
| 677 | if (fd < 0) |
| 678 | { |
| 679 | log<level::ERR>("Failed to create inotify watch", |
| 680 | entry("ERRNO=%d", errno)); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | constexpr auto JOURNAL_RUN_PATH = "/run/systemd/journal"; |
| 685 | wd = inotify_add_watch(fd, JOURNAL_RUN_PATH, |
| 686 | IN_MOVED_TO | IN_DONT_FOLLOW | IN_ONLYDIR); |
| 687 | if (wd < 0) |
| 688 | { |
| 689 | log<level::ERR>("Failed to watch journal directory", |
| 690 | entry("PATH=%s", JOURNAL_RUN_PATH), |
| 691 | entry("ERRNO=%d", errno)); |
| 692 | close(fd); |
| 693 | return; |
| 694 | } |
| 695 | continue; |
| 696 | } |
| 697 | |
| 698 | // Let's wait until inotify reports an event |
| 699 | struct pollfd fds = { |
| 700 | .fd = fd, |
| 701 | .events = POLLIN, |
| 702 | }; |
| 703 | constexpr auto pollTimeout = 5; // 5 seconds |
| 704 | rc = poll(&fds, 1, pollTimeout * 1000); |
| 705 | if (rc < 0) |
| 706 | { |
| 707 | log<level::ERR>("Failed to add event", entry("ERRNO=%d", errno), |
| 708 | entry("ERR=%s", strerror(-rc))); |
| 709 | inotify_rm_watch(fd, wd); |
| 710 | close(fd); |
| 711 | return; |
| 712 | } |
| 713 | else if (rc == 0) |
| 714 | { |
| 715 | log<level::INFO>("Poll timeout, no new journal synced data", |
| 716 | entry("TIMEOUT=%d", pollTimeout)); |
| 717 | break; |
| 718 | } |
| 719 | |
| 720 | // Read from the specified file descriptor until there is no new data, |
| 721 | // throwing away everything read since the timestamp will be read at the |
| 722 | // beginning of the loop. |
| 723 | constexpr auto maxBytes = 64; |
| 724 | uint8_t buffer[maxBytes]; |
| 725 | while (read(fd, buffer, maxBytes) > 0) |
| 726 | ; |
| 727 | } |
| 728 | |
Adriana Kobylak | 4a029f2 | 2018-05-23 12:58:19 -0500 | [diff] [blame] | 729 | if (fd != -1) |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 730 | { |
Adriana Kobylak | 4a029f2 | 2018-05-23 12:58:19 -0500 | [diff] [blame] | 731 | if (wd != -1) |
| 732 | { |
| 733 | inotify_rm_watch(fd, wd); |
| 734 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 735 | close(fd); |
| 736 | } |
| 737 | |
| 738 | return; |
| 739 | } |
| 740 | |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 741 | std::string Manager::readFWVersion() |
| 742 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 743 | auto version = util::getOSReleaseValue("VERSION_ID"); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 744 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 745 | if (!version) |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 746 | { |
| 747 | log<level::ERR>("Unable to read BMC firmware version"); |
| 748 | } |
| 749 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 750 | return version.value_or(""); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 751 | } |
| 752 | |
Matt Spinler | 3fb83b3 | 2019-07-26 11:22:44 -0500 | [diff] [blame] | 753 | void Manager::create(const std::string& message, Entry::Level severity, |
| 754 | const std::map<std::string, std::string>& additionalData) |
| 755 | { |
| 756 | // Convert the map into a vector of "key=value" strings |
| 757 | std::vector<std::string> ad; |
| 758 | metadata::associations::combine(additionalData, ad); |
| 759 | |
| 760 | createEntry(message, severity, ad); |
| 761 | } |
| 762 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 763 | void Manager::createWithFFDC( |
| 764 | const std::string& message, Entry::Level severity, |
| 765 | const std::map<std::string, std::string>& additionalData, |
| 766 | const FFDCEntries& ffdc) |
| 767 | { |
| 768 | // Convert the map into a vector of "key=value" strings |
| 769 | std::vector<std::string> ad; |
| 770 | metadata::associations::combine(additionalData, ad); |
| 771 | |
| 772 | createEntry(message, severity, ad, ffdc); |
| 773 | } |
| 774 | |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 775 | } // namespace internal |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 776 | } // namespace logging |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 777 | } // namespace phosphor |