diff options
| author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-05-10 11:43:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-10 11:43:40 -0400 |
| commit | fbc128ee93553d7f9fa9f665d6a3fe5b0b596e63 (patch) | |
| tree | 74fb3dde23d26d19e676ebbf639d8b26ebf747a4 /pkg/systemd/generate/common.go | |
| parent | 446e5b300611ce576d5d3980fbf57fe3653b04a1 (diff) | |
| parent | 77e6ae24369e6c7bed85141ae6f7d0c7b0e26c0b (diff) | |
| download | podman-fbc128ee93553d7f9fa9f665d6a3fe5b0b596e63.tar.gz podman-fbc128ee93553d7f9fa9f665d6a3fe5b0b596e63.tar.bz2 podman-fbc128ee93553d7f9fa9f665d6a3fe5b0b596e63.zip | |
Merge pull request #10236 from Luap99/generate-systemd-env
Add envars to the generated systemd unit
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 |
