Skip to content

Commit 06b6842

Browse files
Merge pull request #26027 from Luap99/signal
sigproxy: ignore SIGSTOP and handle case where container is already removed
2 parents 8f22a0c + 941a6d0 commit 06b6842

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

pkg/domain/infra/abi/terminal/sigproxy_commn.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ func ProxySignals(ctr *libpod.Container) {
2828
go func() {
2929
for s := range sigBuffer {
3030
syscallSignal := s.(syscall.Signal)
31-
if signal.IsSignalIgnoredBySigProxy(syscallSignal) {
32-
continue
33-
}
3431

3532
if err := ctr.Kill(uint(syscallSignal)); err != nil {
36-
if errors.Is(err, define.ErrCtrStateInvalid) {
33+
// If the container is no longer running/removed do not log it as error.
34+
if errors.Is(err, define.ErrCtrStateInvalid) || errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved) {
3735
logrus.Infof("Ceasing signal forwarding to container %s as it has stopped", ctr.ID())
3836
} else {
3937
logrus.Errorf("forwarding signal %d to container %s: %v", s, ctr.ID(), err)

pkg/domain/infra/tunnel/runtime.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ func remoteProxySignals(ctrID string, killFunc func(string) error) {
4646
go func() {
4747
for s := range sigBuffer {
4848
syscallSignal := s.(syscall.Signal)
49-
if signal.IsSignalIgnoredBySigProxy(syscallSignal) {
50-
continue
51-
}
5249
signalName, err := signal.ParseSysSignalToName(syscallSignal)
5350
if err != nil {
5451
logrus.Infof("Ceasing signal %v forwarding to container %s as it has stopped: %s", s, ctrID, err)

pkg/signal/signal_common.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ func ParseSignalNameOrNumber(rawSignal string) (syscall.Signal, error) {
4646
return -1, fmt.Errorf("invalid signal: %s", basename)
4747
}
4848

49-
// CatchAll catches all signals and relays them to the specified channel.
49+
// CatchAll catches all signals (except the ones that make no sense to handle/forward,
50+
// see isSignalIgnoredBySigProxy()) and relays them to the specified channel.
5051
func CatchAll(sigc chan os.Signal) {
5152
handledSigs := make([]os.Signal, 0, len(SignalMap))
5253
for _, s := range SignalMap {
53-
handledSigs = append(handledSigs, s)
54+
if !isSignalIgnoredBySigProxy(s) {
55+
handledSigs = append(handledSigs, s)
56+
}
5457
}
5558
signal.Notify(sigc, handledSigs...)
5659
}

pkg/signal/signal_linux.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ var SignalMap = map[string]syscall.Signal{
8989
"RTMAX": sigrtmax,
9090
}
9191

92-
// IsSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
93-
func IsSignalIgnoredBySigProxy(s syscall.Signal) bool {
92+
// isSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
93+
func isSignalIgnoredBySigProxy(s syscall.Signal) bool {
9494
// Ignore SIGCHLD and SIGPIPE - these are most likely intended for the podman command itself.
9595
// SIGURG was added because of golang 1.14 and its preemptive changes causing more signals to "show up".
9696
// https://github.com/containers/podman/issues/5483
97-
return s == syscall.SIGCHLD || s == syscall.SIGPIPE || s == syscall.SIGURG
97+
// SIGSTOP cannot be ignored/forwarded by userspace.
98+
switch s {
99+
case syscall.SIGCHLD, syscall.SIGPIPE, syscall.SIGURG, syscall.SIGSTOP:
100+
return true
101+
default:
102+
return false
103+
}
98104
}

pkg/signal/signal_linux_mipsx.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ var SignalMap = map[string]syscall.Signal{
8989
"RTMAX": sigrtmax,
9090
}
9191

92-
// IsSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
93-
func IsSignalIgnoredBySigProxy(s syscall.Signal) bool {
92+
// isSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
93+
func isSignalIgnoredBySigProxy(s syscall.Signal) bool {
9494
// Ignore SIGCHLD and SIGPIPE - these are most likely intended for the podman command itself.
9595
// SIGURG was added because of golang 1.14 and its preemptive changes causing more signals to "show up".
9696
// https://github.com/containers/podman/issues/5483
97-
return s == syscall.SIGCHLD || s == syscall.SIGPIPE || s == syscall.SIGURG
97+
// SIGSTOP cannot be ignored/forwarded by userspace.
98+
switch s {
99+
case syscall.SIGCHLD, syscall.SIGPIPE, syscall.SIGURG, syscall.SIGSTOP:
100+
return true
101+
default:
102+
return false
103+
}
98104
}

pkg/signal/signal_unix.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,16 @@ var SignalMap = map[string]syscall.Signal{
8787
"RTMAX": sigrtmax,
8888
}
8989

90-
// IsSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
91-
func IsSignalIgnoredBySigProxy(s syscall.Signal) bool {
90+
// isSignalIgnoredBySigProxy determines whether sig-proxy should ignore syscall signal
91+
func isSignalIgnoredBySigProxy(s syscall.Signal) bool {
9292
// Ignore SIGCHLD and SIGPIPE - these are most likely intended for the podman command itself.
9393
// SIGURG was added because of golang 1.14 and its preemptive changes causing more signals to "show up".
9494
// https://github.com/containers/podman/issues/5483
95-
return s == syscall.SIGCHLD || s == syscall.SIGPIPE || s == syscall.SIGURG
95+
// SIGSTOP cannot be ignored/forwarded by userspace.
96+
switch s {
97+
case syscall.SIGCHLD, syscall.SIGPIPE, syscall.SIGURG, syscall.SIGSTOP:
98+
return true
99+
default:
100+
return false
101+
}
96102
}

pkg/signal/signal_unsupported.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ var SignalMap = map[string]syscall.Signal{
8787
"RTMAX": sigrtmax,
8888
}
8989

90-
// IsSignalIgnoredBySigProxy determines whether to sig-proxy should ignore syscall signal
90+
// isSignalIgnoredBySigProxy determines whether to sig-proxy should ignore syscall signal
9191
// keep the container running or not. In unsupported OS this should not ignore any syscall signal.
92-
func IsSignalIgnoredBySigProxy(s syscall.Signal) bool {
92+
func isSignalIgnoredBySigProxy(_ syscall.Signal) bool {
9393
return false
9494
}

0 commit comments

Comments
 (0)