Skip to content

Commit 7425f32

Browse files
authored
Merge pull request #9 from espressif/fix/leaking_zombies
fix: Add global handler to reap zombie children
2 parents 591f027 + dc06051 commit 7425f32

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,30 @@ import (
66
"net/http"
77
"net/http/cgi"
88
"os"
9+
"os/signal"
910
"strings"
11+
"syscall"
1012
"time"
1113
)
1214

1315
func main() {
16+
// Set up signal handler to reap zombie processes
17+
// This prevents git processes spawned by CGI handler from becoming zombies
18+
sigChan := make(chan os.Signal, 1)
19+
signal.Notify(sigChan, syscall.SIGCHLD)
20+
go func() {
21+
for range sigChan {
22+
// Reap all zombie children
23+
for {
24+
var status syscall.WaitStatus
25+
pid, err := syscall.Wait4(-1, &status, syscall.WNOHANG, nil)
26+
if err != nil || pid <= 0 {
27+
break
28+
}
29+
}
30+
}
31+
}()
32+
1433
// Parse config.
1534
if len(os.Args) != 2 {
1635
log.Fatal("please specify the path to a config file, an example config is available at https://github.com/espressif/git-mirror-server/blob/master/example-config.toml")

0 commit comments

Comments
 (0)