summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/common.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-08-01 11:34:17 +0200
committerGitHub <noreply@github.com>2022-08-01 11:34:17 +0200
commit271a9f45a462c652d4f025f583fc3bd204d95656 (patch)
treeb5a3b70333378b1893b14101f5740f9469845d6b /pkg/systemd/generate/common.go
parentf5f7909932dc314612539dabf8682b17c6e20970 (diff)
parent6a9338ad6cb6c6c65fae7786b35636f260389ea9 (diff)
downloadpodman-271a9f45a462c652d4f025f583fc3bd204d95656.tar.gz
podman-271a9f45a462c652d4f025f583fc3bd204d95656.tar.bz2
podman-271a9f45a462c652d4f025f583fc3bd204d95656.zip
Merge pull request #15056 from Luap99/generate-systemd-sdnotify
podman generate systemd: handle --sdnotify correctly
Diffstat (limited to 'pkg/systemd/generate/common.go')
-rw-r--r--pkg/systemd/generate/common.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go
index 60b0c4b52..b0a441d54 100644
--- a/pkg/systemd/generate/common.go
+++ b/pkg/systemd/generate/common.go
@@ -42,7 +42,7 @@ RequiresMountsFor={{{{.RunRoot}}}}
// filterPodFlags removes --pod, --pod-id-file and --infra-conmon-pidfile from the specified command.
// argCount is the number of last arguments which should not be filtered, e.g. the container entrypoint.
func filterPodFlags(command []string, argCount int) []string {
- processed := []string{}
+ processed := make([]string, 0, len(command))
for i := 0; i < len(command)-argCount; i++ {
s := command[i]
if s == "--pod" || s == "--pod-id-file" || s == "--infra-conmon-pidfile" {
@@ -63,7 +63,7 @@ func filterPodFlags(command []string, argCount int) []string {
// filterCommonContainerFlags removes --sdnotify, --rm and --cgroups from the specified command.
// argCount is the number of last arguments which should not be filtered, e.g. the container entrypoint.
func filterCommonContainerFlags(command []string, argCount int) []string {
- processed := []string{}
+ processed := make([]string, 0, len(command))
for i := 0; i < len(command)-argCount; i++ {
s := command[i]
@@ -71,7 +71,7 @@ func filterCommonContainerFlags(command []string, argCount int) []string {
case s == "--rm":
// Boolean flags support --flag and --flag={true,false}.
continue
- case s == "--sdnotify", s == "--cgroups", s == "--cidfile", s == "--restart":
+ case s == "--cgroups", s == "--cidfile", s == "--restart":
i++
continue
case strings.HasPrefix(s, "--rm="),
@@ -111,6 +111,24 @@ func escapeSystemdArg(arg string) string {
return arg
}
+func removeSdNotifyArg(args []string, argCount int) []string {
+ processed := make([]string, 0, len(args))
+ for i := 0; i < len(args)-argCount; i++ {
+ s := args[i]
+
+ switch {
+ case s == "--sdnotify":
+ i++
+ continue
+ case strings.HasPrefix(s, "--sdnotify="):
+ continue
+ }
+ processed = append(processed, s)
+ }
+ processed = append(processed, args[len(args)-argCount:]...)
+ return processed
+}
+
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