linker: changes to init work arounds
Change three things regarding the work around to the fact that init is
special:
1) Only first stage init is special, so we change the check to include
accessing /proc/self/exe, which if is available, means that we're
not first stage init and do not need any work arounds.
2) Fix the fact that /init may be a symlink and may need readlink()
3) Suppress errors from realpath_fd() since these are expected to fail
due to /proc not being mounted.
Bug: 80395578
Test: sailfish boots without the audit generated from calling stat()
on /init and without the errors from realpath_fd()
Change-Id: I266f1486b142cb9a41ec791eba74122bdf38cf12
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 0470d7a..6d646a2 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -354,7 +354,9 @@
std::vector<char> buf(PATH_MAX), proc_self_fd(PATH_MAX);
async_safe_format_buffer(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd);
if (readlink(&proc_self_fd[0], &buf[0], buf.size()) == -1) {
- PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
+ if (!is_first_stage_init()) {
+ PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
+ }
return false;
}
@@ -993,8 +995,10 @@
if (realpath_fd(fd, realpath)) {
*realpath += separator;
} else {
- PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
- normalized_path.c_str());
+ if (!is_first_stage_init()) {
+ PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
+ normalized_path.c_str());
+ }
*realpath = normalized_path;
}
@@ -1024,7 +1028,10 @@
if (fd != -1) {
*file_offset = 0;
if (!realpath_fd(fd, realpath)) {
- PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.", path);
+ if (!is_first_stage_init()) {
+ PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
+ path);
+ }
*realpath = path;
}
}
@@ -1071,7 +1078,10 @@
if (fd != -1) {
*file_offset = 0;
if (!realpath_fd(fd, realpath)) {
- PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.", name);
+ if (!is_first_stage_init()) {
+ PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
+ name);
+ }
*realpath = name;
}
}
@@ -1354,8 +1364,12 @@
}
if (!realpath_fd(extinfo->library_fd, &realpath)) {
- PRINT("warning: unable to get realpath for the library \"%s\" by extinfo->library_fd. "
- "Will use given name.", name);
+ if (!is_first_stage_init()) {
+ PRINT(
+ "warning: unable to get realpath for the library \"%s\" by extinfo->library_fd. "
+ "Will use given name.",
+ name);
+ }
realpath = name;
}
@@ -1510,9 +1524,9 @@
static void soinfo_unload(soinfo* si);
static void shuffle(std::vector<LoadTask*>* v) {
- if (is_init()) {
- // arc4random* is not available in init because /dev/random hasn't yet been
- // created.
+ if (is_first_stage_init()) {
+ // arc4random* is not available in first stage init because /dev/random
+ // hasn't yet been created.
return;
}
for (size_t i = 0, size = v->size(); i < size; ++i) {