1 #include <fcntl.h> 2 #include <unistd.h> 3 #include <sys/ioctl.h> 4 #include <errno.h> 5 #include <phosphor-logging/log.hpp> 6 #include <phosphor-logging/elog.hpp> 7 #include <xyz/openbmc_project/Common/error.hpp> 8 #include <org/open_power/OCC/Device/error.hpp> 9 #include "occ_presence.hpp" 10 #include "occ_manager.hpp" 11 #include "elog-errors.hpp" 12 13 namespace open_power 14 { 15 namespace occ 16 { 17 18 // Reads the occs_present file and analyzes the data 19 void Presence::analyzeEvent() 20 { 21 using namespace phosphor::logging; 22 using namespace sdbusplus::org::open_power::OCC::Device::Error; 23 24 // Get the number of bytes to read 25 int len = -1; 26 auto r = ioctl(fd, FIONREAD, &len); 27 if (r < 0) 28 { 29 elog<ConfigFailure>( 30 phosphor::logging::org::open_power::OCC::Device:: 31 ConfigFailure::CALLOUT_ERRNO(errno), 32 phosphor::logging::org::open_power::OCC::Device:: 33 ConfigFailure::CALLOUT_DEVICE_PATH(file.c_str())); 34 } 35 36 auto data = readFile(len); 37 if (data.empty()) 38 { 39 return; 40 } 41 42 // Let stoi determine the base 43 auto occsPresent = std::stoi(data, nullptr, 0); 44 if (manager.getNumOCCs() != occsPresent) 45 { 46 log<level::INFO>("OCC presence mismatch", 47 entry("BMC_OCCS=%d", manager.getNumOCCs(), 48 entry("OCC_OCCS=%d", occsPresent))); 49 if (callBack) 50 { 51 callBack(); 52 } 53 } 54 } 55 56 } // namespace occ 57 } // namespace open_power 58