update_ucode: avoid calling find on non-existing directories

During various reasons (specifically, due to being called at various
stags of mirocode_ctl installation/upgrade) it is possible that some
directories do not exist, which is problematic, as find exits
with non-zero exit code if being called on them.  Avoid that by wrapping
find calls in a function that checks that the first find argument
is indeed an existing directory before calling find itself.

* update_ucode (find_d): New function.
Convert find calls that are not prefixed with $cmd into find_d calls.
* microcode_ctl.spec (Release): Bump to 4.
(%changelog): Mention it.

Resolves: #2225681
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
This commit is contained in:
Eugene Syromiatnikov 2023-08-09 16:47:47 +02:00
parent c74a0195dc
commit 5fab5a8467
2 changed files with 17 additions and 8 deletions

View File

@ -12,7 +12,7 @@
Summary: CPU microcode updates for Intel x86 processors
Name: microcode_ctl
Version: %{intel_ucode_version}
Release: 3%{?dist}
Release: 4%{?dist}
Epoch: 4
License: CC0 and Redistributable, no modification permitted
URL: https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files
@ -545,6 +545,10 @@ rm -rf %{buildroot}
%changelog
* Tue Aug 01 2023 Eugene Syromiatnikov <esyr@redhat.com> - 4:20230214-4
- Avoid spurious find failures due to calls on directories that may not exist
(#2225681).
* Wed Jun 28 2023 Eugene Syromiatnikov <esyr@redhat.com> - 4:20230214-3
- Force locale to C in check_caveats, reload_microcode, and update_ucode
(#2218104).

View File

@ -17,6 +17,11 @@ usage()
debug() { [ 0 = "$verbose" ] || echo "$*" >&2; }
# Calls find only if the first argument exists and is a directory.
# Avoids spurious "find: '...' No such file or directory" for the directories
# that may not exist.
find_d() { [ \! -d "$1" ] || find "$@"; }
MC_DIR=/usr/share/microcode_ctl
INTEL_UCODE_DIR=intel-ucode
DATA_DIR=/usr/share/microcode_ctl/ucode_with_caveats
@ -81,7 +86,7 @@ add|remove|refresh|list)
if [ -z "$kernel" ]; then
debug "No kernel versions provided, scanning..."
kvers=$(find /lib/modules/ -name '[2-9].*' -print)
kvers=$(find_d /lib/modules/ -name '[2-9].*' -print)
for k_dir in $kvers; do
k="${k_dir#/lib/modules/}"
[ ! -e "${k_dir}/symvers.gz" ] || {
@ -90,7 +95,7 @@ add|remove|refresh|list)
}
done
kvers=$(find /lib/firmware/ -name '[2-9].*' -print)
kvers=$(find_d /lib/firmware/ -name '[2-9].*' -print)
for k_dir in $kvers; do
k="${k_dir#/lib/firmware/}"
[ ! -d "$k_dir" ] || {
@ -131,7 +136,7 @@ while :; do
refresh|remove|list)
debug " Removing old files from ${FW_DIR}/${INTEL_UCODE_DIR}"
if [ 0 = "$remove_cleanup" ]; then
find "${MC_DIR}/${INTEL_UCODE_DIR}" \
find_d "${MC_DIR}/${INTEL_UCODE_DIR}" \
-maxdepth 1 -mindepth 1 \
-type f -printf '%f\n'
else
@ -154,7 +159,7 @@ while :; do
done
[ "xlist" = "x$action" ] || {
# Removing possible dangling symlinks
find "${FW_DIR}/${INTEL_UCODE_DIR}" \
find_d "${FW_DIR}/${INTEL_UCODE_DIR}" \
-maxdepth 1 -mindepth 1 \
-type l -printf '%p\n' \
| while read -r fname; do
@ -216,7 +221,7 @@ fi | while read -r i; do
debug " Removing \"$paths\" (part of $action)..."
for p in $(printf "%s" "$paths"); do
find "$DATA_DIR/$i" -path "$DATA_DIR/$i/$p" \
find_d "$DATA_DIR/$i" -path "$DATA_DIR/$i/$p" \
-printf "%P\n"
done | while read -r path; do
[ -e "$FW_DIR/$k/readme-$i" ] || {
@ -274,7 +279,7 @@ fi | while read -r i; do
}
for p in $(printf "%s" "$paths"); do
find "$DATA_DIR/$i" -path "$DATA_DIR/$i/$p" \
find_d "$DATA_DIR/$i" -path "$DATA_DIR/$i/$p" \
-printf "%P\n"
done | while read -r path; do
[ ! -e "$FW_DIR/$k/$path" ] || {
@ -307,7 +312,7 @@ done
debug "Checking for dangling symlinks..."
for k in $(echo "$kernel"); do
debug " Processing kernel version \"$k\""
find "${FW_DIR}/${k}" \
find_d "${FW_DIR}/${k}" \
-mindepth 1 -type l -printf '%p\n' \
| while read -r fname; do
[ -e "$fname" ] || {