|
31 | 31 | #include "src/common/fs/temp_file.h" |
32 | 32 | #include "src/common/minitar/minitar.h" |
33 | 33 | #include "src/common/system/config.h" |
| 34 | +#include "src/common/system/linux_headers_utils.h" |
34 | 35 | #include "src/common/system/proc_pid_path.h" |
35 | 36 | #include "src/common/zlib/zlib_wrapper.h" |
36 | 37 |
|
@@ -209,55 +210,11 @@ Status FindLinuxHeadersDirectory(const std::filesystem::path& lib_modules_dir) { |
209 | 210 | return error::NotFound("Could not find 'source' or 'build' under $0.", lib_modules_dir.string()); |
210 | 211 | } |
211 | 212 |
|
212 | | -StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::filesystem::path p) { |
213 | | - // Check if "p" is a symlink. |
214 | | - std::error_code ec; |
215 | | - const bool is_symlink = std::filesystem::is_symlink(p, ec); |
216 | | - if (ec) { |
217 | | - return error::NotFound(absl::Substitute("Did not find the host headers at path: $0, $1.", |
218 | | - p.string(), ec.message())); |
219 | | - } |
220 | | - |
221 | | - if (!is_symlink) { |
222 | | - // Not a symlink, we are good now. |
223 | | - return p; |
224 | | - } |
225 | | - |
226 | | - // Resolve the symlink, and re-convert to a host path.. |
227 | | - const std::filesystem::path resolved = std::filesystem::read_symlink(p, ec); |
228 | | - if (ec) { |
229 | | - return error::Internal(ec.message()); |
230 | | - } |
231 | | - |
232 | | - // Relative paths containing "../" can result in an invalid host mount path when using |
233 | | - // ToHostPath. Therefore, we need to treat the absolute and relative cases differently. |
234 | | - std::filesystem::path resolved_host_path; |
235 | | - if (resolved.is_absolute()) { |
236 | | - resolved_host_path = system::Config::GetInstance().ToHostPath(resolved); |
237 | | - VLOG(1) << absl::Substitute( |
238 | | - "Symlink target is an absolute path. Converting that to host path: $0 -> $1.", |
239 | | - resolved.string(), resolved_host_path.string()); |
240 | | - } else { |
241 | | - resolved_host_path = p.parent_path(); |
242 | | - resolved_host_path /= resolved.string(); |
243 | | - VLOG(1) << absl::Substitute( |
244 | | - "Symlink target is a relative path. Concatenating it to parent directory: $0", |
245 | | - resolved_host_path.string()); |
246 | | - } |
247 | | - |
248 | | - // Downstream won't be ok unless the resolved host path exists; return an error if needed. |
249 | | - if (!fs::Exists(resolved_host_path)) { |
250 | | - return error::NotFound(absl::Substitute("Did not find host headers at resolved path: $0.", |
251 | | - resolved_host_path.string())); |
252 | | - } |
253 | | - return resolved_host_path; |
254 | | -} |
255 | | - |
256 | 213 | Status LinkHostLinuxHeadersKernel(const std::filesystem::path& lib_modules_dir) { |
257 | 214 | const auto host_path = system::Config::GetInstance().ToHostPath(lib_modules_dir); |
258 | 215 | LOG(INFO) << absl::Substitute("Looking for host Linux headers at $0.", host_path.string()); |
259 | 216 |
|
260 | | - PX_ASSIGN_OR_RETURN(const auto resolved_host_path, ResolvePossibleSymlinkToHostPath(host_path)); |
| 217 | + PX_ASSIGN_OR_RETURN(const auto resolved_host_path, system::ResolvePossibleSymlinkToHostPath(host_path)); |
261 | 218 | PX_RETURN_IF_ERROR(fs::CreateSymlinkIfNotExists(resolved_host_path, lib_modules_dir)); |
262 | 219 | LOG(INFO) << absl::Substitute("Linked host headers at $0 to symlink in pem namespace at $1.", |
263 | 220 | resolved_host_path.string(), lib_modules_dir.string()); |
|
0 commit comments