blob: 85751ed0a39dd96415678d68483feb2597788c28 [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
9#include <xyz/openbmc_project/Common/File/error.hpp>
10
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060011namespace phosphor
12{
13namespace logging
14{
15
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060016// TODO Add interfaces to handle the error log id numbering
17
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050018void Entry::delete_()
19{
20 parent.erase(id());
21}
22
Deepak Kodihalli97431892017-06-12 09:14:57 -050023bool Entry::resolved(bool value)
24{
Patrick Venturef18bf832018-10-26 18:14:00 -070025 auto current =
26 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved();
Deepak Kodihalli97431892017-06-12 09:14:57 -050027 if (value != current)
28 {
Patrick Venturef18bf832018-10-26 18:14:00 -070029 value ? associations({}) : associations(assocs);
30 current =
31 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
32 value);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060033
34 uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
35 std::chrono::system_clock::now().time_since_epoch())
36 .count();
37 updateTimestamp(ms);
38
Deepak Kodihalli97431892017-06-12 09:14:57 -050039 serialize(*this);
40 }
41
42 return current;
43}
44
Vijay Lobod354a392021-06-01 16:21:02 -050045std::string Entry::eventId(std::string value)
46{
47 auto current =
48 sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId();
49 if (value != current)
50 {
51 current =
52 sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId(
53 value);
54 serialize(*this);
55 }
56
57 return current;
58}
59
Vijay Lobo593a4c62021-06-16 14:25:26 -050060std::string Entry::resolution(std::string value)
61{
62 auto current =
63 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolution();
64 if (value != current)
65 {
66 current =
67 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolution(
68 value);
69 serialize(*this);
70 }
71
72 return current;
73}
74
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060075sdbusplus::message::unix_fd Entry::getEntry()
76{
Matt Spinler42517c22023-01-12 16:25:49 -060077 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK);
78 if (fd == -1)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060079 {
80 auto e = errno;
81 log<level::ERR>("Failed to open Entry File", entry("ERRNO=%d", e),
82 entry("PATH=%s", path().c_str()));
83 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
84 }
85
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060086 // Schedule the fd to be closed by sdbusplus when it sends it back over
87 // D-Bus.
88 sdeventplus::Event event = sdeventplus::Event::get_default();
89 fdCloseEventSource = std::make_unique<sdeventplus::source::Defer>(
90 event, std::bind(std::mem_fn(&Entry::closeFD), this, fd,
91 std::placeholders::_1));
92
93 return fd;
94}
95
Patrick Williamsf40323d2021-04-16 15:35:17 -050096void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060097{
98 close(fd);
99 fdCloseEventSource.reset();
100}
101
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600102} // namespace logging
Patrick Venturef18bf832018-10-26 18:14:00 -0700103} // namespace phosphor