Skip to content

Conversation

@travier
Copy link
Member

@travier travier commented Jan 15, 2026

Build the sysext from Fedora RPMs and from scratch as part of the test to make this work on all releases and independently of the unofficial sysext project.

Only test on x86_64 & aarch64 for now.


Fixes: coreos/fedora-coreos-tracker#1940

Build the sysext from Fedora RPMs and from scratch as part of the test
to make this work on all releases and independently of the unofficial
sysext project.

Only test on x86_64 & aarch64 for now.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request reworks the systemd sysext test to build the extension from RPMs locally, rather than downloading pre-built ones. This is a great improvement for test reliability and independence. My review includes several suggestions to enhance the robustness, security, and efficiency of the new build script. Key areas for improvement include proper temporary directory management, safer package repository handling, correct version sorting, and more robust file operations.

dnf download --resolve --arch=noarch --arch="$(arch)" "${rpm}"

# Figure out version to use
pkg="$(ls ${rpm}-*.rpm | sort -h | head -1)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The sort -h command is for sorting human-readable numbers (e.g., 2K, 1G), not version strings. For correct version sorting, you should use sort -V. To get the latest version, you should select the last item after sorting, not the first. Using ls -1 is also recommended in scripts to ensure one file per line.

Suggested change
pkg="$(ls ${rpm}-*.rpm | sort -h | head -1)"
pkg="$(ls -1 ${rpm}-*.rpm | sort -V | tail -n 1)"

Comment on lines +25 to +26
tmpdir="/tmp/sysext-${rpm}"
mkdir "${tmpdir}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a fixed temporary directory name can lead to conflicts and is a security risk. It's better to use mktemp -d to create a unique and secure temporary directory.

Suggested change
tmpdir="/tmp/sysext-${rpm}"
mkdir "${tmpdir}"
tmpdir=$(mktemp -d "/tmp/sysext-${rpm}.XXXXXX")

Comment on lines +34 to +35
rm -rf /etc/yum.repos.d/fedora-cisco-openh264.repo
dnf download --resolve --arch=noarch --arch="$(arch)" "${rpm}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Removing the repository file is a destructive action that modifies system state. A safer approach is to temporarily disable the repository for the dnf command using the --disablerepo flag.

Suggested change
rm -rf /etc/yum.repos.d/fedora-cisco-openh264.repo
dnf download --resolve --arch=noarch --arch="$(arch)" "${rpm}"
dnf download --resolve --arch=noarch --arch="$(arch)" --disablerepo=fedora-cisco-openh264 "${rpm}"

mkfs.erofs -zlz4 "${name}" rootfs
mv "${name}" /tmp

popd > /dev/null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The temporary directory created for the build is not removed, which will leave files in /tmp. It's important to clean up this directory after it's no longer needed.

Suggested change
popd > /dev/null
popd > /dev/null
rm -rf "${tmpdir}"

Comment on lines +106 to +107
mv "/tmp/${name}"*".raw" "/var/lib/extensions.d"
ln -snf "/var/lib/extensions.d/${name}"*".raw" "/var/lib/extensions/${name}.raw"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using globs (*) with mv and ln can be risky. If the glob expands to zero, or more than one file, these commands can fail or have unintended consequences. It's safer to verify that the glob matches exactly one file before proceeding.

For example:

local files=(/path/to/"${name}"*.raw)
if [ "${#files[@]}" -ne 1 ]; then
    fatal "Expected 1 file, found ${#files[@]}"
fi
# Now use "${files[0]}"
safely

Please apply this pattern to both the mv and ln commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a test for systemd system extensions (sysexts)

1 participant