diff options
author | Paul Holzinger <paul.holzinger@web.de> | 2021-05-05 22:51:23 +0200 |
---|---|---|
committer | Paul Holzinger <paul.holzinger@web.de> | 2021-05-10 12:01:24 +0200 |
commit | 77e6ae24369e6c7bed85141ae6f7d0c7b0e26c0b (patch) | |
tree | 99c84def2231d9baad798e298fdf79feba0b7c49 /pkg/systemd/generate/common.go | |
parent | 54bed1025d07bc5f77ee4e1e7f942157e211ec0a (diff) | |
download | podman-77e6ae24369e6c7bed85141ae6f7d0c7b0e26c0b.tar.gz podman-77e6ae24369e6c7bed85141ae6f7d0c7b0e26c0b.tar.bz2 podman-77e6ae24369e6c7bed85141ae6f7d0c7b0e26c0b.zip |
Add envars to the generated systemd unit
The with --new generated systemd unit loses the environment variables
when the create command only contains the key without the value. Since
podman tries to lookup those values from the environment the unit can
fail.
This commits ensures that we will add the environment variables to the
unit file when this is the case. The container environment variables are
looked up in the container spec.
Fixes #10101
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'pkg/systemd/generate/common.go')
-rw-r--r-- | pkg/systemd/generate/common.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go index eafd45528..0f667e2f4 100644 --- a/pkg/systemd/generate/common.go +++ b/pkg/systemd/generate/common.go @@ -89,19 +89,24 @@ func filterCommonContainerFlags(command []string, argCount int) []string { // see: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines func escapeSystemdArguments(command []string) []string { for i := range command { - command[i] = strings.ReplaceAll(command[i], "$", "$$") - command[i] = strings.ReplaceAll(command[i], "%", "%%") - if strings.ContainsAny(command[i], " \t") { - command[i] = strconv.Quote(command[i]) - } else if strings.Contains(command[i], `\`) { - // strconv.Quote also escapes backslashes so - // we should replace only if strconv.Quote was not used - command[i] = strings.ReplaceAll(command[i], `\`, `\\`) - } + command[i] = escapeSystemdArg(command[i]) } return command } +func escapeSystemdArg(arg string) string { + arg = strings.ReplaceAll(arg, "$", "$$") + arg = strings.ReplaceAll(arg, "%", "%%") + if strings.ContainsAny(arg, " \t") { + arg = strconv.Quote(arg) + } else if strings.Contains(arg, `\`) { + // strconv.Quote also escapes backslashes so + // we should replace only if strconv.Quote was not used + arg = strings.ReplaceAll(arg, `\`, `\\`) + } + return arg +} + func removeDetachArg(args []string, argCount int) []string { // "--detach=false" could also be in the container entrypoint // split them off so we do not remove it there |