From 5b25b99e2eed7eaf82bf73b8e8021b314fc3cbdb Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 3 Oct 2018 00:15:19 +0200 Subject: Fix runtime crash in bundled package --- scripts/package.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/scripts/package.py b/scripts/package.py index 47fc45d..a10cdcb 100755 --- a/scripts/package.py +++ b/scripts/package.py @@ -13,10 +13,10 @@ run_script_linux = """ set -e -script_path=`realpath $0` +script_path=`readlink -f $0` script_dir=`dirname $script_path` cd "$script_dir" -"./$PROGRAM_NAME" +"./$SO_LOADER" --library-path libs "./$PROGRAM_NAME" "$@" """ def get_executable_dynamic_libraries(filepath): @@ -31,7 +31,7 @@ def get_executable_dynamic_libraries(filepath): if len(s) >= 3 and b"=>" in s: lib_path = " ".join(x.decode("UTF-8") for x in s[2:-1]) if os.path.exists(lib_path): - libs.append(os.path.realpath(lib_path)) + libs.append([os.path.realpath(lib_path), os.path.basename(lib_path)]) return libs def make_executable(filepath): @@ -46,20 +46,20 @@ def main(): os.makedirs(sys.argv[2], exist_ok=True) libs = get_executable_dynamic_libraries(sys.argv[1]) - so_loader_pattern = re.compile("ld-[0-9.]+\\.so.*") + so_loader_pattern = re.compile("ld-linux-x86-64\\.so.*") so_loader = None for lib in libs: - lib_filename = os.path.basename(lib) - if so_loader_pattern.match(lib_filename): + if so_loader_pattern.match(lib[1]): if so_loader != None: print("Unexpected error: found multiple so loaders, unable to recover") exit(2) - so_loader = lib_filename + so_loader = lib[1] if not so_loader: print("Unexpected error: no so loader found, unable to recover") exit(5) + so_loader = os.path.join("libs", so_loader) executable_filename = os.path.basename(sys.argv[1]) new_executable_path = os.path.join(sys.argv[2], executable_filename) shutil.copyfile(sys.argv[1], new_executable_path) @@ -72,7 +72,7 @@ def main(): print("Failed to execute patchelf --set-interpreter on executable %s, error: %s" % (new_executable_path, stderr)) exit(3) - process = subprocess.Popen(["patchelf", "--set-rpath", ".", new_executable_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["patchelf", "--set-rpath", "libs", new_executable_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = process.communicate() if process.returncode != 0: print("Failed to execute patchelf --set-rpath on executable %s, error: %s" % (new_executable_path, stderr)) @@ -80,19 +80,19 @@ def main(): run_script_path = os.path.join(sys.argv[2], "run.sh") with open(run_script_path, "wb") as run_script: - run_script.write(run_script_linux.replace("$PROGRAM_NAME", executable_filename).encode("UTF-8")) + run_script.write(run_script_linux.replace("$SO_LOADER", so_loader).replace("$PROGRAM_NAME", "program").encode("UTF-8")) make_executable(run_script_path) package_name = new_executable_path + ".tar.gz" print("Creating archive %s" % os.path.basename(package_name)) with tarfile.open(package_name, "w:gz") as tar: for lib in libs: - print("Adding shared library %s to package" % lib) - tar.add(lib, arcname=os.path.basename(lib)) + print("Adding shared library %s to package" % lib[0]) + tar.add(lib[0], arcname=os.path.join("libs", lib[1])) print("Adding executable %s to package" % sys.argv[1]) - tar.add(new_executable_path, arcname=executable_filename) + tar.add(new_executable_path, arcname="program") print("Adding run script %s to package" % run_script_path) - tar.add(run_script_path, arcname="run.sh") + tar.add(run_script_path, arcname=executable_filename) print("Removing temporary files") os.remove(new_executable_path) -- cgit v1.2.3