ignore ld preload config

This commit is contained in:
outofmemo 2022-12-04 09:31:14 +08:00
parent 3716d59cd9
commit e816bafc35

View File

@ -11,6 +11,11 @@ dst="$2"
shift shift
shift shift
libs="$(ldd "$src" | grep -F '/' | sed -E 's|[^/]*/([^ ]+).*?|/\1|')"
ld_so="$(echo "$libs" | grep -F '/ld-linux-')"
ld_so="$(basename "$ld_so")"
program="$(basename "$src")"
cat >"$dst" <<EOF cat >"$dst" <<EOF
#!/bin/bash #!/bin/bash
tmp_dir="\$(mktemp -d)" tmp_dir="\$(mktemp -d)"
@ -21,13 +26,11 @@ if ! (touch "\$check_path" && chmod +x "\$check_path" && [ -x "\$check_path" ]);
tmp_dir="\$(TMPDIR="\$(pwd)" mktemp -d)" tmp_dir="\$(TMPDIR="\$(pwd)" mktemp -d)"
fi fi
sed '1,/^#__END__$/d' "\$0" | tar -xz -C "\$tmp_dir" sed '1,/^#__END__$/d' "\$0" | tar -xz -C "\$tmp_dir"
"\$tmp_dir/LD_SO" --library-path "\$tmp_dir" "\$tmp_dir/PROGRAM" "\$@" sed -i 's@/etc/ld.so.preload@/etc/___so.preload@g' "\$tmp_dir/$ld_so"
"\$tmp_dir/$ld_so" --library-path "\$tmp_dir" "\$tmp_dir/$program" "\$@"
exit \$? exit \$?
#__END__ #__END__
EOF EOF
libs="$(ldd "$src" | grep -F '/' | sed -E 's|[^/]*/([^ ]+).*?|/\1|')"
ld_so="$(echo "$libs" | grep -F '/ld-linux-')"
sed -E -i -e 's|PROGRAM|'"$(basename "$src")"'|' -e 's|LD_SO|'"$(basename "$ld_so")"'|' "$dst"
tar -czh --transform 's/.*\///g' "$src" $libs "$@" >>"$dst" 2> >(grep -v 'Removing leading' >&2) tar -czh --transform 's/.*\///g' "$src" $libs "$@" >>"$dst" 2> >(grep -v 'Removing leading' >&2)
chmod +x "$dst" chmod +x "$dst"