oem-ibm: Improving logs (lg2)
This commit corrects the severity level of logs and also formats the
message string, fixing the ill-defined message string of the logs as
mentioned in the anti-pattern document [1]. Additionally, based on the
requirement this commit adds more debug information to logs.
[1]: https://github.com/openbmc/docs/blob/master/anti-patterns.md#ill-defined-data-structuring-in-lg2-message-strings
Change-Id: I24ca21de35d5a1a9b3cc64b28a149e4c213055f9
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/oem/ibm/libpldmresponder/utils.cpp b/oem/ibm/libpldmresponder/utils.cpp
index 05978b4..a29a0d4 100644
--- a/oem/ibm/libpldmresponder/utils.cpp
+++ b/oem/ibm/libpldmresponder/utils.cpp
@@ -27,10 +27,12 @@
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- if (strnlen(socketInterface.c_str(), sizeof(addr.sun_path)) ==
- sizeof(addr.sun_path))
+ size_t interfaceLength = strnlen(socketInterface.c_str(),
+ sizeof(addr.sun_path));
+ if (interfaceLength == sizeof(addr.sun_path))
{
- error("setupUnixSocket: UNIX socket path too long");
+ error("Setup unix socket path '{PATH}' is too long '{LENGTH}'", "PATH",
+ socketInterface, "LENGTH", interfaceLength);
return -1;
}
@@ -38,21 +40,21 @@
if ((sock = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1)
{
- error("setupUnixSocket: socket() call failed");
+ error("Failed to open unix socket");
return -1;
}
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1)
{
- error("setupUnixSocket: bind() call failed with errno {ERR}", "ERR",
- errno);
+ error("Failed to bind unix socket, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
close(sock);
return -1;
}
if (listen(sock, 1) == -1)
{
- error("setupUnixSocket: listen() call failed");
+ error("Failed listen() call while setting up unix socket");
close(sock);
return -1;
}
@@ -70,7 +72,9 @@
int retval = select(nfd, &rfd, NULL, NULL, &tv);
if (retval < 0)
{
- error("setupUnixSocket: select call failed {ERR}", "ERR", errno);
+ error(
+ "Failed select() call while setting up unix socket, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
close(sock);
return -1;
}
@@ -80,7 +84,9 @@
fd = accept(sock, NULL, NULL);
if (fd < 0)
{
- error("setupUnixSocket: accept() call failed {ERR}", "ERR", errno);
+ error(
+ "Failed accept() call while setting up unix socket, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
close(sock);
return -1;
}
@@ -108,7 +114,9 @@
int retval = select(nfd, NULL, &wfd, NULL, &tv);
if (retval < 0)
{
- error("writeToUnixSocket: select call failed {ERR}", "ERR", errno);
+ error(
+ "Failed to write to unix socket select, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
close(sock);
return -1;
}
@@ -125,11 +133,14 @@
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
{
error(
- "writeToUnixSocket: Write call failed with EAGAIN or EWOULDBLOCK or EINTR");
+ "Failed to write to unix socket, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
nwrite = 0;
continue;
}
- error("writeToUnixSocket: Failed to write {ERR}", "ERR", errno);
+ error(
+ "Failed to write to unix socket, error number - {ERROR_NUM}",
+ "ERROR_NUM", errno);
close(sock);
return -1;
}