1 #include "elog_entry.hpp" 2 3 #include "elog_serialize.hpp" 4 #include "log_manager.hpp" 5 6 #include <unistd.h> 7 8 #include <xyz/openbmc_project/Common/File/error.hpp> 9 10 namespace phosphor 11 { 12 namespace logging 13 { 14 15 // TODO Add interfaces to handle the error log id numbering 16 17 void Entry::delete_() 18 { 19 parent.erase(id()); 20 } 21 22 bool Entry::resolved(bool value) 23 { 24 auto current = 25 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(); 26 if (value != current) 27 { 28 value ? associations({}) : associations(assocs); 29 current = 30 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved( 31 value); 32 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 38 serialize(*this); 39 } 40 41 return current; 42 } 43 44 sdbusplus::message::unix_fd Entry::getEntry() 45 { 46 FILE* fp = fopen(path().c_str(), "rb"); 47 if (fp == nullptr) 48 { 49 auto e = errno; 50 log<level::ERR>("Failed to open Entry File", entry("ERRNO=%d", e), 51 entry("PATH=%s", path().c_str())); 52 throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open(); 53 } 54 55 auto fd = fileno(fp); 56 57 // Schedule the fd to be closed by sdbusplus when it sends it back over 58 // D-Bus. 59 sdeventplus::Event event = sdeventplus::Event::get_default(); 60 fdCloseEventSource = std::make_unique<sdeventplus::source::Defer>( 61 event, std::bind(std::mem_fn(&Entry::closeFD), this, fd, 62 std::placeholders::_1)); 63 64 return fd; 65 } 66 67 void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) 68 { 69 close(fd); 70 fdCloseEventSource.reset(); 71 } 72 73 } // namespace logging 74 } // namespace phosphor 75