mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
Unify termination signal handling across platforms
- 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. Signed-off-by: Rodolfo Carvalho <rcarvalh@redhat.com>
This commit is contained in:
parent
2347d0f047
commit
9576f71b9a
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user