blob: 8f86ccaee41de456aabb08e963485d5745e9f728 [file] [log] [blame]
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06001#include "elog_entry.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Deepak Kodihalli97431892017-06-12 09:14:57 -05003#include "elog_serialize.hpp"
Arya K Padman916bb972024-09-26 01:39:26 -05004#include "extensions.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07005#include "log_manager.hpp"
Patrick Williamsfa2d9622024-09-30 16:25:43 -04006#include "paths.hpp"
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06007
Matt Spinler42517c22023-01-12 16:25:49 -06008#include <fcntl.h>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -06009#include <unistd.h>
10
Arya K Padman5bc26532024-04-10 06:19:25 -050011#include <phosphor-logging/lg2.hpp>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060012#include <xyz/openbmc_project/Common/File/error.hpp>
13
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060014namespace phosphor
15{
16namespace logging
17{
18
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060019// TODO Add interfaces to handle the error log id numbering
20
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050021void Entry::delete_()
22{
23 parent.erase(id());
24}
25
Deepak Kodihalli97431892017-06-12 09:14:57 -050026bool Entry::resolved(bool value)
27{
Patrick Venturef18bf832018-10-26 18:14:00 -070028 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070029 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved();
Deepak Kodihalli97431892017-06-12 09:14:57 -050030 if (value != current)
31 {
Arya K Padman916bb972024-09-26 01:39:26 -050032 // 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 Venturef18bf832018-10-26 18:14:00 -070059 value ? associations({}) : associations(assocs);
60 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070061 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(
Patrick Venturef18bf832018-10-26 18:14:00 -070062 value);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060063
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 Kodihalli97431892017-06-12 09:14:57 -050069 serialize(*this);
70 }
71
72 return current;
73}
74
Vijay Lobod354a392021-06-01 16:21:02 -050075std::string Entry::eventId(std::string value)
76{
77 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070078 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId();
Vijay Lobod354a392021-06-01 16:21:02 -050079 if (value != current)
80 {
81 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070082 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(
Vijay Lobod354a392021-06-01 16:21:02 -050083 value);
84 serialize(*this);
85 }
86
87 return current;
88}
89
Vijay Lobo593a4c62021-06-16 14:25:26 -050090std::string Entry::resolution(std::string value)
91{
92 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070093 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution();
Vijay Lobo593a4c62021-06-16 14:25:26 -050094 if (value != current)
95 {
96 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070097 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(
Vijay Lobo593a4c62021-06-16 14:25:26 -050098 value);
99 serialize(*this);
100 }
101
102 return current;
103}
104
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600105sdbusplus::message::unix_fd Entry::getEntry()
106{
Matt Spinler42517c22023-01-12 16:25:49 -0600107 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK);
108 if (fd == -1)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600109 {
110 auto e = errno;
Arya K Padman5bc26532024-04-10 06:19:25 -0500111 lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}",
112 "ERRNO", e, "PATH", path());
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600113 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
114 }
115
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600116 // 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 Williamsf40323d2021-04-16 15:35:17 -0500126void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600127{
128 close(fd);
129 fdCloseEventSource.reset();
130}
131
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600132} // namespace logging
Patrick Venturef18bf832018-10-26 18:14:00 -0700133} // namespace phosphor