diff options
author | Jakob Borg <jakob@nym.se> | 2014-05-24 12:28:36 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-05-24 12:28:36 +0200 |
commit | 4af3f77a9aade98b3dddab62cebba1194a14957a (patch) | |
tree | 07f0a1c681adb68c8203fb1acd8dbae384fc8f96 /cmd | |
parent | 8c4f07ef1b2a9cd2fcd0dcd01113115065469449 (diff) |
Wait for parent to release sockets (fixes #267, fixes #241)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/syncthing/main.go | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index d464394bb8..592275aefd 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -100,11 +100,6 @@ func main() { flag.Usage = usageFor(flag.CommandLine, usage, extraUsage) flag.Parse() - if len(os.Getenv("STRESTART")) > 0 { - // Give the parent process time to exit and release sockets etc. - time.Sleep(1 * time.Second) - } - if showVersion { fmt.Println(LongVersion) return @@ -226,6 +221,10 @@ func main() { }() } + if len(os.Getenv("STRESTART")) > 0 { + waitForParentExit() + } + // The TLS configuration is used for both the listening socket and outgoing // connections. @@ -363,6 +362,21 @@ func main() { } <-stop + l.Okln("Exiting") +} + +func waitForParentExit() { + l.Infoln("Waiting for parent to exit...") + // Wait for the listen address to become free, indicating that the parent has exited. + for { + ln, err := net.Listen("tcp", cfg.Options.ListenAddress[0]) + if err == nil { + ln.Close() + break + } + time.Sleep(250 * time.Millisecond) + } + l.Okln("Continuing") } func setupUPnP() int { |