From 9e2ed8993af1246c4479644819af864c278b4f78 Mon Sep 17 00:00:00 2001 From: Sergey Bolshakov Date: Fri, 14 Mar 2008 17:59:18 +0300 Subject: [PATCH] fixed to fail on unclean gencpio termination --- mkinitfs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mkinitfs b/mkinitfs index 6038005..cf567a0 100755 --- a/mkinitfs +++ b/mkinitfs @@ -1,22 +1,29 @@ #!/bin/sh -e -out=$1 -shift +PROG=mkinitfs -[ -n "$out" ] || { - echo "Usage: mkinitfs outfile" >&2 +Fatal() +{ + echo "$PROG: $*" >&2 exit 1 } +TEMP= + exit_handler() { local rc=$? trap - EXIT - [ $rc -eq 0 ] || rm -f -- $out + [ -z "$TEMP" ] || rm -f -- "$TEMP" + [ $rc -eq 0 ] || rm -f -- "$OUT" exit $rc } +[ -n "$1" ] || Fatal "Usage: mkinitfs outfile" +OUT="$1"; shift + trap exit_handler HUP PIPE INT TERM QUIT EXIT +TEMP=`mktemp -t mkinitfs.XXXXXXXXXX` || Fatal "Failed to create temporary file." ( @@ -60,4 +67,6 @@ find /lib/mkinitrd/udev -type f|\ sed -e 's,/lib/mkinitrd/udev,,' -e 's,^.\+$,file\t&\t/lib/mkinitrd/udev&\t0755\t0 0,g' find /etc/modprobe.d/ /etc/udev/rules.d -type f|\ sed -e 's,^.\+$,file\t&\t&\t0644\t0 0,g' -) | `pwd`/gencpio - |gzip -c > $out +) | `pwd`/gencpio - > "$TEMP" + +gzip -c < "$TEMP" > "$OUT"