]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(base): remove grep dependency
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Wed, 30 Nov 2022 11:44:50 +0000 (12:44 +0100)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Sat, 3 Dec 2022 11:31:19 +0000 (11:31 +0000)
The base module requires grep with the `rd.memdebug=1` command line parameter.
As this code is broken if grep is not added by other means and grep is only
required for this, rewriting this code to avoid the dependency.

modules.d/99base/dracut-lib.sh

index 6ba836ec3b82e724274ca28a71bc1194bcdec8fc..83ca9fab92fe4a5f1f2755e2118da62bb54f58b8 100755 (executable)
@@ -1104,7 +1104,13 @@ make_trace_mem() {
 show_memstats() {
     case $1 in
         shortmem)
-            grep -e "^MemFree" -e "^Cached" -e "^Slab" /proc/meminfo
+            while read -r line || [ -n "$line" ]; do
+                str_starts "$line" "MemFree" \
+                    || str_starts "$line" "Cached" \
+                    || str_starts "$line" "Slab" \
+                    || continue
+                echo "$line"
+            done < /proc/meminfo
             ;;
         mem)
             cat /proc/meminfo