From cc52a5d55370128a8966ffd658819ce81d861786 Mon Sep 17 00:00:00 2001 From: David Scott Date: Sun, 3 Apr 2016 14:25:28 +0100 Subject: [PATCH] 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 --- alpine/packages/proxy/main.go | 8 +++++++- alpine/packages/proxy/proxy.go | 10 ++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/alpine/packages/proxy/main.go b/alpine/packages/proxy/main.go index c709a4996..654b6e667 100644 --- a/alpine/packages/proxy/main.go +++ b/alpine/packages/proxy/main.go @@ -1,5 +1,11 @@ package main +import ( + "pkg/proxy" +) + func main() { - execProxy() + host, container := parseHostContainerAddrs() + + proxyForever(proxy.NewProxy(host, container)) } diff --git a/alpine/packages/proxy/proxy.go b/alpine/packages/proxy/proxy.go index 64937c50d..d72e131ac 100644 --- a/alpine/packages/proxy/proxy.go +++ b/alpine/packages/proxy/proxy.go @@ -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) {