12
. "github.com/containers/podman/v5/test/utils"
13
. "github.com/onsi/ginkgo/v2"
14
. "github.com/onsi/gomega"
15
"golang.org/x/sys/unix"
18
const sigCatch = "trap \"echo FOO >> /h/fifo \" 8; echo READY >> /h/fifo; while :; do sleep 0.25; done"
19
const sigCatch2 = "trap \"echo Received\" SIGFPE; while :; do sleep 0.25; done"
21
var _ = Describe("Podman run with --sig-proxy", func() {
23
Specify("signals are forwarded to container using sig-proxy", func() {
24
if podmanTest.Host.Arch == "ppc64le" {
25
Skip("Doesn't work on ppc64le")
27
signal := syscall.SIGFPE
28
// Set up a socket for communication
29
udsDir := filepath.Join(tempdir, "socket")
30
err := os.Mkdir(udsDir, 0700)
31
Expect(err).ToNot(HaveOccurred())
32
udsPath := filepath.Join(udsDir, "fifo")
33
err = syscall.Mkfifo(udsPath, 0600)
34
Expect(err).ToNot(HaveOccurred())
36
err = podmanTest.RestoreArtifact(fedoraMinimal)
37
Expect(err).ToNot(HaveOccurred())
39
_, pid := podmanTest.PodmanPID([]string{"run", "-v", fmt.Sprintf("%s:/h:Z", udsDir), fedoraMinimal, "bash", "-c", sigCatch})
41
uds, _ := os.OpenFile(udsPath, os.O_RDONLY|syscall.O_NONBLOCK, 0600)
44
// Wait for the script in the container to alert us that it is READY
47
buf := make([]byte, 1024)
48
n, err := uds.Read(buf)
49
if err != nil && err != io.EOF {
50
GinkgoWriter.Println(err)
53
data := string(buf[0:n])
54
if strings.Contains(data, "READY") {
57
time.Sleep(1 * time.Second)
59
Fail("Timed out waiting for READY from container")
63
// Ok, container is up and running now and so is the script
65
if err := unix.Kill(pid, signal); err != nil {
66
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
69
// The sending of the signal above will send FOO to the socket; here we
70
// listen to the socket for that.
73
buf := make([]byte, 1024)
74
n, err := uds.Read(buf)
76
GinkgoWriter.Println(err)
79
data := string(buf[0:n])
80
if strings.Contains(data, "FOO") {
83
time.Sleep(1 * time.Second)
85
Fail("timed out waiting for FOO from container")
91
Specify("signals are not forwarded to container with sig-proxy false", func() {
92
signal := syscall.SIGFPE
94
err = podmanTest.RestoreArtifact(fedoraMinimal)
95
Expect(err).ToNot(HaveOccurred())
97
session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch2})
99
Expect(WaitForContainer(podmanTest)).To(BeTrue(), "WaitForContainer()")
101
// Kill with given signal
102
// Should be no output, SIGPOLL is usually ignored
103
if err := unix.Kill(pid, signal); err != nil {
104
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
107
// Kill with -9 to guarantee the container dies
108
killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test2"})
109
killSession.WaitWithDefaultTimeout()
110
Expect(killSession).Should(ExitCleanly())
112
session.WaitWithDefaultTimeout()
113
Expect(session).To(ExitWithError())
114
Expect(session.OutputToString()).To(Not(ContainSubstring("Received")))