Gentoo Archives: gentoo-commits

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/eselect:master commit in: /, modules/
Date: Sat, 06 May 2017 13:24:21
Message-Id: 1494075898.5fd090827d2f4464245bbd454371c040358d6b1d.ulm@gentoo
1 commit: 5fd090827d2f4464245bbd454371c040358d6b1d
2 Author: Ulrich Müller <ulm <AT> gentoo <DOT> org>
3 AuthorDate: Sat May 6 13:04:58 2017 +0000
4 Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
5 CommitDate: Sat May 6 13:04:58 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/eselect.git/commit/?id=5fd09082
7
8 Improved error checking in kernel module.
9
10 * modules/kernel.eselect (do_set): Don't remove the old symlink
11 before we know that we have a valid new target. Simplify.
12 (set_symlink): Check if the new link target is valid, then remove
13 any old symlink, then set the new one.
14 (remove_symlink): Use rm -f.
15
16 ChangeLog | 6 ++++++
17 modules/kernel.eselect | 32 ++++++++++++++++----------------
18 2 files changed, 22 insertions(+), 16 deletions(-)
19
20 diff --git a/ChangeLog b/ChangeLog
21 index 2b356bd..6deef3a 100644
22 --- a/ChangeLog
23 +++ b/ChangeLog
24 @@ -1,5 +1,11 @@
25 2017-05-06 Ulrich Müller <ulm@g.o>
26
27 + * modules/kernel.eselect (do_set): Don't remove the old symlink
28 + before we know that we have a valid new target. Simplify.
29 + (set_symlink): Check if the new link target is valid, then remove
30 + any old symlink, then set the new one.
31 + (remove_symlink): Use rm -f.
32 +
33 * modules/kernel.eselect (set_symlink):
34 * modules/profile.eselect (set_symlink): Check range of number,
35 bug 617572. Thanks to Takuto Yoshida <otakuto.gentoo@×××××.com>.
36
37 diff --git a/modules/kernel.eselect b/modules/kernel.eselect
38 index e76c143..57b9b7e 100644
39 --- a/modules/kernel.eselect
40 +++ b/modules/kernel.eselect
41 @@ -35,7 +35,7 @@ find_targets() {
42
43 # remove the kernel symlink
44 remove_symlink() {
45 - rm "${EROOT}/usr/src/linux"
46 + rm -f "${EROOT}/usr/src/linux"
47 }
48
49 # set the kernel symlink
50 @@ -49,15 +49,19 @@ set_symlink() {
51 target=${targets[target-1]}
52 fi
53
54 - if [[ -z ${target} ]]; then
55 - die -q "Target \"$1\" doesn't appear to be valid!"
56 - elif [[ -f ${EROOT}/usr/src/${target}/Makefile ]]; then
57 - ln -s "${target}" "${EROOT}/usr/src/linux"
58 - elif [[ -f ${EROOT}/usr/src/linux-${target}/Makefile ]]; then
59 - ln -s "linux-${target}" "${EROOT}/usr/src/linux"
60 - else
61 - die -q "Target \"$1\" doesn't appear to be valid!"
62 + if [[ -n ${target} ]]; then
63 + if [[ -f ${EROOT}/usr/src/${target}/Makefile ]]; then
64 + :
65 + elif [[ -f ${EROOT}/usr/src/linux-${target}/Makefile ]]; then
66 + target=linux-${target}
67 + else # target not valid
68 + target=
69 + fi
70 fi
71 + [[ -n ${target} ]] || die -q "Target \"$1\" doesn't appear to be valid!"
72 +
73 + remove_symlink || die -q "Couldn't remove existing symlink"
74 + ln -s "${target}" "${EROOT}/usr/src/linux"
75 }
76
77 ### show action ###
78 @@ -114,14 +118,10 @@ do_set() {
79 [[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
80 [[ $# -gt 1 ]] && die -q "Too many parameters"
81
82 - if [[ -L ${EROOT}/usr/src/linux ]]; then
83 - # existing symlink
84 - remove_symlink || die -q "Couldn't remove existing symlink"
85 - set_symlink "$1" || die -q "Couldn't set a new symlink"
86 - elif [[ -e ${EROOT}/usr/src/linux ]]; then
87 + if [[ -e ${EROOT}/usr/src/linux && ! -L ${EROOT}/usr/src/linux ]]; then
88 # we have something strange
89 die -q "${EROOT}/usr/src/linux exists but is not a symlink"
90 - else
91 - set_symlink "$1" || die -q "Couldn't set a new symlink"
92 fi
93 +
94 + set_symlink "$1" || die -q "Couldn't set a new symlink"
95 }