From 63cc7b9216d69f413cd5414c96cf2c9a403e03ae Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 11 Feb 2009 20:15:48 -0800 Subject: minitramfs: find/cpio exit codes ignored while building initramfs The final stage of mkinitramfs that builds the image does not verify the exit codes of find or cpio: (cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip >"${outfile}") || exit 1 Once bug 514936 is solved, this will be even more important, since cpio will actually return errors. Attached is a gross alternative to depending on bash... Current behavior: $ find /fail | cpio --quiet --dereference -o -H newc | gzip > /tmp/archive.gz find: `/fail': No such file or directory $ echo $? 0 Desired behavior: $ set -o pipefail $ find /fail | cpio --quiet --dereference -o -H newc | gzip > /tmp/archive.gz find: `/fail': No such file or directory $ echo $? 1 (closes: #514938) [ already useful in finding stupid mkinitramfs path errors -maks ] --- mkinitramfs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mkinitramfs b/mkinitramfs index 70ff0fe..0aa2ba7 100755 --- a/mkinitramfs +++ b/mkinitramfs @@ -266,7 +266,24 @@ if [ -e "${CONFDIR}/DSDT.aml" ]; then fi [ "${verbose}" = y ] && echo "Building cpio ${outfile} initramfs" -(cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip >"${outfile}") || exit 1 +( +# work around lack of "set -o pipefail" for the following pipe: +# cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip >"${outfile}" +exec 3>&1 +eval ` + # http://cfaj.freeshell.org/shell/cus-faq-2.html + exec 4>&1 >&3 3>&- + { + cd "${DESTDIR}" && find . 4>&-; echo "ec1=$?;" >&4 + } | { + cpio --quiet --dereference -o -H newc 4>&-; echo "ec2=$?;" >&4 + } | gzip >"${outfile}" + echo "ec3=$?;" >&4 +` +if [ "$ec1" -ne 0 ]; then exit "$ec1"; fi +if [ "$ec2" -ne 0 ]; then exit "$ec2"; fi +if [ "$ec3" -ne 0 ]; then exit "$ec3"; fi +) || exit $? if [ -s "${__TMPCPIOGZ}" ]; then cat "${__TMPCPIOGZ}" >>"${outfile}" || exit 1 -- cgit v1.2.3