Skip to content

Commit

Permalink
Add 'broken' status
Browse files Browse the repository at this point in the history
If either a dkms module source, or the symbolic link pointing to
it is missing, the output of `dkms status` will be messed up.
Add a new status called 'broken', which will inform the user
about it in a nicely formatted way.
is_module_added() was modified to not report a module as added,
if not both the source directory and the 'source' symlink exist.
do_autoinstall() and run_match() were modified to handle a broken
status. They skip that particular module/version combo and continue
iterating.
The new function module_is_broken_and_die() was introduced to die
early on a broken module.
Because if in a broken state everything has to be considered volatile,
we always die. User intvervention is required to restore a healthy
environment.
The man page was updated with the new 'broken' status.

Signed-off-by: Mart Frauenlob <[email protected]>
  • Loading branch information
AllKind committed Dec 8, 2023
1 parent 377d531 commit e4af22f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Binary file added .dkms.in.swp
Binary file not shown.
5 changes: 5 additions & 0 deletions dkms.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ Returns the current status of modules, versions and kernels within
the tree as well as whether they have been added, built or installed.
Status can be shown for just a certain module, a certain kernel,
a module/version combination or a module/version/kernel combination.

If the source directory, or the symbolic link 'source' pointing to it is missing,
the status of the module/version combination will be displayed as 'broken'.
In that case dkms will not perform any other action on that particular module/version combination.
Manual intervention is required.
.SY autoinstall
.YS
.IP "" 4
Expand Down
55 changes: 54 additions & 1 deletion dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,25 @@ list_each_installed_module()
done
}

# Check if either the module source, or the symlink pointing to it is missing
is_module_broken() {
[[ $1 && $2 ]] || return 1
[[ -d $dkms_tree/$1/$2 ]] || return 2
if [[ -L $dkms_tree/$1/$2/source && ! -d $dkms_tree/$1/$2/source ]]; then
[[ $verbose ]] && error "The source directory for $1/$2is missing."
return
elif [[ ! -L $dkms_tree/$1/$2/source && -d $dkms_tree/$1/$2/source ]]; then
[[ $verbose ]] && error "The symbolic link 'source' to the source directory of $1/$2 is missing."
return
fi
return 1

}

is_module_added() {
[[ $1 && $2 ]] || return 1
[[ -d $dkms_tree/$1/$2 ]] || return 2
[[ -L $dkms_tree/$1/$2/source || -d $dkms_tree/$1/$2/source ]];
[[ -L $dkms_tree/$1/$2/source && -d $dkms_tree/$1/$2/source ]] || return 2
}

is_module_built() {
Expand Down Expand Up @@ -1600,6 +1615,26 @@ do_uninstall()
[[ $(find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module"
}

module_is_broken_and_die() {
local rip=0
local -a msg=()
local p="$dkms_tree/$module/$module_version"

# Die here if the base directory of module/version does not exist.
# Because the module must already be added. Unlike in is_module_broken().
[[ -d $p ]] || die 3 \
$"The module/version combo: $module-$module_version is not located in the DKMS tree."

if [[ -L $p/source && ! -d $p/source ]]; then rip=1
msg+=("The source directory for $module/$module_version is missing.")
fi
if [[ ! -L $p/source && -d $p/source ]]; then rip=1
msg+=("The symbolic link 'source' to the source directory for $module/$module_version is missing.")
fi
((rip)) && die 4 "${msg[@]}" "Manual intervention is required!"
return 0
}

module_is_added_or_die()
{
is_module_added "$module" "$module_version" || die 3 \
Expand Down Expand Up @@ -1801,6 +1836,7 @@ module_status() {
mv="${directory#$dkms_tree/}"
m="${mv%/*}"
v="${mv#*/}"
is_module_broken "$m" "$v" && { echo "broken $m/$v"; continue; }
is_module_added "$m" "$v" || continue
ret=0
module_status_built "$m" "$v" "$3" "$4" || echo "added $m/$v"
Expand All @@ -1821,6 +1857,10 @@ do_status() {
while read status mvka; do
IFS=/ read m v k a <<< "$mvka"
case $status in
broken)
echo "$m/$v: $status"
error "$m/$v: Missing module source directory, or the symbolic link pointing to it."
;;
added)
echo "$m/$v: $status"
;;
Expand Down Expand Up @@ -2097,6 +2137,11 @@ run_match()
echo $"Module: $template_module"
echo $"Version: $template_version"

# Continue if the status is broken, as there is nothing we can do
if is_module_broken "$template_module" "$template_version"; then
error $"$template_module/$template_version: Missing module source directory, or the symbolic link pointing to it."
continue
fi
maybe_build_module "$template_module" "$template_version" "$kernelver" "$arch"
maybe_install_module "$template_module" "$template_version" "$kernelver" "$arch"
done < <(echo "$template_kernel_status")
Expand Down Expand Up @@ -2225,6 +2270,11 @@ autoinstall() {
# a list of modules and their latest version.
while read status mvka; do
IFS='/' read m v k a <<< "$mvka"
# If the module status is broken there is nothing that can be done
if [[ $status = broken ]]; then
error "Module $m/$v is broken. Missing source directory, or the symbolic link pointing to it."
continue
fi
if [[ -z "${latest["$m"]}" ]]; then
known_modules[${#known_modules[@]}]="$m"
latest["$m"]="$v"
Expand Down Expand Up @@ -2579,12 +2629,14 @@ setup_kernels_arches "$action"
case "$action" in
remove | unbuild | uninstall)
check_module_args $action
module_is_broken_and_die
module_is_added_or_die
[[ $action = uninstall ]] && check_root || check_rw_dkms_tree
${action}_module
;;
add | build | install)
check_all_is_banned $action # TODO: fix/enable --all
[[ $action != add ]] && module_is_broken_and_die && module_is_added_or_die
[[ $action = install ]] && check_root || check_rw_dkms_tree
${action}_module
;;
Expand All @@ -2596,6 +2648,7 @@ match)
;;
mktarball)
check_module_args mktarball
module_is_broken_and_die
module_is_added_or_die
make_tarball
;;
Expand Down

0 comments on commit e4af22f

Please sign in to comment.