mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 09:39:08 +00:00
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:
parent
cc52a5d553
commit
3d5767714c
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user