dracut/0031-fix-dracut-functions-avoid-awk-in-get_maj_min.patch
Pavel Valena 5857b7d190 Resolves: RHEL-39404,RHEL-47145,RHEL-53350,RHEL-53361,RHEL-53431,RHEL-53791,RHEL-54650
From-source-git-commit: e3d7b6907c414bbe25a93a3fcd2de2205316c13f

Changes added using `packit source-git update-dist-git`, which has different
patch definition format than `centpkg import` (this will be used from now on).

Also, fixup previous entry wrong date in %changelog.
2024-08-19 13:34:50 +02:00

40 lines
1.3 KiB
Diff

From d18bbc304e838ecf3b888ce4d70f1d96d21821f5 Mon Sep 17 00:00:00 2001
From: Daniel McIlvaney <damcilva@microsoft.com>
Date: Fri, 7 Jun 2024 11:38:54 -0700
Subject: [PATCH 31/31] fix(dracut-functions): avoid awk in get_maj_min()
The `get_maj_min()` cache lookup is commonly used
across many flows. While `awk` should be available,
some highly constrained environments may not have it.
A second call to `grep` can provide the same behaviour
without adding a dependnecy.
Lines in the cache will be of the form "/dev/sda2 8:2".
`awk '{print $NF}'` returns the last word of a matching line. Since
the initial matching regex is so specific a second call to grep can
easily extract the last word.
(cherry picked commit ec7efd5701e9a1b24f2e85666d625fb1fe46ce86)
Related: RHEL-47145
---
dracut-functions.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dracut-functions.sh b/dracut-functions.sh
index 43d905e3..b4d57454 100755
--- a/dracut-functions.sh
+++ b/dracut-functions.sh
@@ -243,7 +243,7 @@ get_maj_min() {
local _out
if [[ $get_maj_min_cache_file ]]; then
- _out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | awk '{print $NF}')"
+ _out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | grep -oE "\S+$")"
fi
if ! [[ "$_out" ]]; then
--
2.42.0