summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorpixdamix@gmail.com <pixdamix@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2012-11-22 07:24:42 (EST)
committer pixdamix@gmail.com <pixdamix@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2012-11-22 07:24:42 (EST)
commit6b576f0d9b00f78a60f4994b663fd8ce43b9f6da (patch)
tree675af5651717547cdd513f4270a0229d701e0e4c /utils
parent5077685e6433d5609b9b82100e4dd18910d6affd (diff)
update-alternatives: use 'ln -n'
Using the '-n' option (--no-dereference) is a better way to solve the do-not-link-into-directory issue. Using only 'ln -sf' can cause problems on SELinux enabled hosts when target is inaccessible; e.g. when preparing an offline rootsystem: | $ cd <offline root> | $ ln -sf /lib/systemd/systemd sbin/init # alternative #1 | $ ln -sf /bin/busybox sbin/init # alternative #2 | ln: accessing `sbin/init': Permission denied | | --> strace: | brk(0) = 0x102b000 | stat("sbin/init", 0x7fffaa91c900) = -1 EACCES (Permission denied) | ... | exit_group(1) = ? Now with '-n': | $ ln -snf /bin/busybox sbin/init | lstat("sbin/init", {st_mode=S_IFLNK|0777, st_size=20, ...}) = 0 | lstat("sbin/init", {st_mode=S_IFLNK|0777, st_size=20, ...}) = 0 | stat("/bin/busybox", 0x7fff8c1a3bd0) = -1 ENOENT (No such file or directory) | symlink("/bin/busybox", "sbin/init") = -1 EEXIST (File exists) | unlink("sbin/init") = 0 | symlink("/bin/busybox", "sbin/init") = 0 The '-n' flag is well supported (coreutils have it at least since 1999, busybox at least since 0.60.3 (2002)) and it obsoletes the explicit check whether target is a directory. Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> git-svn-id: http://opkg.googlecode.com/svn/trunk@649 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'utils')
-rw-r--r--utils/update-alternatives.in9
1 files changed, 1 insertions, 8 deletions
diff --git a/utils/update-alternatives.in b/utils/update-alternatives.in
index 34d89f1..2a6f6cc 100644
--- a/utils/update-alternatives.in
+++ b/utils/update-alternatives.in
@@ -113,14 +113,7 @@ find_best_alt() {
if [ ! -d $link_dir ]; then
mkdir -p $link_dir
fi
- if [ -h $link -a -d $link ]; then
- # If $link exists and the target is a directory,
- # 'ln -sf $path $link' doesn't replace the link to
- # that directory, it creates new link inside.
- echo "update-alternatives: Removing $link".
- rm -f $link
- fi
- ln -sf $path $link
+ ln -snf $path $link
echo "update-alternatives: Linking $link to $path"
else
echo "update-alternatives: Error: not linking $link to $path since $link exists and is not a link"