Skip to content

Commit

Permalink
/org.osbuild.systemd.unit*: Don't use interpolation with ConfigParser
Browse files Browse the repository at this point in the history
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 <module>
    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
```
  • Loading branch information
alexlarsson committed Sep 17, 2024
1 parent cc8e47f commit a2f46cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stages/org.osbuild.systemd.unit
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion stages/org.osbuild.systemd.unit.create
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a2f46cb

Please sign in to comment.