1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #22460 from jwhonce/wip/sigpipe

Ignore SIGPIPE events
This commit is contained in:
Sebastiaan van Stijn 2016-06-02 16:05:22 +02:00
commit 171af54931
2 changed files with 14 additions and 7 deletions

View file

@ -127,6 +127,11 @@ func (cli *DaemonCli) start() (err error) {
stopc := make(chan bool)
defer close(stopc)
signal.Trap(func() {
cli.stop()
<-stopc // wait for daemonCli.start() to return
})
// warn from uuid package when running the daemon
uuid.Loggerf = logrus.Warnf
@ -280,11 +285,6 @@ func (cli *DaemonCli) start() (err error) {
serveAPIWait := make(chan error)
go api.Wait(serveAPIWait)
signal.Trap(func() {
cli.stop()
<-stopc // wait for daemonCli.start() to return
})
// after the daemon is done setting up we can notify systemd api
notifySystem()

View file

@ -18,15 +18,22 @@ import (
// * If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is
// skipped and the process is terminated immediately (allows force quit of stuck daemon)
// * A SIGQUIT always causes an exit without cleanup, with a goroutine dump preceding exit.
// * Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
// the docker daemon is not restarted and also running under systemd.
// Fixes https://github.com/docker/docker/issues/19728
//
func Trap(cleanup func()) {
c := make(chan os.Signal, 1)
// we will handle INT, TERM, QUIT here
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}
// we will handle INT, TERM, QUIT, SIGPIPE here
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE}
gosignal.Notify(c, signals...)
go func() {
interruptCount := uint32(0)
for sig := range c {
if sig == syscall.SIGPIPE {
continue
}
go func(sig os.Signal) {
logrus.Infof("Processing signal '%v'", sig)
switch sig {