summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurentiu Palcu <laurentiu.palcu@intel.com>2018-07-23 17:41:03 +0100
committerRoss Burton <ross.burton@intel.com>2018-07-23 18:05:37 +0100
commitf6913cae59a52823dc2c143b526d5080e61dd64d (patch)
tree760fa7fd133c46b4708c02556896830868e3d191
parent8a72dd75db9949f3175600f101e4bc1ffac076de (diff)
downloadupdate-rc.d-f6913cae59a52823dc2c143b526d5080e61dd64d.tar.gz
update-rc.d-f6913cae59a52823dc2c143b526d5080e61dd64d.tar.bz2
update-rc.d-f6913cae59a52823dc2c143b526d5080e61dd64d.zip
Check if symlinks are valid
When using root option and $initd/$bn is a symlink, the script would fail because the symlink points to a path on target. For example: /path/to/target/rootfs/etc/init.d/syslog -> /etc/init.d/syslog.busybox Hence, [ -f /path/to/target/rootfs/etc/init.d/syslog ] condition would return false. This patch adds the posibility to check whether the file the symlink points to actually exists in rootfs path and then continue.
-rw-r--r--update-rc.d25
1 files changed, 23 insertions, 2 deletions
diff --git a/update-rc.d b/update-rc.d
index 5e32902..976b4cb 100644
--- a/update-rc.d
+++ b/update-rc.d
@@ -147,13 +147,34 @@ fi
bn=$1
shift
+sn=$initd/$bn
+if [ -L "$sn" -a -n "$root" ]; then
+ if which readlink >/dev/null; then
+ while true; do
+ linksn="$(readlink "$sn")"
+ if [ -z "$linksn" ]; then
+ break
+ fi
+
+ sn="$linksn"
+ case "$sn" in
+ /*) sn="$root$sn" ;;
+ *) sn="$initd/$sn" ;;
+ esac
+ done
+ else
+ echo "update-rc.d: readlink tool not present, cannot check whether \
+ $sn symlink points to a valid file." >&2
+ fi
+fi
+
if [ $1 != "remove" ]; then
- if [ ! -f "$initd/$bn" ]; then
+ if [ ! -f "$sn" ]; then
echo "update-rc.d: $initd/$bn: file does not exist" >&2
exit 1
fi
else
- if [ -f "$initd/$bn" ]; then
+ if [ -f "$sn" ]; then
if [ $force -eq 1 ]; then
echo "update-rc.d: $initd/$bn exists during rc.d purge (continuing)" >&2
else