From 5faae56bb7ec4a39d62e41bfec52b7c5b56fcab6 Mon Sep 17 00:00:00 2001 From: Bashar Abdelgafer Date: Tue, 25 Jun 2024 14:17:18 +0300 Subject: [PATCH] issue: 3958757 Change error message to warning when reading FS files Adjust XLIO behavior to generate warnings instead of error messages when it is unable to access FS files. This may occur in containerized environments. Since default values are provided, the severity of the issue is less critical. Change the default log severity in read_file_to_int() from VLOG_ERROR to VLOG_WARNING,and rephrase print message for better clarity. Signed-off-by: Bashar Abdelgafer --- src/core/util/utils.cpp | 11 ++++++----- src/core/util/utils.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/util/utils.cpp b/src/core/util/utils.cpp index 601113572..e16a5ed0d 100644 --- a/src/core/util/utils.cpp +++ b/src/core/util/utils.cpp @@ -547,27 +547,28 @@ int priv_read_file(const char *path, char *buf, size_t size, int fd = SYSCALL(open, path, O_RDONLY); BULLSEYE_EXCLUDE_BLOCK_START if (fd < 0) { - VLOG_PRINTF(log_level, "ERROR while opening file %s (errno %d %m)", path, errno); + VLOG_PRINTF(log_level, "Couldn't open file %s (errno %d %m)", path, errno); return -1; } BULLSEYE_EXCLUDE_BLOCK_END len = SYSCALL(read, fd, buf, size); BULLSEYE_EXCLUDE_BLOCK_START if (len < 0) { - VLOG_PRINTF(log_level, "ERROR while reading from file %s (errno %d %m)", path, errno); + VLOG_PRINTF(log_level, "Couldn't read file %s (errno %d %m)", path, errno); } BULLSEYE_EXCLUDE_BLOCK_END SYSCALL(close, fd); return len; } -int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level) +int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level /*VLOG_WARNING*/) { int value = -1; std::ifstream file_stream(path); if (!file_stream || !(file_stream >> value)) { - VLOG_PRINTF(log_level, "ERROR while getting int from from file %s, we'll use default %d", - path, default_value); + VLOG_PRINTF(log_level, + "Couldn't read an integer from file %s (errno %d %m), we'll use default %d", + path, errno, default_value); return default_value; } return value; diff --git a/src/core/util/utils.h b/src/core/util/utils.h index af11bbbe0..1b6649022 100644 --- a/src/core/util/utils.h +++ b/src/core/util/utils.h @@ -192,10 +192,10 @@ inline int priv_safe_try_read_file(const char *path, char *buf, size_t size) /** * Read content of file detailed in 'path' (usually a sysfs file) - * upon failure print error + * upon failure print warning * @return int value (atoi) of the file content, or 'default_value' upon failure */ -int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level = VLOG_ERROR); +int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level = VLOG_WARNING); /** * Get port number from interface name