summaryrefslogtreecommitdiff
path: root/linker/linker_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linker/linker_main.cpp')
-rw-r--r--linker/linker_main.cpp16
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