1 From 2041085d1a700201dc088991ca8136e7935bf42f Mon Sep 17 00:00:00 2001
2 From: Victor Kamensky <kamensky@cisco.com>
3 Date: Wed, 21 Mar 2018 11:35:26 -0500
4 Subject: [PATCH] sysroot: handle symbolic links with absolute name relative to
7 In case of symbolic link found under sysroot point to absolute path,
8 instead of trying to look for such absolute path in host system,
9 apply sysroot prefix first.
11 Upstream-Status: Backport
12 Signed-off-by: Victor Kamensky <kamensky@cisco.com>
14 util.cxx | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 1 file changed, 76 insertions(+)
18 ===================================================================
21 @@ -441,6 +441,64 @@ split_lines(const char *buf, size_t n)
26 +follow_link(const string& name, const string& sysroot)
33 + const char *f = name.c_str();
37 + linkname = (char *) malloc(st.st_size + 1);
41 + r = readlink(f, linkname, st.st_size + 1);
42 + linkname[st.st_size] = '\0';
44 + * If we have non-empty sysroot and we got link that
45 + * points to absolute path name, we need to look at
46 + * this path relative to sysroot itself. access and
47 + * stat will follow symbolic links correctly only in
48 + * case with empty sysroot.
50 + while (r != -1 && linkname && linkname[0] == '/')
52 + string fname1 = sysroot + linkname;
53 + const char *f1 = fname1.c_str();
54 + if (access(f1, X_OK) == 0
55 + && stat(f1, &st) == 0
56 + && S_ISREG(st.st_mode))
61 + else if (lstat(f1, &st) == 0
62 + && S_ISLNK(st.st_mode))
65 + linkname = (char *) malloc(st.st_size + 1);
68 + r = readlink(f1, linkname, st.st_size + 1);
69 + linkname[st.st_size] = '\0';
83 // Resolve an executable name to a canonical full path name, with the
84 // same policy as execvp(). A program name not containing a slash
85 // will be searched along the $PATH.
86 @@ -465,6 +523,14 @@ string find_executable(const string& nam
87 if (name.find('/') != string::npos) // slash in the path already?
89 retpath = sysroot + name;
91 + const char *f = retpath.c_str();
93 + && lstat(f, &st) == 0
94 + && S_ISLNK(st.st_mode))
96 + retpath = follow_link(f, sysroot);
99 else // Nope, search $PATH.
101 @@ -493,6 +559,16 @@ string find_executable(const string& nam
105 + else if (sysroot != ""
106 + && lstat(f, &st) == 0
107 + && S_ISLNK(st.st_mode))
109 + retpath = follow_link(f, sysroot);