From af3c70fb4082c62dba7aacb1dbeb014995dabb4d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 17 Sep 2024 11:41:49 +0200 Subject: [PATCH] /org.osbuild.systemd.unit*: Don't use interpolation with ConfigParser Its not uncommon for systemd unit key values to contain things like "%t", as these are magic values expanded by systemd. We need to disable the ConfigParser default interpolation that treats '%' as meaning interpolation. Otherwise you will get errors like: ``` File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 66, in r = main(args["tree"], args["options"]) File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 46, in main config.set(section, option, str(value)) File "/usr/lib64/python3.9/configparser.py", line 1204, in set super().set(section, option, value) File "/usr/lib64/python3.9/configparser.py", line 894, in set value = self._interpolation.before_set(self, section, option, File "/usr/lib64/python3.9/configparser.py", line 402, in before_set raise ValueError("invalid interpolation syntax in %r at " ValueError: invalid interpolation syntax in '%t/asil-ipc-demo/asil_ipc.socket' at position 0 ``` --- stages/org.osbuild.systemd.unit | 2 +- stages/org.osbuild.systemd.unit.create | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stages/org.osbuild.systemd.unit b/stages/org.osbuild.systemd.unit index 354c664e..c4512a7a 100755 --- a/stages/org.osbuild.systemd.unit +++ b/stages/org.osbuild.systemd.unit @@ -24,7 +24,7 @@ def main(tree, options): # We trick configparser into letting us write multiple instances of the same option by writing them as keys with no # value, so we enable allow_no_value - config = configparser.ConfigParser(allow_no_value=True) + config = configparser.ConfigParser(allow_no_value=True, interpolation=None) # prevent conversion of the option name to lowercase config.optionxform = lambda option: option diff --git a/stages/org.osbuild.systemd.unit.create b/stages/org.osbuild.systemd.unit.create index 2a027f3c..625f62b8 100755 --- a/stages/org.osbuild.systemd.unit.create +++ b/stages/org.osbuild.systemd.unit.create @@ -28,7 +28,7 @@ def main(tree, options): # We trick configparser into letting us write multiple instances of the same option by writing them as keys with no # value, so we enable allow_no_value - config = configparser.ConfigParser(allow_no_value=True) + config = configparser.ConfigParser(allow_no_value=True, interpolation=None) # prevent conversion of the option name to lowercase config.optionxform = lambda option: option