
Starting with go1.14, the go runtime hijacks SIGURG but with no way to not send to other signal handlers. In practice, we get this signal frequently. I found this while testing out go1.15 with ctr and multiple execs with only `echo hello`. When the process exits quickly, if the previous commit is not applied, you end up with an error message that it couldn't forward SIGURG to the container (due to the process being gone). Signed-off-by: Brian Goff <cpuguy83@gmail.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
/*
|
|
Copyright The containerd Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package commands
|
|
|
|
import (
|
|
gocontext "context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/containerd/containerd"
|
|
"github.com/containerd/containerd/errdefs"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type killer interface {
|
|
Kill(gocontext.Context, syscall.Signal, ...containerd.KillOpts) error
|
|
}
|
|
|
|
// ForwardAllSignals forwards signals
|
|
func ForwardAllSignals(ctx gocontext.Context, task killer) chan os.Signal {
|
|
sigc := make(chan os.Signal, 128)
|
|
signal.Notify(sigc)
|
|
go func() {
|
|
for s := range sigc {
|
|
if canIgnoreSignal(s) {
|
|
logrus.Debugf("Ignoring signal %s", s)
|
|
continue
|
|
}
|
|
logrus.Debug("forwarding signal ", s)
|
|
if err := task.Kill(ctx, s.(syscall.Signal)); err != nil {
|
|
if errdefs.IsNotFound(err) {
|
|
logrus.WithError(err).Debugf("Not forwarding signal %s", s)
|
|
return
|
|
}
|
|
logrus.WithError(err).Errorf("forward signal %s", s)
|
|
}
|
|
}
|
|
}()
|
|
return sigc
|
|
}
|
|
|
|
// StopCatch stops and closes a channel
|
|
func StopCatch(sigc chan os.Signal) {
|
|
signal.Stop(sigc)
|
|
close(sigc)
|
|
}
|