Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Check if symlinks are valid |
| 2 | |
| 3 | When using root option and $initd/$bn is a symlink, the script would fail because |
| 4 | the symlink points to a path on target. For example: |
| 5 | |
| 6 | /path/to/target/rootfs/etc/init.d/syslog -> /etc/init.d/syslog.busybox |
| 7 | |
| 8 | Hence, [ -f /path/to/target/rootfs/etc/init.d/syslog ] condition would return |
| 9 | false. |
| 10 | |
| 11 | This patch adds the posibility to check whether the file the symlink points to |
| 12 | actually exists in rootfs path and then continue. |
| 13 | |
| 14 | Upstream-Status: Pending |
| 15 | |
| 16 | Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com> |
| 17 | Signed-off-by: Christopher Larson <chris_larson@mentor.com> |
| 18 | |
| 19 | Index: git/update-rc.d |
| 20 | =================================================================== |
| 21 | --- git.orig/update-rc.d |
| 22 | +++ git/update-rc.d |
| 23 | @@ -147,13 +147,34 @@ fi |
| 24 | bn=$1 |
| 25 | shift |
| 26 | |
| 27 | +sn=$initd/$bn |
| 28 | +if [ -L "$sn" -a -n "$root" ]; then |
| 29 | + if which readlink >/dev/null; then |
| 30 | + while true; do |
| 31 | + linksn="$(readlink "$sn")" |
| 32 | + if [ -z "$linksn" ]; then |
| 33 | + break |
| 34 | + fi |
| 35 | + |
| 36 | + sn="$linksn" |
| 37 | + case "$sn" in |
| 38 | + /*) sn="$root$sn" ;; |
| 39 | + *) sn="$initd/$sn" ;; |
| 40 | + esac |
| 41 | + done |
| 42 | + else |
| 43 | + echo "update-rc.d: readlink tool not present, cannot check whether \ |
| 44 | + $sn symlink points to a valid file." >&2 |
| 45 | + fi |
| 46 | +fi |
| 47 | + |
| 48 | if [ $1 != "remove" ]; then |
| 49 | - if [ ! -f "$initd/$bn" ]; then |
| 50 | + if [ ! -f "$sn" ]; then |
| 51 | echo "update-rc.d: $initd/$bn: file does not exist" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | else |
| 55 | - if [ -f "$initd/$bn" ]; then |
| 56 | + if [ -f "$sn" ]; then |
| 57 | if [ $force -eq 1 ]; then |
| 58 | echo "update-rc.d: $initd/$bn exists during rc.d purge (continuing)" >&2 |
| 59 | else |