summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-05 11:26:57 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-05 11:36:59 +0200
commitb902f9b4d48328e00d92188f432568b3b3c07391 (patch)
tree902d8fd0b91853d87ac2d2cadd7d14595a37fabf /src
parentda2ebe2b5cfef7b0f2e49160aa22ef5020fa964b (diff)
downloadjustbuild-b902f9b4d48328e00d92188f432568b3b3c07391.tar.gz
When using errno, log the actual error message
For the user it is more useful to see the actual error message, provided by strerror(), than the pure error code.
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/launch.cpp5
-rw-r--r--src/utils/cpp/file_locking.cpp12
2 files changed, 9 insertions, 8 deletions
diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp
index d83ef8e5..ccebd966 100644
--- a/src/other_tools/just_mr/launch.cpp
+++ b/src/other_tools/just_mr/launch.cpp
@@ -14,7 +14,8 @@
#include "src/other_tools/just_mr/launch.hpp"
-#include <cerrno> // for errno
+#include <cerrno> // for errno
+#include <cstring> // for strerror()
#include <filesystem>
#include <utility>
@@ -256,6 +257,6 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file,
[[maybe_unused]] auto res =
execvp(argv[0], static_cast<char* const*>(argv.data()));
// execvp returns only if command errored out
- Logger::Log(LogLevel::Error, "execvp failed with error code {}", errno);
+ Logger::Log(LogLevel::Error, "execvp failed with:\n{}", strerror(errno));
return kExitExecError;
}
diff --git a/src/utils/cpp/file_locking.cpp b/src/utils/cpp/file_locking.cpp
index d7f0c49a..53cba2bf 100644
--- a/src/utils/cpp/file_locking.cpp
+++ b/src/utils/cpp/file_locking.cpp
@@ -14,7 +14,8 @@
#include "src/utils/cpp/file_locking.hpp"
-#include <cerrno> // for errno
+#include <cerrno> // for errno
+#include <cstring> // for strerror()
#ifdef __unix__
#include <sys/file.h>
@@ -56,11 +57,10 @@ auto LockFile::Acquire(std::filesystem::path const& fspath,
// attach flock
auto err = flock(fileno(file_handle), is_shared ? LOCK_SH : LOCK_EX);
if (err != 0) {
- Logger::Log(
- LogLevel::Error,
- "LockFile: applying lock to file {} failed with errno {}",
- lock_file->string(),
- errno);
+ Logger::Log(LogLevel::Error,
+ "LockFile: applying lock to file {} failed with:\n{}",
+ lock_file->string(),
+ strerror(errno));
fclose(file_handle);
return std::nullopt;
}