proxy: on exit, return to main for cleanup

Previously the proxy.go would directly call `os.Exit`. This patch
causes control to return to `main` where we can tear down any port
forward.

Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
David Scott 2016-04-03 14:42:17 +01:00
parent cc52a5d553
commit 3d5767714c
2 changed files with 11 additions and 5 deletions

View File

@ -1,11 +1,18 @@
package main
import (
"log"
"os"
"pkg/proxy"
)
func main() {
host, container := parseHostContainerAddrs()
proxyForever(proxy.NewProxy(host, container))
err := proxyForever(proxy.NewProxy(host, container))
if err != nil {
os.Exit(0)
}
os.Exit(1)
}

View File

@ -13,13 +13,13 @@ import (
)
// proxyForever signals the parent success/failure and runs the proxy forever
func proxyForever(p proxy.Proxy, err error) {
func proxyForever(p proxy.Proxy, err error) error {
f := os.NewFile(3, "signal-parent")
if err != nil {
fmt.Fprintf(f, "1\n%s", err)
f.Close()
os.Exit(1)
return err
}
go handleStopSignals(p)
fmt.Fprint(f, "0\n")
@ -27,6 +27,7 @@ func proxyForever(p proxy.Proxy, err error) {
// Run will block until the proxy stops
p.Run()
return nil
}
// From docker/libnetwork/portmapper/proxy.go:
@ -64,7 +65,5 @@ func handleStopSignals(p proxy.Proxy) {
for range s {
p.Close()
os.Exit(0)
}
}