mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
Merge pull request #215 from djs55/proxy-arg
proxy: add interactive mode with `-i`
This commit is contained in:
commit
16fa85917f
@ -12,8 +12,14 @@ import (
|
|||||||
"proxy/libproxy"
|
"proxy/libproxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var interactiveMode bool
|
||||||
|
|
||||||
|
|
||||||
// sendError signals the error to the parent and quits the process.
|
// sendError signals the error to the parent and quits the process.
|
||||||
func sendError(err error) {
|
func sendError(err error) {
|
||||||
|
if interactiveMode {
|
||||||
|
log.Fatal("Failed to set up proxy", err)
|
||||||
|
}
|
||||||
f := os.NewFile(3, "signal-parent")
|
f := os.NewFile(3, "signal-parent")
|
||||||
|
|
||||||
fmt.Fprintf(f, "1\n%s", err)
|
fmt.Fprintf(f, "1\n%s", err)
|
||||||
@ -23,6 +29,10 @@ func sendError(err error) {
|
|||||||
|
|
||||||
// sendOK signals the parent that the forward is running.
|
// sendOK signals the parent that the forward is running.
|
||||||
func sendOK() {
|
func sendOK() {
|
||||||
|
if interactiveMode {
|
||||||
|
log.Println("Proxy running")
|
||||||
|
return
|
||||||
|
}
|
||||||
f := os.NewFile(3, "signal-parent")
|
f := os.NewFile(3, "signal-parent")
|
||||||
fmt.Fprint(f, "0\n")
|
fmt.Fprint(f, "0\n")
|
||||||
f.Close()
|
f.Close()
|
||||||
@ -45,9 +55,11 @@ func parseHostContainerAddrs() (host net.Addr, port int, container net.Addr) {
|
|||||||
hostPort = flag.Int("host-port", -1, "host port")
|
hostPort = flag.Int("host-port", -1, "host port")
|
||||||
containerIP = flag.String("container-ip", "", "container ip")
|
containerIP = flag.String("container-ip", "", "container ip")
|
||||||
containerPort = flag.Int("container-port", -1, "container port")
|
containerPort = flag.Int("container-port", -1, "container port")
|
||||||
|
interactive = flag.Bool("i", false, "print success/failure to stdout/stderr")
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
interactiveMode = *interactive
|
||||||
|
|
||||||
switch *proto {
|
switch *proto {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
|
Loading…
Reference in New Issue
Block a user