aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2017-05-06 15:04:58 +0200
committerUlrich Müller <ulm@gentoo.org>2017-05-06 15:04:58 +0200
commit5fd090827d2f4464245bbd454371c040358d6b1d (patch)
treeb373a00df131d1171d09ca2d88edb4794e7362bd /modules/kernel.eselect
parentCheck range of number in kernel and profile modules. (diff)
downloadeselect-5fd090827d2f4464245bbd454371c040358d6b1d.tar.gz
eselect-5fd090827d2f4464245bbd454371c040358d6b1d.tar.bz2
eselect-5fd090827d2f4464245bbd454371c040358d6b1d.zip
Improved error checking in kernel module.
* modules/kernel.eselect (do_set): Don't remove the old symlink before we know that we have a valid new target. Simplify. (set_symlink): Check if the new link target is valid, then remove any old symlink, then set the new one. (remove_symlink): Use rm -f.
Diffstat (limited to 'modules/kernel.eselect')
-rw-r--r--modules/kernel.eselect32
1 files changed, 16 insertions, 16 deletions
diff --git a/modules/kernel.eselect b/modules/kernel.eselect
index e76c143..57b9b7e 100644
--- a/modules/kernel.eselect
+++ b/modules/kernel.eselect
@@ -35,7 +35,7 @@ find_targets() {
# remove the kernel symlink
remove_symlink() {
- rm "${EROOT}/usr/src/linux"
+ rm -f "${EROOT}/usr/src/linux"
}
# set the kernel symlink
@@ -49,15 +49,19 @@ set_symlink() {
target=${targets[target-1]}
fi
- if [[ -z ${target} ]]; then
- die -q "Target \"$1\" doesn't appear to be valid!"
- elif [[ -f ${EROOT}/usr/src/${target}/Makefile ]]; then
- ln -s "${target}" "${EROOT}/usr/src/linux"
- elif [[ -f ${EROOT}/usr/src/linux-${target}/Makefile ]]; then
- ln -s "linux-${target}" "${EROOT}/usr/src/linux"
- else
- die -q "Target \"$1\" doesn't appear to be valid!"
+ if [[ -n ${target} ]]; then
+ if [[ -f ${EROOT}/usr/src/${target}/Makefile ]]; then
+ :
+ elif [[ -f ${EROOT}/usr/src/linux-${target}/Makefile ]]; then
+ target=linux-${target}
+ else # target not valid
+ target=
+ fi
fi
+ [[ -n ${target} ]] || die -q "Target \"$1\" doesn't appear to be valid!"
+
+ remove_symlink || die -q "Couldn't remove existing symlink"
+ ln -s "${target}" "${EROOT}/usr/src/linux"
}
### show action ###
@@ -114,14 +118,10 @@ do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
- if [[ -L ${EROOT}/usr/src/linux ]]; then
- # existing symlink
- remove_symlink || die -q "Couldn't remove existing symlink"
- set_symlink "$1" || die -q "Couldn't set a new symlink"
- elif [[ -e ${EROOT}/usr/src/linux ]]; then
+ if [[ -e ${EROOT}/usr/src/linux && ! -L ${EROOT}/usr/src/linux ]]; then
# we have something strange
die -q "${EROOT}/usr/src/linux exists but is not a symlink"
- else
- set_symlink "$1" || die -q "Couldn't set a new symlink"
fi
+
+ set_symlink "$1" || die -q "Couldn't set a new symlink"
}