Created
April 22, 2016 07:18
-
-
Save svinota/b1a6f29b4c8a9cf96cf6d6f35afe23e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"time" | |
"github.com/vishvananda/netlink" | |
) | |
func WaitForLink(ch <-chan netlink.LinkUpdate, ifaceName string) bool { | |
for { | |
timeout := time.After(time.Minute) | |
select { | |
case update := <-ch: | |
if ifaceName == update.Link.Attrs().Name { | |
return true | |
} | |
case <-timeout: | |
return false | |
} | |
} | |
} | |
func main() { | |
ch := make(chan netlink.LinkUpdate) | |
done := make(chan struct{}) | |
defer close(done) | |
if err := netlink.LinkSubscribe(ch, done); err != nil { | |
os.Exit(2) | |
} | |
if !WaitForLink(ch, "dummy2") { | |
os.Exit(3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment