mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 05:36:12 +00:00
Merge pull request #23865 from rhcarvalho/unify-signal-handling
Automatic merge from submit-queue Unify termination signal handling across platforms The signals are used to ensure proper execution of cleaning up actions to restore a terminal in: - [pkg/kubectl/cmd/attach.go#L163-L226](b8d000853e/pkg/kubectl/cmd/attach.go (L163-L226)
) - [pkg/kubectl/cmd/util/editor/editor.go#L112-L137](b8d000853e/pkg/kubectl/cmd/util/editor/editor.go (L112-L137)
) All supported platforms can handle the same set of signals we're interested in, thus we don't need build contraints to use a set of signals on Linux, while restricting ourselves to only SIGINT on Darwin and Windows. According to the documentation of os/signal, similar to SIGINT and SIGTERM, SIGHUP causes the program to exit, therefore add it to the list of handled signals. The fist commit is part of #23643.
This commit is contained in:
@@ -1,26 +0,0 @@
|
|||||||
// +build !linux
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
|
||||||
|
|
||||||
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 interrupt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// childSignals are the allowed signals that can be sent to children in Windows to terminate
|
|
||||||
var childSignals = []os.Signal{os.Interrupt}
|
|
@@ -1,27 +0,0 @@
|
|||||||
// +build linux
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
|
||||||
|
|
||||||
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 interrupt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// childSignals are the allowed signals that can be sent to children in Unix variant OS's
|
|
||||||
var childSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT}
|
|
@@ -20,8 +20,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// terminationSignals are signals that cause the program to exit in the
|
||||||
|
// supported platforms (linux, darwin, windows).
|
||||||
|
var terminationSignals = []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT}
|
||||||
|
|
||||||
// Handler guarantees execution of notifications after a critical section (the function passed
|
// Handler guarantees execution of notifications after a critical section (the function passed
|
||||||
// to a Run method), even in the presence of process termination. It guarantees exactly once
|
// to a Run method), even in the presence of process termination. It guarantees exactly once
|
||||||
// invocation of the provided notify functions.
|
// invocation of the provided notify functions.
|
||||||
@@ -82,7 +87,7 @@ func (h *Handler) Signal(s os.Signal) {
|
|||||||
// per Handler instance, so calling Run more than once will not behave as the user expects.
|
// per Handler instance, so calling Run more than once will not behave as the user expects.
|
||||||
func (h *Handler) Run(fn func() error) error {
|
func (h *Handler) Run(fn func() error) error {
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, childSignals...)
|
signal.Notify(ch, terminationSignals...)
|
||||||
defer func() {
|
defer func() {
|
||||||
signal.Stop(ch)
|
signal.Stop(ch)
|
||||||
close(ch)
|
close(ch)
|
||||||
|
Reference in New Issue
Block a user