Skip to content

Commit

Permalink
Set systemd mode if entrypoint begins with /bin/sh -c
Browse files Browse the repository at this point in the history
Fixes: containers#13324

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Mar 30, 2022
1 parent b362367 commit a4203bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,16 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
"/usr/sbin/init": true,
"/usr/local/sbin/init": true,
}
if useSystemdCommands[command[0]] || (filepath.Base(command[0]) == "systemd") {
// Grab last command incase this is launched from a shell
cmd := command
if len(command) > 2 {
// Podman build will add "/bin/sh" "-c" to
// Entrypoint. Remove and search for systemd
if command[0] == "/bin/sh" && command[1] == "-c" {
cmd = command[2:]
}
}
if useSystemdCommands[cmd[0]] || (filepath.Base(cmd[0]) == "systemd") {
useSystemd = true
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/systemd_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package integration

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

. "github.com/containers/podman/v4/test/utils"
Expand Down Expand Up @@ -130,6 +132,31 @@ WantedBy=default.target
Expect(conData[0].Config.SystemdMode).To(BeTrue())
})

It("podman systemd in command triggers systemd mode", func() {
containerfile := fmt.Sprintf(`FROM %s
RUN mkdir -p /usr/lib/systemd/; touch /usr/lib/systemd/systemd
CMD /usr/lib/systemd/systemd`, ALPINE)

containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile")
err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "-t", "systemd", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

ctrName := "testCtr"
run := podmanTest.Podman([]string{"create", "--name", ctrName, "systemd"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(0))

result := podmanTest.Podman([]string{"inspect", ctrName})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
conData := result.InspectContainerToJSON()
Expect(conData).To(HaveLen(1))
Expect(conData[0].Config.SystemdMode).To(BeTrue())
})

It("podman create container with --uidmap and conmon PidFile accessible", func() {
ctrName := "testCtrUidMap"
run := podmanTest.Podman([]string{"run", "-d", "--uidmap=0:1:1000", "--name", ctrName, ALPINE, "top"})
Expand Down

0 comments on commit a4203bd

Please sign in to comment.