Skip to content

Commit

Permalink
Apply review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
spikat committed Mar 5, 2025
1 parent 340c6db commit ec6366b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
20 changes: 11 additions & 9 deletions pkg/security/ptracer/ptracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,17 +541,19 @@ func (ctx *CWSPtracerCtx) AttachTracer() error {
return nil
}

var forwardedSignals = []os.Signal{
// Signal, number, and possible cause of container runtime sending them
syscall.SIGHUP, // 1 - Reload configuration (useful for reloading services inside a container)
syscall.SIGINT, // 2 - Graceful shutdown (sent when stopping container interactively)
syscall.SIGQUIT, // 3 - Graceful shutdown + core dump (used for debugging containerized apps)
syscall.SIGUSR1, // 10 - Application-specific user-defined signal (can trigger app reloads)
syscall.SIGUSR2, // 12 - Another user-defined signal, often used for hot reloads inside a container
syscall.SIGTERM, // 15 - Default stop signal (`docker stop`, `kubectl delete pod`)
}

func startSignalForwarder(pid int) {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan,
// Signal, number, and possible cause of container runtime sending them
syscall.SIGHUP, // 1 - Reload configuration (useful for reloading services inside a container)
syscall.SIGINT, // 2 - Graceful shutdown (sent when stopping container interactively)
syscall.SIGQUIT, // 3 - Graceful shutdown + core dump (used for debugging containerized apps)
syscall.SIGUSR1, // 10 - Application-specific user-defined signal (can trigger app reloads)
syscall.SIGUSR2, // 12 - Another user-defined signal, often used for hot reloads inside a container
syscall.SIGTERM, // 15 - Default stop signal (`docker stop`, `kubectl delete pod`)
)
signal.Notify(sigChan, forwardedSignals...)
go func() {
for sig := range sigChan {
unixSig, _ := sig.(syscall.Signal)
Expand Down
12 changes: 2 additions & 10 deletions pkg/security/ptracer/ptracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ func child() {
}

func TestSignalForwarding(t *testing.T) {
forwardedSignals := []syscall.Signal{
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGUSR1,
syscall.SIGUSR2,
syscall.SIGTERM,
}

// fork to have a child to receive signals
err := fork.Fork("child")
if err != nil {
Expand All @@ -100,7 +91,8 @@ func TestSignalForwarding(t *testing.T) {
for _, sig := range forwardedSignals {
t.Run(fmt.Sprintf("%v", sig), func(t *testing.T) {
// send signal to ourselves
syscall.Kill(os.Getpid(), sig)
unixSig, _ := sig.(syscall.Signal)
syscall.Kill(os.Getpid(), unixSig)

// wait for child response
n, err := fifo.Read(buffer)
Expand Down

0 comments on commit ec6366b

Please sign in to comment.