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