Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split SIGCHLD from all other signal handlers in supervisor (v3) #493

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions sup/sup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,43 @@ func Run() {
if err != nil {
log.Fatal("failed to start ContainerPilot worker process:", err)
}
handleSignals(proc.Pid)
passThroughSignals(proc.Pid)
handleReaping(proc.Pid)
proc.Wait()
}

// handleSignals listens for signals used to gracefully shutdown and
// passThroughSignals listens for signals used to gracefully shutdown and
// passes them thru to the ContainerPilot worker process.
func handleSignals(pid int) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT, syscall.SIGCHLD, syscall.SIGUSR1)
func passThroughSignals(pid int) {
sigRecv := make(chan os.Signal, 1)
signal.Notify(sigRecv, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
go func() {
for signal := range sig {
switch signal {
for sig := range sigRecv {
switch sig {
case syscall.SIGINT:
syscall.Kill(pid, syscall.SIGINT)
case syscall.SIGTERM:
syscall.Kill(pid, syscall.SIGTERM)
case syscall.SIGUSR1:
syscall.Kill(pid, syscall.SIGUSR1)
case syscall.SIGCHLD:
go reap()
}
}
}()
}

// handleReaping listens for the SIGCHLD signal only and triggers
// reaping of child processes
func handleReaping(pid int) {
sigRecv := make(chan os.Signal, 1)
signal.Notify(sigRecv, syscall.SIGCHLD)
go func() {
for {
<-sigRecv
reap()
}
}()
}

// reaps child processes that have been reparented to PID1
func reap() {
for {
Expand Down