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