podman

Форк
0
/
run_signal_test.go 
117 строк · 3.3 Кб
1
package integration
2

3
import (
4
	"fmt"
5
	"io"
6
	"os"
7
	"path/filepath"
8
	"strings"
9
	"syscall"
10
	"time"
11

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"
16
)
17

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"
20

21
var _ = Describe("Podman run with --sig-proxy", func() {
22

23
	Specify("signals are forwarded to container using sig-proxy", func() {
24
		if podmanTest.Host.Arch == "ppc64le" {
25
			Skip("Doesn't work on ppc64le")
26
		}
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())
35
		if isRootless() {
36
			err = podmanTest.RestoreArtifact(fedoraMinimal)
37
			Expect(err).ToNot(HaveOccurred())
38
		}
39
		_, pid := podmanTest.PodmanPID([]string{"run", "-v", fmt.Sprintf("%s:/h:Z", udsDir), fedoraMinimal, "bash", "-c", sigCatch})
40

41
		uds, _ := os.OpenFile(udsPath, os.O_RDONLY|syscall.O_NONBLOCK, 0600)
42
		defer uds.Close()
43

44
		// Wait for the script in the container to alert us that it is READY
45
		counter := 0
46
		for {
47
			buf := make([]byte, 1024)
48
			n, err := uds.Read(buf)
49
			if err != nil && err != io.EOF {
50
				GinkgoWriter.Println(err)
51
				return
52
			}
53
			data := string(buf[0:n])
54
			if strings.Contains(data, "READY") {
55
				break
56
			}
57
			time.Sleep(1 * time.Second)
58
			if counter == 15 {
59
				Fail("Timed out waiting for READY from container")
60
			}
61
			counter++
62
		}
63
		// Ok, container is up and running now and so is the script
64

65
		if err := unix.Kill(pid, signal); err != nil {
66
			Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
67
		}
68

69
		// The sending of the signal above will send FOO to the socket; here we
70
		// listen to the socket for that.
71
		counter = 0
72
		for {
73
			buf := make([]byte, 1024)
74
			n, err := uds.Read(buf)
75
			if err != nil {
76
				GinkgoWriter.Println(err)
77
				return
78
			}
79
			data := string(buf[0:n])
80
			if strings.Contains(data, "FOO") {
81
				break
82
			}
83
			time.Sleep(1 * time.Second)
84
			if counter == 15 {
85
				Fail("timed out waiting for FOO from container")
86
			}
87
			counter++
88
		}
89
	})
90

91
	Specify("signals are not forwarded to container with sig-proxy false", func() {
92
		signal := syscall.SIGFPE
93
		if isRootless() {
94
			err = podmanTest.RestoreArtifact(fedoraMinimal)
95
			Expect(err).ToNot(HaveOccurred())
96
		}
97
		session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch2})
98

99
		Expect(WaitForContainer(podmanTest)).To(BeTrue(), "WaitForContainer()")
100

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))
105
		}
106

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())
111

112
		session.WaitWithDefaultTimeout()
113
		Expect(session).To(ExitWithError())
114
		Expect(session.OutputToString()).To(Not(ContainSubstring("Received")))
115
	})
116

117
})
118

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.