summaryrefslogtreecommitdiff
path: root/src/utils/cpp
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/utils/cpp
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/utils/cpp')
-rw-r--r--src/utils/cpp/file_locking.cpp12
1 files changed, 6 insertions, 6 deletions
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;
}