rocm_smi_lib: Fix rocm-smi --showfan shows 'unable to detect fan'

Code changes related to the following:
  * Reverts earlier fix for the same issue
  * Check for existence of files before reading

Change-Id: I175b20c3343c414b12b79dc3fc404f53fbaabf3a
Signed-off-by: Oliveira, Daniel <daniel.oliveira@amd.com>
这个提交包含在:
Oliveira, Daniel
2023-08-28 20:08:13 -05:00
父节点 84e90e55d5
当前提交 328ce0150b
修改 3 个文件,包含 16 行新增11 行删除
+12 -3
查看文件
@@ -158,13 +158,15 @@ int isRegularFile(std::string fname, bool *is_reg) {
struct stat file_stat;
int ret;
assert(is_reg != nullptr);
ret = stat(fname.c_str(), &file_stat);
if (ret) {
return errno;
}
*is_reg = S_ISREG(file_stat.st_mode);
if (is_reg != nullptr) {
*is_reg = S_ISREG(file_stat.st_mode);
}
return 0;
}
@@ -192,6 +194,13 @@ int WriteSysfsStr(std::string path, std::string val) {
}
int ReadSysfsStr(std::string path, std::string *retStr) {
// On success, zero is returned. On error, -1 is returned, and
// errno is set to indicate the error.
auto is_regular_file_result = isRegularFile(path, nullptr);
if (is_regular_file_result != 0) {
return ENOENT;
}
std::stringstream ss;
int ret = 0;
std::ostringstream oss;