diff options
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 7edfd54ea..aa12b6ef1 100644 --- a/linker/linker_main.cpp +++ b/linker/linker_main.cpp @@ -194,11 +194,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 |