From: Michal Sekletar Date: Mon, 9 Sep 2024 10:54:16 +0000 (+0200) Subject: analyze: modernize opening ELF binary a bit X-Git-Tag: v257-rc1~99^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b189f0d4553b2f7fb52e48d38a530dd95daca39c;p=thirdparty%2Fsystemd.git analyze: modernize opening ELF binary a bit --- diff --git a/src/analyze/analyze-inspect-elf.c b/src/analyze/analyze-inspect-elf.c index 01824d5eaba..12f347de6a9 100644 --- a/src/analyze/analyze-inspect-elf.c +++ b/src/analyze/analyze-inspect-elf.c @@ -4,6 +4,7 @@ #include "analyze.h" #include "analyze-inspect-elf.h" +#include "chase.h" #include "elf-util.h" #include "errno-util.h" #include "fd-util.h" @@ -19,23 +20,13 @@ static int analyze_elf(char **filenames, sd_json_format_flags_t json_flags) { STRV_FOREACH(filename, filenames) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *package_metadata = NULL; _cleanup_(table_unrefp) Table *t = NULL; - _cleanup_free_ char *abspath = NULL, *path = NULL, *stacktrace = NULL; + _cleanup_free_ char *abspath = NULL, *stacktrace = NULL; _cleanup_close_ int fd = -EBADF; bool coredump = false; - r = path_make_absolute_cwd(*filename, &abspath); - if (r < 0) - return log_error_errno(r, "Could not make an absolute path out of \"%s\": %m", *filename); - - path = path_join(empty_to_root(arg_root), abspath); - if (!path) - return log_oom(); - - path_simplify(path); - - fd = RET_NERRNO(open(path, O_RDONLY|O_CLOEXEC)); + fd = chase_and_open(*filename, arg_root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, &abspath); if (fd < 0) - return log_error_errno(fd, "Could not open \"%s\": %m", path); + return log_error_errno(fd, "Could not open \"%s\": %m", *filename); r = parse_elf_object(fd, abspath, arg_root, /* fork_disable_dump= */false, &stacktrace, &package_metadata); if (r < 0)