Skip to content

Conversation

@arrowd
Copy link
Contributor

@arrowd arrowd commented Jan 21, 2026

When sourcing this file it may overwrite the VERSION shell variable, which in turn end up being used for @Version@ substitutions in various .in files.

I was lucky to catch this when preparing a FreeBSD port update.
Spec reference: https://www.freedesktop.org/software/systemd/man/latest/os-release.html#VERSION=

When sourcing this file it may overwrite the VERSION shell variable, which
in turn end up being used for @Version@ substitutions in various .in files.
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

The pull request correctly identifies and fixes an issue where sourcing /etc/os-release can clobber the VERSION variable. However, the fix can be made more robust and portable. My review includes a suggestion to use a subshell to source /etc/os-release, which prevents clobbering of any shell variables, not just VERSION. This approach is cleaner and safer. Additionally, I've corrected a non-POSIX [[ test to a portable [ test, which was a pre-existing bug in this code block.

Comment on lines +21 to 26
_old_version="$VERSION"
. /etc/os-release
VERSION="$_old_version"
if ([[ "${ID}" = "suse" ]]) || ([[ "${ID_LIKE#*suse*}" != "${ID_LIKE}" ]]); then
osname="suse"
fi

Choose a reason for hiding this comment

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

high

While saving and restoring the VERSION variable works, a more robust and cleaner approach is to source /etc/os-release inside a subshell. This prevents any variables from leaking into the main script's environment, completely avoiding issues with variable clobbering (including VERSION).

Additionally, the [[ ... ]] construct is a bashism and not guaranteed to be available in all POSIX shells that configure scripts may run under. It should be replaced with the portable [ ... ] test.

This suggestion implements both improvements.

        _osname_suse=$(
            . /etc/os-release
            if [ "${ID}" = "suse" ] || [ "${ID_LIKE#*suse*}" != "${ID_LIKE}" ]; then
                echo "suse"
            fi
        )
        if [ "x$_osname_suse" = "xsuse" ]; then
            osname="suse"
        fi

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.

3 participants