28ab1c
From 6ed9cff05fb1015fe50951c93430052004d22b01 Mon Sep 17 00:00:00 2001
28ab1c
From: Harald Hoyer <harald@redhat.com>
28ab1c
Date: Fri, 21 May 2021 12:19:32 +0200
28ab1c
Subject: [PATCH] fix(dracut-functions): get_maj_min without
28ab1c
 get_maj_min_cache_file set
28ab1c
28ab1c
If `get_maj_min_cache_file` is unset `get_maj_min()` would error out.
28ab1c
28ab1c
Fix it to work without a cache file set.
28ab1c
28ab1c
(cherry picked from commit a277a5fc7acc0a9e8d853f09671495f9d27645c1)
28ab1c
28ab1c
Cherry-picked from: a277a5fc7acc0a9e8d853f09671495f9d27645c1
28ab1c
Resolves: #1957622
28ab1c
---
28ab1c
 dracut-functions.sh | 15 +++++++++++----
28ab1c
 1 file changed, 11 insertions(+), 4 deletions(-)
28ab1c
28ab1c
diff --git a/dracut-functions.sh b/dracut-functions.sh
28ab1c
index a221967c..eb2ce748 100755
28ab1c
--- a/dracut-functions.sh
28ab1c
+++ b/dracut-functions.sh
28ab1c
@@ -200,13 +200,20 @@ get_fs_env() {
28ab1c
 # 8:2
28ab1c
 get_maj_min() {
28ab1c
     local _majmin
28ab1c
-    out="$(grep -m1 -oP "^$1 \K\S+$" "${get_maj_min_cache_file:?}")"
28ab1c
-    if [ -z "$out" ]; then
28ab1c
+    local _out
28ab1c
+
28ab1c
+    if [[ $get_maj_min_cache_file ]]; then
28ab1c
+        _out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
28ab1c
+    fi
28ab1c
+
28ab1c
+    if ! [[ "$_out" ]]; then
28ab1c
     _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
28ab1c
         out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
28ab1c
-        echo "$1 $out" >> "${get_maj_min_cache_file:?}"
28ab1c
+        if [[ $get_maj_min_cache_file ]]; then
28ab1c
+            echo "$1 $_out" >> "$get_maj_min_cache_file"
28ab1c
+    fi
28ab1c
     fi
28ab1c
-    echo -n "$out"
28ab1c
+    echo -n "$_out"
28ab1c
 }
28ab1c
 
28ab1c
 # get_devpath_block <device>
28ab1c