blob: f0b3e4575a737534b6f21e68c5012ab7c934cc68 [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
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -06006#include <unistd.h>
7
8#include <xyz/openbmc_project/Common/File/error.hpp>
9
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060010namespace phosphor
11{
12namespace logging
13{
14
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060015// TODO Add interfaces to handle the error log id numbering
16
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050017void Entry::delete_()
18{
19 parent.erase(id());
20}
21
Deepak Kodihalli97431892017-06-12 09:14:57 -050022bool Entry::resolved(bool value)
23{
Patrick Venturef18bf832018-10-26 18:14:00 -070024 auto current =
25 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved();
Deepak Kodihalli97431892017-06-12 09:14:57 -050026 if (value != current)
27 {
Patrick Venturef18bf832018-10-26 18:14:00 -070028 value ? associations({}) : associations(assocs);
29 current =
30 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
31 value);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060032
33 uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
34 std::chrono::system_clock::now().time_since_epoch())
35 .count();
36 updateTimestamp(ms);
37
Deepak Kodihalli97431892017-06-12 09:14:57 -050038 serialize(*this);
39 }
40
41 return current;
42}
43
Vijay Lobod354a392021-06-01 16:21:02 -050044std::string Entry::eventId(std::string value)
45{
46 auto current =
47 sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId();
48 if (value != current)
49 {
50 current =
51 sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId(
52 value);
53 serialize(*this);
54 }
55
56 return current;
57}
58
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060059sdbusplus::message::unix_fd Entry::getEntry()
60{
61 FILE* fp = fopen(path().c_str(), "rb");
62 if (fp == nullptr)
63 {
64 auto e = errno;
65 log<level::ERR>("Failed to open Entry File", entry("ERRNO=%d", e),
66 entry("PATH=%s", path().c_str()));
67 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
68 }
69
70 auto fd = fileno(fp);
71
72 // Schedule the fd to be closed by sdbusplus when it sends it back over
73 // D-Bus.
74 sdeventplus::Event event = sdeventplus::Event::get_default();
75 fdCloseEventSource = std::make_unique<sdeventplus::source::Defer>(
76 event, std::bind(std::mem_fn(&Entry::closeFD), this, fd,
77 std::placeholders::_1));
78
79 return fd;
80}
81
Patrick Williamsf40323d2021-04-16 15:35:17 -050082void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/)
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060083{
84 close(fd);
85 fdCloseEventSource.reset();
86}
87
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060088} // namespace logging
Patrick Venturef18bf832018-10-26 18:14:00 -070089} // namespace phosphor