From 1079122ea0c1733024dbebadd2ae8ad2c88a9bee Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 31 Jan 2012 22:20:49 -0500 Subject: [PATCH] copy_binaries: utility function to pick up a binary and needed libs The existing multipath functionality manually picks up a binary and lots of needed libraries manually, and sometimes misses libraries if the binary was linked against something else. Use lddtree from app-misc/pax-utils to get all libraries with the binary. The only ones that will be missed are those that are dlopen()ed. cpio is used for copying to preserve directory structure. lddtree usage replaces a larger manual function from calling ldd, that was also vulnerable to injections. Signed-off-by: Robin H. Johnson (commit message rewritten) --- ChangeLog | 4 ++++ gen_initramfs.sh | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc8be73..5115896 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ # Distributed under the GPL v2 # $Id$ + 06 Feb 2012: Richard Yao gen_initramfs.sh: + copy_binaries utility function for putting binaries and librares into + initramfs (see git commit for full details). + 06 Feb 2012; Robin H. Johnson defaults/initrd.scripts: Support virtio devices, and provide fallback of all remaining devices. diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 32a1b1e..b96e36e 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -3,6 +3,15 @@ CPIO_ARGS="--quiet -o -H newc" +copy_binaries() { + + local destdir=$1 files=$2 + + # Copy files + lddtree $files | tr ')(' '\n' |awk '/=>/{ if($3 ~ /^\//){print $3}}' | sort | uniq | cpio -p --make-directories --dereference --quiet $destdir + +} + append_base_layout() { if [ -d "${TEMP}/initramfs-base-temp" ] then -- 2.26.2