1 #include "elog_entry.hpp" 2 3 #include "elog_serialize.hpp" 4 #include "log_manager.hpp" 5 6 #include <fcntl.h> 7 #include <unistd.h> 8 9 #include <phosphor-logging/lg2.hpp> 10 #include <xyz/openbmc_project/Common/File/error.hpp> 11 12 namespace phosphor 13 { 14 namespace logging 15 { 16 17 // TODO Add interfaces to handle the error log id numbering 18 19 void Entry::delete_() 20 { 21 parent.erase(id()); 22 } 23 24 bool Entry::resolved(bool value) 25 { 26 auto current = 27 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(); 28 if (value != current) 29 { 30 value ? associations({}) : associations(assocs); 31 current = 32 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved( 33 value); 34 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 40 serialize(*this); 41 } 42 43 return current; 44 } 45 46 std::string Entry::eventId(std::string value) 47 { 48 auto current = 49 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId(); 50 if (value != current) 51 { 52 current = 53 sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId( 54 value); 55 serialize(*this); 56 } 57 58 return current; 59 } 60 61 std::string Entry::resolution(std::string value) 62 { 63 auto current = 64 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution(); 65 if (value != current) 66 { 67 current = 68 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution( 69 value); 70 serialize(*this); 71 } 72 73 return current; 74 } 75 76 sdbusplus::message::unix_fd Entry::getEntry() 77 { 78 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK); 79 if (fd == -1) 80 { 81 auto e = errno; 82 lg2::error("Failed to open Entry File ERRNO={ERRNO}, PATH={PATH}", 83 "ERRNO", e, "PATH", path()); 84 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open(); 85 } 86 87 // 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 97 void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) 98 { 99 close(fd); 100 fdCloseEventSource.reset(); 101 } 102 103 } // namespace logging 104 } // namespace phosphor 105