Blame SOURCES/0396-dracut-only-use-one-tmpdir.patch

712866
From b4ad021d34975f25f50024e3601354f75593837f Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Wed, 29 Jun 2016 11:25:12 +0200
712866
Subject: [PATCH] dracut: only use one tmpdir
712866
712866
also remove any partial written initramfs images
712866
---
712866
 dracut-logger.sh |  3 +--
712866
 dracut.sh        | 66 +++++++++++++++++++++++++++++++++++++++-----------------
712866
 2 files changed, 47 insertions(+), 22 deletions(-)
712866
712866
diff --git a/dracut-logger.sh b/dracut-logger.sh
5c6c2a
index ffa56167..53f74625 100755
712866
--- a/dracut-logger.sh
712866
+++ b/dracut-logger.sh
712866
@@ -150,8 +150,7 @@ dlog_init() {
712866
             && type -P systemd-cat &>/dev/null \
712866
             && systemctl --quiet is-active systemd-journald.socket &>/dev/null \
712866
             && { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then
712866
-            readonly _dlogdir="$(mktemp --tmpdir="$TMPDIR/" -d -t dracut-log.XXXXXX)"
712866
-            readonly _systemdcatfile="$_dlogdir/systemd-cat"
712866
+            readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat"
712866
             mkfifo "$_systemdcatfile"
712866
             readonly _dlogfd=15
712866
             systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" &
712866
diff --git a/dracut.sh b/dracut.sh
5c6c2a
index b85d42dd..78976792 100755
712866
--- a/dracut.sh
712866
+++ b/dracut.sh
712866
@@ -813,24 +813,25 @@ fi
712866
 [[ $hostonly != "-h" ]] && unset hostonly
712866
 
712866
 readonly TMPDIR="$tmpdir"
712866
-readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
712866
-[ -d "$initdir" ] || {
712866
-    printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
712866
+readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
712866
+[ -d "$DRACUT_TMPDIR" ] || {
712866
+    printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
712866
     exit 1
712866
 }
712866
 
712866
 # clean up after ourselves no matter how we die.
712866
 trap '
712866
     ret=$?;
712866
-    [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
712866
-    [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
712866
-    [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
712866
+    [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
712866
     exit $ret;
712866
     ' EXIT
712866
 
712866
 # clean up after ourselves no matter how we die.
712866
 trap 'exit 1;' SIGINT
712866
 
712866
+readonly initdir="${DRACUT_TMPDIR}/initramfs"
712866
+mkdir "$initdir"
712866
+
712866
 export DRACUT_KERNEL_LAZY="1"
712866
 export DRACUT_RESOLVE_LAZY="1"
712866
 
712866
@@ -878,20 +879,18 @@ case "$(arch)" in
712866
     i686|x86_64)
712866
         ;;
712866
     *)
712866
-        early_microcode=no
712866
-        dinfo "Disabling early microcode for $(arch)"
712866
+        if [[ $early_microcode = yes ]]; then
712866
+            early_microcode=no
712866
+            dinfo "Disabling early microcode for $(arch)"
712866
+        fi
712866
         ;;
712866
 esac
712866
 
712866
 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
712866
-    readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
712866
-    [ -d "$early_cpio_dir" ] || {
712866
-        printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_cpio.XXXXXX failed." >&2
712866
-        exit 1
712866
-    }
712866
+    readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio"
712866
+    mkdir "$early_cpio_dir"
712866
 fi
712866
 
712866
-
712866
 if (( ${#drivers_l[@]} )); then
712866
     drivers=''
712866
     while pop drivers_l val; do
712866
@@ -1485,7 +1484,7 @@ if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
712866
 fi
712866
 
712866
 if [[ $early_microcode = yes ]]; then
712866
-    dinfo "*** Generating early-microcode cpio image ***"
712866
+    dinfo "*** Generating early-microcode cpio image contents ***"
712866
     ucode_dir=(amd-ucode intel-ucode)
712866
     ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
712866
     _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
712866
@@ -1521,6 +1520,9 @@ if [[ $early_microcode = yes ]]; then
712866
             fi
712866
         done
712866
     done
712866
+    if ! [[ $create_early_cpio = yes ]]; then
712866
+        dinfo "*** No early-microcode cpio image needed ***"
712866
+    fi
712866
 fi
712866
 
712866
 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
712866
@@ -1546,23 +1548,47 @@ dinfo "*** Creating image file ***"
712866
 [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"
712866
 
712866
 if [[ $create_early_cpio = yes ]]; then
712866
+    dinfo "*** Creating microcode section ***"
712866
     echo 1 > "$early_cpio_dir/d/early_cpio"
712866
     # The microcode blob is _before_ the initramfs blob, not after
712866
-    (cd "$early_cpio_dir/d";     find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > $outfile)
712866
+    if ! (
712866
+            umask 077
712866
+            cd "$early_cpio_dir/d"
712866
+            find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
712866
+        ); then
712866
+        dfatal "dracut: creation of $outfile failed"
712866
+        exit 1
712866
+    else
712866
+        dinfo "*** Created microcode section ***"
712866
+    fi
712866
 fi
712866
-if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
712866
-    $compress >> "$outfile"; ); then
712866
+
712866
+if ! (
712866
+        umask 077
712866
+        cd "$initdir"
712866
+        find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
712866
+            $compress >> "${DRACUT_TMPDIR}/initramfs.img";
712866
+    ); then
712866
     dfatal "dracut: creation of $outfile failed"
712866
     exit 1
712866
 fi
712866
+
712866
 dinfo "*** Creating image file done ***"
712866
 
712866
 if (( maxloglvl >= 5 )); then
712866
     if [[ $allowlocal ]]; then
712866
-	"$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
712866
+	"$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
712866
     else
712866
-        lsinitrd "$outfile"| ddebug
712866
+        lsinitrd "${DRACUT_TMPDIR}/initramfs.img" | ddebug
712866
     fi
712866
 fi
712866
 
712866
+if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile" |& derror ; then
712866
+    dinfo "*** Creating initramfs image file '$outfile' done ***"
712866
+else
712866
+    rm -f -- "$outfile"
712866
+    dfatal "dracut: creation of $outfile failed"
712866
+    exit 1
712866
+fi
712866
+
712866
 exit 0