Skip to content

Commit

Permalink
fixup! Add support to sig-proxy for podman-remote
Browse files Browse the repository at this point in the history
  • Loading branch information
boaz0 committed Aug 4, 2022
1 parent 88bcd93 commit c9d4365
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta

// Attach
if opts.SigProxy {
ProxySignal(con.ID, func(signal string) error {
RemoteProxySignals(con.ID, func(signal string) error {
killOpts := entities.KillOptions{All: false, Latest: false, Signal: signal}
_, err := ic.ContainerKill(ctx, []string{con.ID}, killOpts)
return err
Expand Down
22 changes: 2 additions & 20 deletions pkg/domain/infra/tunnel/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,15 @@ type SystemEngine struct {
ClientCtx context.Context
}

func ProxySignal(ctrID string, killFunc func(string) error) {
// RemoteProxySignals enables sig-proxy in remote mode.
func RemoteProxySignals(ctrID string, killFunc func(string) error) {
sigBuffer := make(chan os.Signal, terminal.SignalBufferSize)
signal.CatchAll(sigBuffer)

logrus.Debugf("Enabling signal proxying")

go func() {
for s := range sigBuffer {
// Ignore SIGCHLD and SIGPIPE - these are mostly likely
// intended for the podman command itself.
// SIGURG was added because of golang 1.14 and its preemptive changes
// causing more signals to "show up".
// https://github.com/containers/podman/issues/5483
if s == syscall.SIGCHLD || s == syscall.SIGPIPE || s == syscall.SIGURG {
continue
}

signalName, err := signal.ParseSysSignalToName(s.(syscall.Signal))
if err != nil {
logrus.Infof("Ceasing signal forwarding to container %s as it has stopped", ctrID)
Expand All @@ -53,16 +45,6 @@ func ProxySignal(ctrID string, killFunc func(string) error) {
} else {
logrus.Errorf("forwarding signal %d to container %s: %v", s, ctrID, err)
}
// If the container dies, and we find out here,
// we need to forward that one signal to
// ourselves so that it is not lost, and then
// we terminate the proxy and let the defaults
// play out.
signal.StopCatch(sigBuffer)
if err := syscall.Kill(syscall.Getpid(), s.(syscall.Signal)); err != nil {
logrus.Errorf("Failed to kill pid %d", syscall.Getpid())
}
return
}
}
}()
Expand Down

0 comments on commit c9d4365

Please sign in to comment.