blob: b4009a5d2c3f2084c989837888cf3fc9b6b263bd [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"
Patrick Venturef18bf832018-10-26 18:14:00 -07004#include "log_manager.hpp"
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06005
Matt Spinler42517c22023-01-12 16:25:49 -06006#include <fcntl.h>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -06007#include <unistd.h>
8
Arya K Padman5bc26532024-04-10 06:19:25 -05009#include <phosphor-logging/lg2.hpp>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060010#include <xyz/openbmc_project/Common/File/error.hpp>
11
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060012namespace phosphor
13{
14namespace logging
15{
16
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060017// TODO Add interfaces to handle the error log id numbering
18
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050019void Entry::delete_()
20{
21 parent.erase(id());
22}
23
Deepak Kodihalli97431892017-06-12 09:14:57 -050024bool Entry::resolved(bool value)
25{
Patrick Venturef18bf832018-10-26 18:14:00 -070026 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070027 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved();
Deepak Kodihalli97431892017-06-12 09:14:57 -050028 if (value != current)
29 {
Patrick Venturef18bf832018-10-26 18:14:00 -070030 value ? associations({}) : associations(assocs);
31 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070032 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(
Patrick Venturef18bf832018-10-26 18:14:00 -070033 value);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060034
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 Kodihalli97431892017-06-12 09:14:57 -050040 serialize(*this);
41 }
42
43 return current;
44}
45
Vijay Lobod354a392021-06-01 16:21:02 -050046std::string Entry::eventId(std::string value)
47{
48 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070049 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId();
Vijay Lobod354a392021-06-01 16:21:02 -050050 if (value != current)
51 {
52 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070053 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(
Vijay Lobod354a392021-06-01 16:21:02 -050054 value);
55 serialize(*this);
56 }
57
58 return current;
59}
60
Vijay Lobo593a4c62021-06-16 14:25:26 -050061std::string Entry::resolution(std::string value)
62{
63 auto current =
Willy Tu6ddbf692023-09-05 10:54:16 -070064 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution();
Vijay Lobo593a4c62021-06-16 14:25:26 -050065 if (value != current)
66 {
67 current =
Willy Tu6ddbf692023-09-05 10:54:16 -070068 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(
Vijay Lobo593a4c62021-06-16 14:25:26 -050069 value);
70 serialize(*this);
71 }
72
73 return current;
74}
75
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060076sdbusplus::message::unix_fd Entry::getEntry()
77{
Matt Spinler42517c22023-01-12 16:25:49 -060078 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK);
79 if (fd == -1)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060080 {
81 auto e = errno;
Arya K Padman5bc26532024-04-10 06:19:25 -050082 lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}",
83 "ERRNO", e, "PATH", path());
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060084 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
85 }
86
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060087 // 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 Williamsf40323d2021-04-16 15:35:17 -050097void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060098{
99 close(fd);
100 fdCloseEventSource.reset();
101}
102
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600103} // namespace logging
Patrick Venturef18bf832018-10-26 18:14:00 -0700104} // namespace phosphor