blob: 183ecbb6ee129674e86c33e727b085926235be26 [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"
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06006
Matt Spinler42517c22023-01-12 16:25:49 -06007#include <fcntl.h>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -06008#include <unistd.h>
9
Arya K Padman5bc26532024-04-10 06:19:25 -050010#include <phosphor-logging/lg2.hpp>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060011#include <xyz/openbmc_project/Common/File/error.hpp>
12
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060013namespace phosphor
14{
15namespace logging
16{
17
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060018// TODO Add interfaces to handle the error log id numbering
19
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050020void Entry::delete_()
21{
22 parent.erase(id());
23}
24
Deepak Kodihalli97431892017-06-12 09:14:57 -050025bool Entry::resolved(bool value)
26{
Patrick Venturef18bf832018-10-26 18:14:00 -070027 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070028 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved();
Deepak Kodihalli97431892017-06-12 09:14:57 -050029 if (value != current)
30 {
Arya K Padman916bb972024-09-26 01:39:26 -050031 // 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 Venturef18bf832018-10-26 18:14:00 -070058 value ? associations({}) : associations(assocs);
59 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070060 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(
Patrick Venturef18bf832018-10-26 18:14:00 -070061 value);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060062
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 Kodihalli97431892017-06-12 09:14:57 -050068 serialize(*this);
69 }
70
71 return current;
72}
73
Vijay Lobod354a392021-06-01 16:21:02 -050074std::string Entry::eventId(std::string value)
75{
76 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070077 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId();
Vijay Lobod354a392021-06-01 16:21:02 -050078 if (value != current)
79 {
80 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070081 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(
Vijay Lobod354a392021-06-01 16:21:02 -050082 value);
83 serialize(*this);
84 }
85
86 return current;
87}
88
Vijay Lobo593a4c62021-06-16 14:25:26 -050089std::string Entry::resolution(std::string value)
90{
91 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070092 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution();
Vijay Lobo593a4c62021-06-16 14:25:26 -050093 if (value != current)
94 {
95 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070096 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(
Vijay Lobo593a4c62021-06-16 14:25:26 -050097 value);
98 serialize(*this);
99 }
100
101 return current;
102}
103
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600104sdbusplus::message::unix_fd Entry::getEntry()
105{
Matt Spinler42517c22023-01-12 16:25:49 -0600106 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK);
107 if (fd == -1)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600108 {
109 auto e = errno;
Arya K Padman5bc26532024-04-10 06:19:25 -0500110 lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}",
111 "ERRNO", e, "PATH", path());
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600112 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
113 }
114
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600115 // 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 Williamsf40323d2021-04-16 15:35:17 -0500125void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600126{
127 close(fd);
128 fdCloseEventSource.reset();
129}
130
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600131} // namespace logging
Patrick Venturef18bf832018-10-26 18:14:00 -0700132} // namespace phosphor