summaryrefslogtreecommitdiffstats
path: root/meta/classes/systemd.bbclass
diff options
context:
space:
mode:
authorDamien Riegel <damien.riegel@savoirfairelinux.com>2018-06-22 14:43:02 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-06-27 13:55:22 +0100
commitcd928d3a985b2432d1acd085aa6d26c3d8786e65 (patch)
treea2b7aa71348dbc08995f13279dcf39330f79b1d3 /meta/classes/systemd.bbclass
parent1ad7165f7e6346c96ef60327a77ebb1a0c583114 (diff)
downloadpoky-cd928d3a985b2432d1acd085aa6d26c3d8786e65.tar.gz
systemd: escape paths passed to shell
Systemd mount configuration file must have a name that match the mount point directory they control. So for instance, if a mount file contains [Mount] ... Where=/mnt/my-data The file must be named `mnt-my\x2ddata.mount`, or systemd will refuse to honour it. If this config file contains an [Install] section, it will silently fail because the unit file is not escaped properly when systemctl is called. To fix that, make sure paths are escaped through `shlex.quote`. (From OE-Core rev: bbd9524256461f1bcafd4103edd575e668de76f8) Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/systemd.bbclass')
-rw-r--r--meta/classes/systemd.bbclass14
1 files changed, 9 insertions, 5 deletions
diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index 1b134322fb..c7b784dea8 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -34,10 +34,10 @@ if type systemctl >/dev/null 2>/dev/null; then
34 systemctl daemon-reload 34 systemctl daemon-reload
35 fi 35 fi
36 36
37 systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE} 37 systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE_ESCAPED}
38 38
39 if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then 39 if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
40 systemctl --no-block restart ${SYSTEMD_SERVICE} 40 systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
41 fi 41 fi
42fi 42fi
43} 43}
@@ -51,10 +51,10 @@ fi
51 51
52if type systemctl >/dev/null 2>/dev/null; then 52if type systemctl >/dev/null 2>/dev/null; then
53 if [ -z "$D" ]; then 53 if [ -z "$D" ]; then
54 systemctl stop ${SYSTEMD_SERVICE} 54 systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
55 fi 55 fi
56 56
57 systemctl $OPTS disable ${SYSTEMD_SERVICE} 57 systemctl $OPTS disable ${SYSTEMD_SERVICE_ESCAPED}
58fi 58fi
59} 59}
60 60
@@ -65,6 +65,7 @@ systemd_populate_packages[vardepsexclude] += "OVERRIDES"
65 65
66python systemd_populate_packages() { 66python systemd_populate_packages() {
67 import re 67 import re
68 import shlex
68 69
69 if not bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d): 70 if not bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d):
70 return 71 return
@@ -85,6 +86,9 @@ python systemd_populate_packages() {
85 def systemd_generate_package_scripts(pkg): 86 def systemd_generate_package_scripts(pkg):
86 bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg) 87 bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
87 88
89 paths_escaped = ' '.join(shlex.quote(s) for s in d.getVar('SYSTEMD_SERVICE_' + pkg, True).split())
90 d.setVar('SYSTEMD_SERVICE_ESCAPED_' + pkg, paths_escaped)
91
88 # Add pkg to the overrides so that it finds the SYSTEMD_SERVICE_pkg 92 # Add pkg to the overrides so that it finds the SYSTEMD_SERVICE_pkg
89 # variable. 93 # variable.
90 localdata = d.createCopy() 94 localdata = d.createCopy()
@@ -130,7 +134,7 @@ python systemd_populate_packages() {
130 systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys) 134 systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys)
131 for key in keys.split(): 135 for key in keys.split():
132 # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files 136 # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files
133 cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key) 137 cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, shlex.quote(fullpath), key)
134 pipe = os.popen(cmd, 'r') 138 pipe = os.popen(cmd, 'r')
135 line = pipe.readline() 139 line = pipe.readline()
136 while line: 140 while line: