-
Notifications
You must be signed in to change notification settings - Fork 69
[refactor][utils] Replace thread-unsafe strerror() with C++ standard error message API #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -596,7 +596,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) // NOLINT | |||||
| auto bundleArg = "--bundle=" + containerBundle.string(); | ||||||
| auto pid = fork(); | ||||||
| if (pid < 0) { | ||||||
| std::cerr << "fork() err: " << ::strerror(errno) << std::endl; | ||||||
| std::cerr << "fork() err: " << std::generic_category().message(errno) << std::endl; | ||||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -613,7 +613,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) // NOLINT | |||||
|
|
||||||
| int wstatus{ 0 }; | ||||||
| if (auto ret = ::waitpid(pid, &wstatus, 0); ret == -1) { | ||||||
| std::cerr << "waitpid() err:" << ::strerror(errno) << std::endl; | ||||||
| std::cerr << "waitpid() err:" << std::generic_category().message(errno) << std::endl; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For system call errors (such as those from
Suggested change
|
||||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1443,8 +1443,9 @@ utils::error::Result<void> ContainerCfgBuilder::buildMountNetworkConf() noexcept | |
| std::array<char, PATH_MAX + 1> buf{}; | ||
| auto *rpath = realpath(resolvConf.string().c_str(), buf.data()); | ||
| if (rpath == nullptr) { | ||
| return LINGLONG_ERR( | ||
| fmt::format("Failed to read symlink {}: {}", resolvConf, strerror(errno))); | ||
| return LINGLONG_ERR(fmt::format("Failed to read symlink {}: {}", | ||
| resolvConf, | ||
| std::generic_category().message(errno))); | ||
|
Comment on lines
+1446
to
+1448
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For system call errors (such as those from return LINGLONG_ERR(fmt::format("Failed to read symlink {}: {}",
resolvConf,
std::system_category().message(errno))); |
||
| } | ||
| target = std::filesystem::path{ rpath }; | ||
| } | ||
|
|
@@ -2319,8 +2320,9 @@ ContainerCfgBuilder::mountBind(const ocppi::runtime::config::types::Mount &mount | |
| } | ||
|
|
||
| if (::mount(mount.source->c_str(), mount.destination.c_str(), "", flags, nullptr) != 0) { | ||
| return LINGLONG_ERR( | ||
| fmt::format("failed to mount {}: {}", mount.source.value(), strerror(errno))); | ||
| return LINGLONG_ERR(fmt::format("failed to mount {}: {}", | ||
| mount.source.value(), | ||
| std::generic_category().message(errno))); | ||
|
Comment on lines
+2323
to
+2325
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For system call errors (such as those from return LINGLONG_ERR(fmt::format("failed to mount {}: {}",
mount.source.value(),
std::system_category().message(errno))); |
||
| } | ||
|
|
||
| return LINGLONG_OK; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For system call errors (such as those from
fork()),std::system_category()is conceptually more appropriate thanstd::generic_category().std::system_category()is specifically designed for errors reported by the operating system, whereasstd::generic_category()is for portable, generic error codes (equivalent tostd::errc). Usingstd::system_category()ensures that any system-specific error codes are correctly mapped to their corresponding error messages.