summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2017-12-14 10:22:22 -0600
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-01-17 01:11:14 +0000
commitc8a8e0102e1bb9dd1e231f809e6327513eea3559 (patch)
treef45286f2a2fbb828ce105c618b6a39af755240bb
parent26d21731c292a02ec71480fade9a06658160eafb (diff)
downloadphosphor-hwmon-c8a8e0102e1bb9dd1e231f809e6327513eea3559.tar.gz
phosphor-hwmon-c8a8e0102e1bb9dd1e231f809e6327513eea3559.zip
Clear errno before reading/writing
Ensure the errno is cleared before accessing the sysfs file, so exceptions thrown without setting an errno can be recognized as such. Without this, the errno could still be set to a nonzero value from a previous operation, and the error handling code would think it happened on the current operation. The difference being if there is a nonzero errno a Read/WriteFailure error will be logged, and if zero the exception will be rethrown. Change-Id: Ia958376ca80484d4d594872ab8ab0154d1b767ca Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r--sysfs.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/sysfs.cpp b/sysfs.cpp
index b0c5a6d..af5f86a 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -267,6 +267,7 @@ int64_t HwmonIO::read(
{
try
{
+ errno = 0;
if (!ifs.is_open())
ifs.open(fullPath);
ifs.clear();
@@ -343,6 +344,7 @@ void HwmonIO::write(
{
try
{
+ errno = 0;
if (!ofs.is_open())
ofs.open(fullPath);
ofs.clear();
OpenPOWER on IntegriCloud