[OE-core] [PATCH 2/2] systemctl-native: explicitly check target validity

Martin Kelly mkelly at xevo.com
Mon Oct 16 16:31:43 UTC 2017


Currently, we parse systemd service files looking for valid WantedBy and
RequiredBy lines. However, invalid lines get silently rejected, causing recipes
to build correctly but then not get enabled in the rootfs.

Add explicit checks for validity and print a message when an invalid target is
found so that the user can fix these issues.

Signed-off-by: Martin Kelly <mkelly at xevo.com>
---
 .../systemd/systemd-systemctl/systemctl            | 37 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 6e5a1b7181..3bed407d9e 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -1,4 +1,24 @@
 #!/bin/sh
+
+check_target_validity() {
+    local line_reg="$1"
+    local service_file="$2"
+    local unit_types_re="$3"
+
+    local line="$(sed $line_reg "$service_file")"
+    if [ -z "$line" ]; then
+        # Line was not found; there's nothing to check.
+        return
+    fi
+
+    if ! echo $line | grep -q $unit_types_re; then
+        echo "One or more of the target types in the service were not recognized as valid."
+        echo "Service: $service_file"
+        echo "Targets: $line"
+        exit 1
+    fi
+}
+
 echo "Started $0 $*"
 
 ROOT=
@@ -120,15 +140,18 @@ for service in $services; do
 			fi
 		fi
 	fi
-	# create the required symbolic links
-	wanted_by=$(sed '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
-		        | tr ',' '\n' \
-		        | grep "$unit_types_re")
 
-	required_by=$(sed '/^RequiredBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
-		        | tr ',' '\n' \
-		        | grep "$unit_types_re")
+    check_target_validity \
+        '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' \
+        "$ROOT/$service_file" \
+        "$unit_types_re"
 
+    check_target_validity \
+        '/^RequiredBy[[:space:]]*=/s,[^=]*=,,p;d' \
+        "$ROOT/$service_file" \
+        "$unit_types_re"
+
+	# create the required symbolic links
 	for dependency in WantedBy RequiredBy; do
 		if [ "$dependency" = "WantedBy" ]; then
 			suffix="wants"
-- 
2.11.0




More information about the Openembedded-core mailing list