diff options
author | Mark Wielaard <mark@klomp.org> | 2020-02-07 18:17:25 -0500 |
---|---|---|
committer | Frank Ch. Eigler <fche@redhat.com> | 2020-02-10 11:10:12 -0500 |
commit | 499129e77aa88b94756bd6c8d50347721689065c (patch) | |
tree | af67236208dd7b01e68457fb034944ac7d1ad238 | |
parent | 8ef876aa170abec983d4359e51a33209ceb01caa (diff) | |
download | elfutils-499129e77aa88b94756bd6c8d50347721689065c.tar.gz |
debuginfod: archive processing: handle -Z EXT=cat with direct fopen
Signed-off-by: Mark Wielaard <mark@klomp.org>
-rw-r--r-- | debuginfod/debuginfod.cxx | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 6d729023..0acd70e4 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1160,11 +1160,24 @@ handle_buildid_r_match (int64_t b_mtime, archive_extension = arch.first; archive_decoder = arch.second; } - string popen_cmd = archive_decoder + " " + shell_escape(b_source0); - FILE* fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? - if (fp == NULL) - throw libc_exception (errno, string("popen ") + popen_cmd); - defer_dtor<FILE*,int> fp_closer (fp, pclose); + FILE* fp; + defer_dtor<FILE*,int>::dtor_fn dfn; + if (archive_decoder != "cat") + { + string popen_cmd = archive_decoder + " " + shell_escape(b_source0); + fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? + dfn = pclose; + if (fp == NULL) + throw libc_exception (errno, string("popen ") + popen_cmd); + } + else + { + fp = fopen (b_source0.c_str(), "r"); + dfn = fclose; + if (fp == NULL) + throw libc_exception (errno, string("fopen ") + b_source0); + } + defer_dtor<FILE*,int> fp_closer (fp, dfn); struct archive *a; a = archive_read_new(); @@ -2048,11 +2061,25 @@ archive_classify (const string& rps, string& archive_extension, archive_extension = arch.first; archive_decoder = arch.second; } - string popen_cmd = archive_decoder + " " + shell_escape(rps); - FILE* fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? - if (fp == NULL) - throw libc_exception (errno, string("popen ") + popen_cmd); - defer_dtor<FILE*,int> fp_closer (fp, pclose); + + FILE* fp; + defer_dtor<FILE*,int>::dtor_fn dfn; + if (archive_decoder != "cat") + { + string popen_cmd = archive_decoder + " " + shell_escape(rps); + fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? + dfn = pclose; + if (fp == NULL) + throw libc_exception (errno, string("popen ") + popen_cmd); + } + else + { + fp = fopen (rps.c_str(), "r"); + dfn = fclose; + if (fp == NULL) + throw libc_exception (errno, string("fopen ") + rps); + } + defer_dtor<FILE*,int> fp_closer (fp, dfn); struct archive *a; a = archive_read_new(); |