diff options
author | Tom Cherry <tomcherry@google.com> | 2018-11-08 13:40:52 -0800 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2018-11-08 21:50:19 +0000 |
commit | 66bc428f93546065ca73779ebefd1082244ecea2 (patch) | |
tree | 09c8940fa17df80cdd9d21cf9e4a8b463ffbaa3f /linker/linker_main.cpp | |
parent | e2833f27c17e87021dae45c0d45025afd51f1e7e (diff) |
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
Diffstat (limited to 'linker/linker_main.cpp')
-rw-r--r-- | linker/linker_main.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp index f7c496a25..d88fc7544 100644 --- a/linker/linker_main.cpp +++ b/linker/linker_main.cpp @@ -195,11 +195,19 @@ struct ExecutableInfo { static ExecutableInfo get_executable_info(KernelArgumentBlock& args) { ExecutableInfo result = {}; - if (is_init()) { - // /proc fs is not mounted when init starts. Therefore we can't use - // /proc/self/exe for init. + if (is_first_stage_init()) { + // /proc fs is not mounted when first stage init starts. Therefore we can't + // use /proc/self/exe for init. stat("/init", &result.file_stat); - result.path = "/init"; + + // /init may be a symlink, so try to read it as such. + char path[PATH_MAX]; + ssize_t path_len = readlink("/init", path, sizeof(path)); + if (path_len == -1 || path_len >= static_cast<ssize_t>(sizeof(path))) { + result.path = "/init"; + } else { + result.path = std::string(path, path_len); + } } else { // Stat "/proc/self/exe" instead of executable_path because // the executable could be unlinked by this point and it should |