Move scopeguard into android::base
Test: boot bullhead, bionic unit tests
Change-Id: I223249684867655ecb53713b10da41d3014f96ae
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 2777d73..d31c652 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -43,8 +43,9 @@
#include <unordered_map>
#include <vector>
+#include <android-base/scopeguard.h>
+
// Private C library headers.
-#include "private/ScopeGuard.h"
#include "linker.h"
#include "linker_block_allocator.h"
@@ -1536,13 +1537,13 @@
// list of libraries to link - see step 2.
size_t soinfos_count = 0;
- auto scope_guard = make_scope_guard([&]() {
+ auto scope_guard = android::base::make_scope_guard([&]() {
for (LoadTask* t : load_tasks) {
LoadTask::deleter(t);
}
});
- auto failure_guard = make_scope_guard([&]() {
+ auto failure_guard = android::base::make_scope_guard([&]() {
// Housekeeping
soinfo_unload(soinfos, soinfos_count);
});
@@ -1661,7 +1662,7 @@
}
});
- failure_guard.disable();
+ failure_guard.Disable();
}
return linked;
@@ -1904,9 +1905,8 @@
ns == nullptr ? "(null)" : ns->get_name(),
ns);
- auto failure_guard = make_scope_guard([&]() {
- LD_LOG(kLogDlopen, "... dlopen failed: %s", linker_get_error_buffer());
- });
+ auto failure_guard = android::base::make_scope_guard(
+ [&]() { LD_LOG(kLogDlopen, "... dlopen failed: %s", linker_get_error_buffer()); });
if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL|RTLD_NODELETE|RTLD_NOLOAD)) != 0) {
DL_ERR("invalid flags to dlopen: %x", flags);
@@ -1966,7 +1966,7 @@
"... dlopen calling constructors: realpath=\"%s\", soname=\"%s\", handle=%p",
si->get_realpath(), si->get_soname(), handle);
si->call_constructors();
- failure_guard.disable();
+ failure_guard.Disable();
LD_LOG(kLogDlopen,
"... dlopen successful: realpath=\"%s\", soname=\"%s\", handle=%p",
si->get_realpath(), si->get_soname(), handle);
@@ -2044,9 +2044,8 @@
ns == nullptr ? "(null)" : ns->get_name(),
ns);
- auto failure_guard = make_scope_guard([&]() {
- LD_LOG(kLogDlsym, "... dlsym failed: %s", linker_get_error_buffer());
- });
+ auto failure_guard = android::base::make_scope_guard(
+ [&]() { LD_LOG(kLogDlsym, "... dlsym failed: %s", linker_get_error_buffer()); });
if (sym_name == nullptr) {
DL_ERR("dlsym failed: symbol name is null");
@@ -2077,7 +2076,7 @@
if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
*symbol = reinterpret_cast<void*>(found->resolve_symbol_address(sym));
- failure_guard.disable();
+ failure_guard.Disable();
LD_LOG(kLogDlsym,
"... dlsym successful: sym_name=\"%s\", sym_ver=\"%s\", found in=\"%s\", address=%p",
sym_name, sym_ver, found->get_soname(), *symbol);
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index 33616f7..a12cfbe 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -33,10 +33,9 @@
#include "linker_utils.h"
#include <android-base/file.h>
+#include <android-base/scopeguard.h>
#include <android-base/strings.h>
-#include <private/ScopeGuard.h>
-
#include <stdlib.h>
#include <string>
@@ -379,9 +378,7 @@
Properties properties(std::move(property_map));
- auto failure_guard = make_scope_guard([] {
- g_config.clear();
- });
+ auto failure_guard = android::base::make_scope_guard([] { g_config.clear(); });
std::unordered_map<std::string, NamespaceConfig*> namespace_configs;
@@ -469,7 +466,7 @@
ns_config->set_permitted_paths(properties.get_paths(property_name_prefix + ".permitted.paths"));
}
- failure_guard.disable();
+ failure_guard.Disable();
*config = &g_config;
return true;
}
diff --git a/linker/tests/linker_config_test.cpp b/linker/tests/linker_config_test.cpp
index 64ab00f..418cbda 100644
--- a/linker/tests/linker_config_test.cpp
+++ b/linker/tests/linker_config_test.cpp
@@ -36,12 +36,11 @@
#include <unistd.h>
+#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
#include <android-base/file.h>
#include <android-base/test_utils.h>
-#include "private/ScopeGuard.h"
-
static const char* config_str =
"# comment \n"
@@ -116,9 +115,8 @@
std::string executable_path = std::string(tmp_dir.path) + "/some-binary";
std::string version_file = std::string(tmp_dir.path) + "/.version";
- auto file_guard = make_scope_guard([&version_file] {
- unlink(version_file.c_str());
- });
+ auto file_guard =
+ android::base::make_scope_guard([&version_file] { unlink(version_file.c_str()); });
ASSERT_TRUE(write_version(version_file, 113U)) << strerror(errno);