Skip to content

Commit

Permalink
tests: Add new "procutils" that exposes PDEATHSIG
Browse files Browse the repository at this point in the history
To fix compilation on MacOS.

I think actually we want to use this pervasively in our tests
on Linux; it doesn't really matter when run inside a transient
container, but `PDEATHSIG` is useful for persistent containers (e.g.)
toolbox and when running outside of a pid namespace, e.g. on a host
system shell directly or in systemd.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 16, 2021
1 parent fa86297 commit e9535f8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions integration/procutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !linux
// +build !linux

package main

import (
"os/exec"
)

// cmdLifecycleToParentIfPossible tries to exit if the parent process exits (only works on Linux)
func cmdLifecycleToParentIfPossible(c *exec.Cmd) {
}
14 changes: 14 additions & 0 deletions integration/procutils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os/exec"
"syscall"
)

// cmdLifecyleToParentIfPossible is a thin wrapper around prctl(PR_SET_PDEATHSIG)
// on Linux.
func cmdLifecycleToParentIfPossible(c *exec.Cmd) {
c.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGTERM,
}
}
4 changes: 1 addition & 3 deletions integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ func newProxy() (*proxy, error) {
// Note ExtraFiles starts at 3
proc := exec.Command("skopeo", "experimental-image-proxy", "--sockfd", "3")
proc.Stderr = os.Stderr
proc.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGTERM,
}
cmdLifecycleToParentIfPossible(proc)
proc.ExtraFiles = append(proc.ExtraFiles, theirfd)

if err = proc.Start(); err != nil {
Expand Down

0 comments on commit e9535f8

Please sign in to comment.