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 | |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/File/error.hpp> |
| 11 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace logging |
| 15 | { |
| 16 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 17 | // TODO Add interfaces to handle the error log id numbering |
| 18 | |
Deepak Kodihalli | 36db46c | 2017-03-31 06:28:44 -0500 | [diff] [blame] | 19 | void Entry::delete_() |
| 20 | { |
| 21 | parent.erase(id()); |
| 22 | } |
| 23 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 24 | bool Entry::resolved(bool value) |
| 25 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 26 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 27 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(); |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 28 | if (value != current) |
| 29 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 30 | value ? associations({}) : associations(assocs); |
| 31 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 32 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 33 | value); |
Matt Spinler | 1e71a4d | 2020-03-04 13:40:22 -0600 | [diff] [blame] | 34 | |
| 35 | uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 36 | std::chrono::system_clock::now().time_since_epoch()) |
| 37 | .count(); |
| 38 | updateTimestamp(ms); |
| 39 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 40 | serialize(*this); |
| 41 | } |
| 42 | |
| 43 | return current; |
| 44 | } |
| 45 | |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 46 | std::string Entry::eventId(std::string value) |
| 47 | { |
| 48 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 49 | sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(); |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 50 | if (value != current) |
| 51 | { |
| 52 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 53 | sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId( |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 54 | value); |
| 55 | serialize(*this); |
| 56 | } |
| 57 | |
| 58 | return current; |
| 59 | } |
| 60 | |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 61 | std::string Entry::resolution(std::string value) |
| 62 | { |
| 63 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 64 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(); |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 65 | if (value != current) |
| 66 | { |
| 67 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 68 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution( |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 69 | value); |
| 70 | serialize(*this); |
| 71 | } |
| 72 | |
| 73 | return current; |
| 74 | } |
| 75 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 76 | sdbusplus::message::unix_fd Entry::getEntry() |
| 77 | { |
Matt Spinler | 42517c2 | 2023-01-12 16:25:49 -0600 | [diff] [blame] | 78 | int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK); |
| 79 | if (fd == -1) |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 80 | { |
| 81 | auto e = errno; |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 82 | lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}", |
| 83 | "ERRNO", e, "PATH", path()); |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 84 | throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open(); |
| 85 | } |
| 86 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 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 |