]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
dracut: add check, if we can write to the output image file
authorHarald Hoyer <harald@redhat.com>
Thu, 18 Feb 2010 17:27:39 +0000 (18:27 +0100)
committerHarald Hoyer <harald@redhat.com>
Thu, 18 Feb 2010 17:27:39 +0000 (18:27 +0100)
dracut

diff --git a/dracut b/dracut
index 47908c469ba340e0f77a35b4bd407ddadfc4dfb8..7e2b95482c8e3475f8b1992a8217f6f7eeb614c7 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -177,7 +177,8 @@ case $dracutmodules in
 esac
 
 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
-[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initramfs-$kernel.img"
+[[ $1 ]] && outfile=$1 || outfile="/boot/initramfs-$kernel.img"
+abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
 
 srcmods="/lib/modules/$kernel/"
 [[ $drivers_dir ]] && srcmods="$drivers_dir"
@@ -188,7 +189,18 @@ if [[ -f $outfile && ! $force ]]; then
     exit 1
 fi
 
-if ! [[ -w $(dirname $outfile) ]]; then
+outdir=$(dirname "$outfile")
+if ! [[ -d "$outdir" ]]; then
+    echo "Can't write $outfile: Directory $outdir does not exist."
+    exit 1
+fi
+
+if ! [[ -w "$outdir" ]]; then
+    echo "No permission to write $outdir."
+    exit 1
+fi
+
+if [[ -f "$outfile" ]] &&  ! [[ -w "$outfile" ]]; then
     echo "No permission to write $outfile."
     exit 1
 fi