Skip to content

Commit

Permalink
fix: Properly exit process if function distro_version fails
Browse files Browse the repository at this point in the history
`distro_version` contains code that can run `exit`, which is supposed to
exit the whole process. However, `distro_version` runs in a subshell.
By default in Bash, this means that `exit` will only exit the subshell, and set `?`
to that exit code. The rest of script will execute, despite the error.

There are two ways to fix this:
- Enable the POSIX shell option `errexit` for the entire script
- Manually check for non-zero exit code and "cascade the error"

The latter was chosen because it is a localized change that does not
affect the behavior of the entire script.
  • Loading branch information
hyperupcall committed Dec 2, 2023
1 parent 4834cf2 commit fbc2548
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ unset CC CXX CFLAGS CXXFLAGS LDFLAGS
# Set important variables
current_kernel=$(uname -r)
current_os=$(uname -s)
running_distribution=$(distro_version)
running_distribution=$(distro_version) || exit
dkms_tree="/var/lib/dkms"
source_tree="/usr/src"
install_tree="/lib/modules"
Expand Down

0 comments on commit fbc2548

Please sign in to comment.