mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 18:11:35 +00:00
proxy: add exposePort
and unexposePort
stubs
This patch removes `proxyForever` and adds `sendError` and `sendOK` for signalling to the parent process. The main function now sequences these functions and calls stub functions `exposePort` and `unexposePort` which will be hooked up in a later patch. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
3d5767714c
commit
eab69ef583
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"pkg/proxy"
|
"pkg/proxy"
|
||||||
)
|
)
|
||||||
@ -9,10 +10,27 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
host, container := parseHostContainerAddrs()
|
host, container := parseHostContainerAddrs()
|
||||||
|
|
||||||
err := proxyForever(proxy.NewProxy(host, container))
|
err := exposePort(host)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(0)
|
sendError(err)
|
||||||
}
|
}
|
||||||
os.Exit(1)
|
p, err := proxy.NewProxy(host, container)
|
||||||
|
if err != nil {
|
||||||
|
unexposePort(host)
|
||||||
|
sendError(err)
|
||||||
|
}
|
||||||
|
go handleStopSignals(p)
|
||||||
|
sendOK()
|
||||||
|
p.Run()
|
||||||
|
unexposePort(host)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exposePort(host net.Addr) error {
|
||||||
|
log.Printf("exposePort %#v\n", host)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func unexposePort(host net.Addr) {
|
||||||
|
log.Printf("unexposePort %#v\n", host)
|
||||||
}
|
}
|
||||||
|
@ -12,22 +12,20 @@ import (
|
|||||||
"pkg/proxy"
|
"pkg/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// proxyForever signals the parent success/failure and runs the proxy forever
|
// sendError signals the error to the parent and quits the process.
|
||||||
func proxyForever(p proxy.Proxy, err error) error {
|
func sendError(err error) {
|
||||||
f := os.NewFile(3, "signal-parent")
|
f := os.NewFile(3, "signal-parent")
|
||||||
|
|
||||||
if err != nil {
|
fmt.Fprintf(f, "1\n%s", err)
|
||||||
fmt.Fprintf(f, "1\n%s", err)
|
f.Close()
|
||||||
f.Close()
|
os.Exit(1)
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
go handleStopSignals(p)
|
// sendOK signals the parent that the forward is running.
|
||||||
|
func sendOK() {
|
||||||
|
f := os.NewFile(3, "signal-parent")
|
||||||
fmt.Fprint(f, "0\n")
|
fmt.Fprint(f, "0\n")
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
// Run will block until the proxy stops
|
|
||||||
p.Run()
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// From docker/libnetwork/portmapper/proxy.go:
|
// From docker/libnetwork/portmapper/proxy.go:
|
||||||
|
Loading…
Reference in New Issue
Block a user