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