proxy: split the execProxy function into parts

Previously `execProxy` would
- create the proxy
- signal success/failure to the parent
- run forever (until signalled)

Since we want to add more proxy setup and teardown, this patch
removes the proxy creation from `execProxy` and renames it to
`proxyForever`. Later patches will be able to perform the necessary
side-effects before signalling success to the parent.

Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
David Scott 2016-04-03 14:25:28 +01:00
parent 1c0b7f8774
commit cc52a5d553
2 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,11 @@
package main
import (
"pkg/proxy"
)
func main() {
execProxy()
host, container := parseHostContainerAddrs()
proxyForever(proxy.NewProxy(host, container))
}

View File

@ -12,14 +12,10 @@ import (
"pkg/proxy"
)
// From docker/libnetwork/portmapper/proxy.go
// execProxy is the reexec function that is registered to start the userland proxies
func execProxy() {
// proxyForever signals the parent success/failure and runs the proxy forever
func proxyForever(p proxy.Proxy, err error) {
f := os.NewFile(3, "signal-parent")
host, container := parseHostContainerAddrs()
p, err := proxy.NewProxy(host, container)
if err != nil {
fmt.Fprintf(f, "1\n%s", err)
f.Close()
@ -33,6 +29,8 @@ func execProxy() {
p.Run()
}
// From docker/libnetwork/portmapper/proxy.go:
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP or UDP
// net.Addrs to map the host and container ports
func parseHostContainerAddrs() (host net.Addr, container net.Addr) {