diff --git a/net/if.go b/net/if.go index 9cea43bc..3cf3baab 100644 --- a/net/if.go +++ b/net/if.go @@ -2,6 +2,7 @@ package net import ( "fmt" + "math" "net" "time" ) @@ -10,11 +11,17 @@ const ( sleepTime = 100 * time.Millisecond ) +// Wait `wait` seconds for an interface to come up. Pass zero to check once +// and return immediately, or a negative value to wait indefinitely. func EnsureInterface(ifaceName string, wait int) (iface *net.Interface, err error) { if iface, err = findInterface(ifaceName); err == nil || wait == 0 { return } - for i := time.Duration(wait) * time.Second / sleepTime; err != nil && i > 0; i-- { + i := int64(math.MaxInt64) + if wait > 0 { + i = int64(time.Duration(wait) * time.Second / sleepTime) + } + for ; err != nil && i > 0; i-- { time.Sleep(sleepTime) iface, err = findInterface(ifaceName) } diff --git a/prog/weavedns/Dockerfile b/prog/weavedns/Dockerfile index d7af8837..883b34b8 100644 --- a/prog/weavedns/Dockerfile +++ b/prog/weavedns/Dockerfile @@ -3,4 +3,4 @@ MAINTAINER Weaveworks Inc WORKDIR /home/weave ADD ./weavedns /home/weave/ EXPOSE 53/udp -ENTRYPOINT ["/home/weave/weavedns", "-wait", "20"] +ENTRYPOINT ["/home/weave/weavedns"] diff --git a/prog/weavedns/main.go b/prog/weavedns/main.go index 21193da6..69832eaf 100644 --- a/prog/weavedns/main.go +++ b/prog/weavedns/main.go @@ -46,7 +46,7 @@ func main() { flag.StringVar(&ifaceName, "iface", "", "name of interface to use for multicast") flag.StringVar(&apiPath, "api", "unix:///var/run/docker.sock", "path to Docker API socket") flag.StringVar(&domain, "domain", weavedns.DefaultLocalDomain, "local domain (ie, 'weave.local.')") - flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up") + flag.IntVar(&wait, "wait", -1, "number of seconds to wait for interfaces to come up (0=don't wait, -1=wait forever)") flag.IntVar(&dnsPort, "dnsport", weavedns.DefaultServerPort, "port to listen to DNS requests") flag.StringVar(&httpIfaceName, "httpiface", "", "interface on which to listen for HTTP requests (defaults to empty string which listens on all interfaces)") flag.IntVar(&httpPort, "httpport", weavedns.DefaultHTTPPort, "port to listen to HTTP requests") diff --git a/prog/weaver/Dockerfile b/prog/weaver/Dockerfile index 437fc9e0..e91764e0 100644 --- a/prog/weaver/Dockerfile +++ b/prog/weaver/Dockerfile @@ -2,4 +2,4 @@ FROM scratch MAINTAINER Weaveworks Inc WORKDIR /home/weave ADD ./weaver /home/weave/ -ENTRYPOINT ["/home/weave/weaver", "-wait", "20"] +ENTRYPOINT ["/home/weave/weaver"] diff --git a/prog/weaver/main.go b/prog/weaver/main.go index d0ac8596..c17a7d46 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -64,7 +64,7 @@ func main() { flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC of interface)") flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)") flag.StringVar(&password, "password", "", "network password") - flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up (0 = don't wait)") + flag.IntVar(&wait, "wait", -1, "number of seconds to wait for interface to come up (0=don't wait, -1=wait forever)") flag.BoolVar(&debug, "debug", false, "enable debug logging") flag.BoolVar(&pktdebug, "pktdebug", false, "enable per-packet debug logging") flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path") diff --git a/prog/weavewait/main.go b/prog/weavewait/main.go index 3cb78663..0acd5f74 100644 --- a/prog/weavewait/main.go +++ b/prog/weavewait/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "os" "os/exec" "os/signal" @@ -17,20 +18,19 @@ func main() { } args := os.Args[1:] - signalWait := 20 + signalWait := time.Duration(math.MaxInt64) if args[0] == "-s" { signalWait = 0 args = args[1:] } - interfaceWait := 20 - signalWait usr2 := make(chan os.Signal) signal.Notify(usr2, syscall.SIGUSR2) select { case <-usr2: - case <-time.After(time.Duration(signalWait) * time.Second): + case <-time.After(signalWait): } - _, err := net.EnsureInterface("ethwe", interfaceWait) + _, err := net.EnsureInterface("ethwe", -1) checkErr(err) binary, err := exec.LookPath(args[0])