summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/update-rc.d/update-rc.d/check-if-symlinks-are-valid.patch
blob: 075171a5a38cc40018d466f71f9205b9f8894f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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.

Upstream-Status: Pending

Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com> 
Signed-off-by: Christopher Larson <chris_larson@mentor.com>

Index: git/update-rc.d
===================================================================
--- git.orig/update-rc.d
+++ git/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