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 <xyz/openbmc_project/Common/File/error.hpp> 10 11 namespace phosphor 12 { 13 namespace logging 14 { 15 16 // TODO Add interfaces to handle the error log id numbering 17 18 void Entry::delete_() 19 { 20 parent.erase(id()); 21 } 22 23 bool Entry::resolved(bool value) 24 { 25 auto current = 26 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(); 27 if (value != current) 28 { 29 value ? associations({}) : associations(assocs); 30 current = 31 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved( 32 value); 33 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 39 serialize(*this); 40 } 41 42 return current; 43 } 44 45 std::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 60 std::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 75 sdbusplus::message::unix_fd Entry::getEntry() 76 { 77 int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK); 78 if (fd == -1) 79 { 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 86 // 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 96 void Entry::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) 97 { 98 close(fd); 99 fdCloseEventSource.reset(); 100 } 101 102 } // namespace logging 103 } // namespace phosphor 104