Skip to content

Commit

Permalink
Merge pull request #12545 from vrothberg/fix-12477
Browse files Browse the repository at this point in the history
generate systemd: support entrypoint JSON strings
  • Loading branch information
openshift-merge-robot authored Dec 9, 2021
2 parents 02eaebd + 2d517b6 commit 4a52a45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/systemd/generate/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func escapeSystemdArguments(command []string) []string {
func escapeSystemdArg(arg string) string {
arg = strings.ReplaceAll(arg, "$", "$$")
arg = strings.ReplaceAll(arg, "%", "%%")
if strings.ContainsAny(arg, " \t") {
if strings.ContainsAny(arg, " \t\"") {
arg = strconv.Quote(arg)
} else if strings.Contains(arg, `\`) {
// strconv.Quote also escapes backslashes so
Expand Down
18 changes: 17 additions & 1 deletion pkg/systemd/generate/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestEscapeSystemdArguments(t *testing.T) {
}{
{
[]string{"foo", "bar=\"arg\""},
[]string{"foo", "bar=\"arg\""},
[]string{"foo", "\"bar=\\\"arg\\\"\""},
},
{
[]string{"foo", "bar=\"arg with space\""},
Expand Down Expand Up @@ -192,6 +192,22 @@ func TestEscapeSystemdArguments(t *testing.T) {
[]string{"foo", `command with two backslashes \\`},
[]string{"foo", `"command with two backslashes \\\\"`},
},
{
[]string{"podman", "create", "--entrypoint", "foo"},
[]string{"podman", "create", "--entrypoint", "foo"},
},
{
[]string{"podman", "create", "--entrypoint=foo"},
[]string{"podman", "create", "--entrypoint=foo"},
},
{
[]string{"podman", "create", "--entrypoint", "[\"foo\"]"},
[]string{"podman", "create", "--entrypoint", "\"[\\\"foo\\\"]\""},
},
{
[]string{"podman", "create", "--entrypoint", "[\"sh\", \"-c\", \"date '+%s'\"]"},
[]string{"podman", "create", "--entrypoint", "\"[\\\"sh\\\", \\\"-c\\\", \\\"date '+%%s'\\\"]\""},
},
}

for _, test := range tests {
Expand Down
3 changes: 2 additions & 1 deletion test/system/250-systemd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ function service_cleanup() {
}

@test "podman autoupdate local" {
# Note that the entrypoint may be a JSON string which requires preserving the quotes (see #12477)
cname=$(random_string)
run_podman create --name $cname --label "io.containers.autoupdate=local" $IMAGE top
run_podman create --name $cname --label "io.containers.autoupdate=local" --entrypoint '["top"]' $IMAGE

# Start systemd service to run this container
service_setup
Expand Down

0 comments on commit 4a52a45

Please sign in to comment.