diff options
author | Tom Cherry <tomcherry@google.com> | 2018-11-29 16:50:37 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-11-29 16:50:37 +0000 |
commit | c7cbef4f2dca7de4fb6186df05e0208d7d7fbfa5 (patch) | |
tree | 2e007e9e9dbc3ae5d85059bb51c9b15acf408c91 /linker/linker_main.cpp | |
parent | 7260329093c3a36536e0bebf4ed5b929430f4efb (diff) | |
parent | 66bc428f93546065ca73779ebefd1082244ecea2 (diff) |
Merge "linker: changes to init work arounds"
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 66766fe56..82b10b74b 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 |