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" |
Arya K Padman | 916bb97 | 2024-09-26 01:39:26 -0500 | [diff] [blame] | 4 | #include "extensions.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 5 | #include "log_manager.hpp" |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 6 | |
Matt Spinler | 42517c2 | 2023-01-12 16:25:49 -0600 | [diff] [blame] | 7 | #include <fcntl.h> |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 8 | #include <unistd.h> |
| 9 | |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 10 | #include <phosphor-logging/lg2.hpp> |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/File/error.hpp> |
| 12 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 13 | namespace phosphor |
| 14 | { |
| 15 | namespace logging |
| 16 | { |
| 17 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 18 | // TODO Add interfaces to handle the error log id numbering |
| 19 | |
Deepak Kodihalli | 36db46c | 2017-03-31 06:28:44 -0500 | [diff] [blame] | 20 | void Entry::delete_() |
| 21 | { |
| 22 | parent.erase(id()); |
| 23 | } |
| 24 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 25 | bool Entry::resolved(bool value) |
| 26 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 28 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(); |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 29 | if (value != current) |
| 30 | { |
Arya K Padman | 916bb97 | 2024-09-26 01:39:26 -0500 | [diff] [blame] | 31 | // Resolve operation will be prohibited if delete operation is |
| 32 | // prohibited. |
| 33 | for (auto& func : Extensions::getDeleteProhibitedFunctions()) |
| 34 | { |
| 35 | try |
| 36 | { |
| 37 | bool prohibited = false; |
| 38 | func(id(), prohibited); |
| 39 | |
| 40 | if (prohibited) |
| 41 | { |
| 42 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 43 | Unavailable(); |
| 44 | } |
| 45 | } |
| 46 | catch (const sdbusplus::xyz::openbmc_project::Common::Error:: |
| 47 | Unavailable& e) |
| 48 | { |
| 49 | throw; |
| 50 | } |
| 51 | catch (const std::exception& e) |
| 52 | { |
| 53 | lg2::error("An extension's deleteProhibited function threw an " |
| 54 | "exception: {ERROR}", |
| 55 | "ERROR", e); |
| 56 | } |
| 57 | } |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 58 | value ? associations({}) : associations(assocs); |
| 59 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 60 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 61 | value); |
Matt Spinler | 1e71a4d | 2020-03-04 13:40:22 -0600 | [diff] [blame] | 62 | |
| 63 | uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 64 | std::chrono::system_clock::now().time_since_epoch()) |
| 65 | .count(); |
| 66 | updateTimestamp(ms); |
| 67 | |
Deepak Kodihalli | 9743189 | 2017-06-12 09:14:57 -0500 | [diff] [blame] | 68 | serialize(*this); |
| 69 | } |
| 70 | |
| 71 | return current; |
| 72 | } |
| 73 | |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 74 | std::string Entry::eventId(std::string value) |
| 75 | { |
| 76 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 77 | sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(); |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 78 | if (value != current) |
| 79 | { |
| 80 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 81 | sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId( |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 82 | value); |
| 83 | serialize(*this); |
| 84 | } |
| 85 | |
| 86 | return current; |
| 87 | } |
| 88 | |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 89 | std::string Entry::resolution(std::string value) |
| 90 | { |
| 91 | auto current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 92 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(); |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 93 | if (value != current) |
| 94 | { |
| 95 | current = |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 96 | sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution( |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 97 | value); |
| 98 | serialize(*this); |
| 99 | } |
| 100 | |
| 101 | return current; |
| 102 | } |
| 103 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 104 | sdbusplus::message::unix_fd Entry::getEntry() |
| 105 | { |
Matt Spinler | 42517c2 | 2023-01-12 16:25:49 -0600 | [diff] [blame] | 106 | int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK); |
| 107 | if (fd == -1) |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 108 | { |
| 109 | auto e = errno; |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 110 | lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}", |
| 111 | "ERRNO", e, "PATH", path()); |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 112 | throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open(); |
| 113 | } |
| 114 | |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 115 | // Schedule the fd to be closed by sdbusplus when it sends it back over |
| 116 | // D-Bus. |
| 117 | sdeventplus::Event event = sdeventplus::Event::get_default(); |
| 118 | fdCloseEventSource = std::make_unique<sdeventplus::source::Defer>( |
| 119 | event, std::bind(std::mem_fn(&Entry::closeFD), this, fd, |
| 120 | std::placeholders::_1)); |
| 121 | |
| 122 | return fd; |
| 123 | } |
| 124 | |
Patrick Williams | f40323d | 2021-04-16 15:35:17 -0500 | [diff] [blame] | 125 | void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) |
Adriana Kobylak | eb5d3f2 | 2021-02-04 14:03:28 -0600 | [diff] [blame] | 126 | { |
| 127 | close(fd); |
| 128 | fdCloseEventSource.reset(); |
| 129 | } |
| 130 | |
Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame] | 131 | } // namespace logging |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 132 | } // namespace phosphor |