Attn: Fix CI complaint of unused-results
Use the results provided by file read/write operations. For mismatch in
number of bytes written on ffdc data creation we add a trace message,
for mismatch in number of bytes read during pel creation we skip
creating the pel.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I3ec6755ef258ac869775b08afafae324a76a2884
diff --git a/attn/attn_dbus.cpp b/attn/attn_dbus.cpp
index 72b637e..0903206 100644
--- a/attn/attn_dbus.cpp
+++ b/attn/attn_dbus.cpp
@@ -131,11 +131,21 @@
// Create FFDC file from buffer data
util::FFDCFile pelFile{util::FFDCFormat::Text};
auto fd = pelFile.getFileDescriptor();
- write(fd, i_buffer.data(), i_buffer.size());
- lseek(fd, 0, SEEK_SET);
auto filePath = pelFile.getPath(); // path to ffdc file
+ size_t numBytes = write(fd, i_buffer.data(), i_buffer.size());
+ if (i_buffer.size() != numBytes)
+ {
+ std::stringstream traceMsg;
+ traceMsg << filePath.c_str() << " only " << (int)numBytes << " of "
+ << (int)i_buffer.size() << " bytes written";
+ auto strobj = traceMsg.str();
+ trace<level::ERROR>(strobj.c_str());
+ }
+
+ lseek(fd, 0, SEEK_SET);
+
// Additional data for log
std::map<std::string, std::string> additional;
additional.emplace("RAWPEL", filePath.string());
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index c4ab877..f50aba5 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -15,6 +15,12 @@
phosphor::logging::log<phosphor::logging::level::INFO>(i_message);
}
+template <>
+void trace<ERROR>(const char* i_message)
+{
+ phosphor::logging::log<phosphor::logging::level::ERR>(i_message);
+}
+
/** @brief Tuple containing information about ffdc files */
using FFDCTuple =
std::tuple<util::FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>;
@@ -56,8 +62,17 @@
util::FFDCFile file{util::FFDCFormat::Custom};
// Write buffer to file and then reset file description file offset
- int fd = file.getFileDescriptor();
- write(fd, static_cast<char*>(i_buffer), i_size);
+ int fd = file.getFileDescriptor();
+ size_t numBytes = write(fd, static_cast<char*>(i_buffer), i_size);
+ if (i_size != numBytes)
+ {
+ std::stringstream traceMsg;
+ traceMsg << file.getPath().c_str() << " only " << (int)numBytes
+ << " of " << (int)i_size << " bytes written";
+ auto strobj = traceMsg.str();
+ trace<level::ERROR>(strobj.c_str());
+ }
+
lseek(fd, 0, SEEK_SET);
return file;
@@ -89,7 +104,15 @@
}
// write buffer to file
- write(fd, buffer.c_str(), buffer.size());
+ size_t numBytes = write(fd, buffer.c_str(), buffer.size());
+ if (buffer.size() != numBytes)
+ {
+ std::stringstream traceMsg;
+ traceMsg << file.getPath().c_str() << " only " << (int)numBytes
+ << " of " << (int)buffer.size() << " bytes written";
+ auto strobj = traceMsg.str();
+ trace<level::ERROR>(strobj.c_str());
+ }
}
// Seek to beginning of file so error logging system can read data
@@ -319,11 +342,22 @@
// read information PEL into buffer
std::vector<uint8_t> buffer(pelSize);
- read(pelFd, buffer.data(), buffer.size());
- close(pelFd);
+ size_t numBytes = read(pelFd, buffer.data(), buffer.size());
+ if (buffer.size() != numBytes)
+ {
+ std::stringstream traceMsg;
+ traceMsg << "Error reading event log: " << (int)numBytes
+ << " of " << (int)buffer.size() << " bytes read";
+ auto strobj = traceMsg.str();
+ trace<level::ERROR>(strobj.c_str());
+ }
+ else
+ {
+ // create PEL from buffer
+ createPelCustom(buffer, i_additional);
+ }
- // create PEL from buffer
- createPelCustom(buffer, i_additional);
+ close(pelFd);
}
}
}
diff --git a/attn/attn_logging.hpp b/attn/attn_logging.hpp
index 7e89555..4f1f785 100644
--- a/attn/attn_logging.hpp
+++ b/attn/attn_logging.hpp
@@ -17,7 +17,8 @@
/** @brief Logging level types */
enum level
{
- INFO
+ INFO,
+ ERROR
};
/** @brief Logging event types */