diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-08-29 21:12:01 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-09-02 20:23:44 +0530 |
commit | 2c1291325d9c6f5cd24c9a98b86154ade667328f (patch) | |
tree | adbf26a13d0d50bce4d51196de838260fc3f4b6b /occ_errors.cpp | |
parent | 18dc1281fe5af83c1dbb9c8895d7af824d2c1856 (diff) | |
download | openpower-occ-control-2c1291325d9c6f5cd24c9a98b86154ade667328f.tar.gz openpower-occ-control-2c1291325d9c6f5cd24c9a98b86154ade667328f.zip |
Seek to file offset 0 after reading error file
For a fd watching for data in sysfs file, a poll would return
immediately after read unless file is closed and re-opened OR
stream is seeked to 0. This commit chooses latter.
From stackoverflow:
Once poll/select indicates that the value has changed, you need to close and
re-open the file, or seek to 0 and read again.
Also, use EPOLLPRI | EPOLLERR than EPOLLIN as needed by sysfs_inotify
Change-Id: I243cdfd9a09c567eac5e52abd9980ebf90b94f89
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_errors.cpp')
-rw-r--r-- | occ_errors.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/occ_errors.cpp b/occ_errors.cpp index fe81f17..bc01c91 100644 --- a/occ_errors.cpp +++ b/occ_errors.cpp @@ -42,7 +42,7 @@ void Error::registerCallBack() { decltype(eventSource.get()) sourcePtr = nullptr; auto r = sd_event_add_io(event.get(), &sourcePtr, fd, - EPOLLIN, processEvents, this); + EPOLLPRI | EPOLLERR, processEvents, this); eventSource.reset(sourcePtr); if (r < 0) @@ -150,6 +150,19 @@ std::string Error::readFile(int len) const phosphor::logging::org::open_power::OCC::Device:: ReadFailure::CALLOUT_DEVICE_PATH(file.c_str())); } + + // Need to seek to START, else the poll returns immediately telling + // there is data to be read + r = lseek(fd, 0, SEEK_SET); + if (r < 0) + { + log<level::ERR>("Failure seeking error file to START"); + elog<ConfigFailure>( + phosphor::logging::org::open_power::OCC::Device:: + ConfigFailure::CALLOUT_ERRNO(errno), + phosphor::logging::org::open_power::OCC::Device:: + ConfigFailure::CALLOUT_DEVICE_PATH(file.c_str())); + } return std::string(data.get()); } |