Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 1 | #include "elog_entry.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 2 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 3 | #include "elog_serialize.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 4 | #include "log_manager.hpp" |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 5 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | |
| 8 | #include <xyz/openbmc_project/Common/File/error.hpp> |
| 9 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace logging |
| 13 | { |
| 14 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 15 | // TODO Add interfaces to handle the error log id numbering |
| 16 | |
Deepak Kodihalli | 36db46c | 2017-03-31 06:28:44 -0500 | [diff] [blame] | 17 | void Entry::delete_() |
| 18 | { |
| 19 | parent.erase(id()); |
| 20 | } |
| 21 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 22 | bool Entry::resolved(bool value) |
| 23 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 24 | auto current = |
| 25 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(); |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 26 | if (value != current) |
| 27 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 28 | value ? associations({}) : associations(assocs); |
| 29 | current = |
| 30 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved( |
| 31 | value); |
Matt Spinler | 1e71a4d | 2020-03-04 13:40:22 -0600 | [diff] [blame] | 32 | |
| 33 | uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 34 | std::chrono::system_clock::now().time_since_epoch()) |
| 35 | .count(); |
| 36 | updateTimestamp(ms); |
| 37 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 38 | serialize(*this); |
| 39 | } |
| 40 | |
| 41 | return current; |
| 42 | } |
| 43 | |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 44 | std::string Entry::eventId(std::string value) |
| 45 | { |
| 46 | auto current = |
| 47 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId(); |
| 48 | if (value != current) |
| 49 | { |
| 50 | current = |
| 51 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId( |
| 52 | value); |
| 53 | serialize(*this); |
| 54 | } |
| 55 | |
| 56 | return current; |
| 57 | } |
| 58 | |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame^] | 59 | std::string Entry::resolution(std::string value) |
| 60 | { |
| 61 | auto current = |
| 62 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolution(); |
| 63 | if (value != current) |
| 64 | { |
| 65 | current = |
| 66 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolution( |
| 67 | value); |
| 68 | serialize(*this); |
| 69 | } |
| 70 | |
| 71 | return current; |
| 72 | } |
| 73 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 74 | sdbusplus::message::unix_fd Entry::getEntry() |
| 75 | { |
| 76 | FILE* fp = fopen(path().c_str(), "rb"); |
| 77 | if (fp == nullptr) |
| 78 | { |
| 79 | auto e = errno; |
| 80 | log<level::ERR>("Failed to open Entry File", entry("ERRNO=%d", e), |
| 81 | entry("PATH=%s", path().c_str())); |
| 82 | throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open(); |
| 83 | } |
| 84 | |
| 85 | auto fd = fileno(fp); |
| 86 | |
| 87 | // Schedule the fd to be closed by sdbusplus when it sends it back over |
| 88 | // D-Bus. |
| 89 | sdeventplus::Event event = sdeventplus::Event::get_default(); |
| 90 | fdCloseEventSource = std::make_unique<sdeventplus::source::Defer>( |
| 91 | event, std::bind(std::mem_fn(&Entry::closeFD), this, fd, |
| 92 | std::placeholders::_1)); |
| 93 | |
| 94 | return fd; |
| 95 | } |
| 96 | |
Patrick Williams | f40323d | 2021-04-16 15:35:17 -0500 | [diff] [blame] | 97 | void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 98 | { |
| 99 | close(fd); |
| 100 | fdCloseEventSource.reset(); |
| 101 | } |
| 102 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 103 | } // namespace logging |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 104 | } // namespace phosphor |