fn: dind SIGINT and SIGCHLD changes (#771)

1) in dind, prevent SIGINT reaching to dockerd. This kills
docker and prevents shutdown as fn server is trying to stop.
2) as init process, always reap child processes.
This commit is contained in:
Tolga Ceylan
2018-02-13 19:46:53 -08:00
committed by GitHub
parent f01b502bc7
commit c132cf1825
3 changed files with 39 additions and 1 deletions

View File

@@ -4,10 +4,13 @@ import (
"context"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
"github.com/fnproject/fn/api/common"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func init() {
@@ -55,3 +58,34 @@ func contextWithSignal(ctx context.Context, signals ...os.Signal) (context.Conte
}()
return newCTX, halt
}
// Installs a child process reaper if init process
func installChildReaper() {
// assume responsibilities of init process if running as init process for Linux
if runtime.GOOS != "linux" || os.Getpid() != 1 {
return
}
var sigs = make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGCHLD)
// we run this forever and leak a go routine. As init, we must
// reap our children until the very end, so this is OK.
go func() {
for {
<-sigs
for {
var status syscall.WaitStatus
var rusage syscall.Rusage
pid, err := syscall.Wait4(-1, &status, syscall.WNOHANG, &rusage)
// no children
if pid <= 0 {
break
}
logrus.Infof("Child terminated pid=%d err=%v status=%v usage=%v", pid, err, status, rusage)
}
}
}()
}