From 936bae418b77ee9e06a93cd3cd444f4204446973 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Sun, 28 May 2017 15:46:51 +0100 Subject: Allow multiple filenames to patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes behaviour less confusing when multiple filenames are passed — previously, any extra filenames would be ignored completely, as would any options passed after a filename. Now these are taken into account. --- src/patchelf.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 55b38e3..cfa39e2 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -45,7 +45,7 @@ static bool debugMode = false; static bool forceRPath = false; -static std::string fileName; +static std::vector fileNames; static int pageSize = PAGESIZE; typedef std::shared_ptr> FileContents; @@ -1546,7 +1546,7 @@ static bool printNeeded = false; static bool noDefaultLib = false; template -static void patchElf2(ElfFile && elfFile) +static void patchElf2(ElfFile && elfFile, std::string fileName) { if (printInterpreter) printf("%s\n", elfFile.getInterpreter().c_str()); @@ -1588,17 +1588,19 @@ static void patchElf2(ElfFile && elfFile) static void patchElf() { - if (!printInterpreter && !printRPath && !printSoname && !printNeeded) - debug("patching ELF file '%s'\n", fileName.c_str()); + for (auto fileName : fileNames) { + if (!printInterpreter && !printRPath && !printSoname && !printNeeded) + debug("patching ELF file '%s'\n", fileName.c_str()); - debug("Kernel page size is %u bytes\n", getPageSize()); + debug("Kernel page size is %u bytes\n", getPageSize()); - auto fileContents = readFile(fileName); + auto fileContents = readFile(fileName); - if (getElfType(fileContents).is32Bit) - patchElf2(ElfFile(fileContents)); - else - patchElf2(ElfFile(fileContents)); + if (getElfType(fileContents).is32Bit) + patchElf2(ElfFile(fileContents), fileName); + else + patchElf2(ElfFile(fileContents), fileName); + } } @@ -1721,11 +1723,12 @@ int mainWrapped(int argc, char * * argv) printf(PACKAGE_STRING "\n"); return 0; } - else break; + else { + fileNames.push_back(arg); + } } - if (i == argc) error("missing filename"); - fileName = argv[i]; + if (fileNames.empty()) error("missing filename"); patchElf(); -- cgit v0.12