Patchwork systemd-systemctl: parse unit files more correctly

login
register
mail settings
Submitter Enrico Scholz
Date April 24, 2013, 11:37 a.m.
Message ID <1366803441-18633-1-git-send-email-enrico.scholz@sigma-chemnitz.de>
Download mbox | patch
Permalink /patch/48727/
State Accepted
Commit 443e75ee2c0e9a62df997aef24855bce54d39177
Headers show

Comments

Enrico Scholz - April 24, 2013, 11:37 a.m.
Old script failed to parse unit files containing comments like

| #Alias=some-alias

or whitespaces like

| WantedBy = foo

correctly.  Patch changes script to interpret keywords only when they
are at the beginning of a line and ignores whitespaces before the '='.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
---
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
Ross Burton - April 24, 2013, 11:53 a.m.
On 24 April 2013 12:37, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
> Old script failed to parse unit files containing comments like
>
> | #Alias=some-alias
>
> or whitespaces like
>
> | WantedBy = foo
>
> correctly.  Patch changes script to interpret keywords only when they
> are at the beginning of a line and ignores whitespaces before the '='.
>
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>

Acked-by: Ross Burton <ross.burton@intel.com>

CC'ing Paul so this ends up in the Dylan branch too.

Ross

Patch

diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index d71c7ed..8abbdf6 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -78,8 +78,7 @@  for service in $services; do
 	echo "Found $service in $service_file"
 
 	# create the required symbolic links
-	wanted_by=$(grep WantedBy $ROOT/$service_file \
-		        | sed 's,WantedBy=,,g' \
+	wanted_by=$(sed '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
 		        | tr ',' '\n' \
 		        | grep '\(\.target$\)\|\(\.service$\)')
 
@@ -97,8 +96,7 @@  for service in $services; do
 	done
 
 	# create the required symbolic 'Alias' links
-	alias=$(grep Alias $ROOT/$service_file \
-		        | sed 's,Alias=,,g' \
+	alias=$(sed '/^Alias[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
 		        | tr ',' '\n' \
 		        | grep '\.service$')
 
@@ -114,8 +112,7 @@  for service in $services; do
 	done
 
 	# call us for the other required scripts
-	also=$(grep Also $ROOT/$service_file \
-		   | sed 's,Also=,,g' \
+	also=$(sed '/^Also[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
 		   | tr ',' '\n')
 	for a in $also; do
 		echo "Also=$a found in $service"