add "waitup", s6 readiness helper for network interfaces
run e.g. "waitup wlan0 10" to wait until wlan0 is operationally up and running, and then send a newline to file descriptor 10
This commit is contained in:
36
pkgs/waitup/waitup.fnl
Normal file
36
pkgs/waitup/waitup.fnl
Normal file
@@ -0,0 +1,36 @@
|
||||
(local netlink (require :netlink))
|
||||
(local sock (netlink.socket))
|
||||
|
||||
(when (< (# arg) 2)
|
||||
(print "usage: waitup ifname fd")
|
||||
(os.exit 1))
|
||||
|
||||
(local ifname (. arg 1))
|
||||
(local fd (tonumber (. arg 2)))
|
||||
(local stream (io.open (.. "/proc/self/fd/" fd) "w"))
|
||||
|
||||
(fn notify-ready []
|
||||
(stream:write "\n")
|
||||
(print (.. (. arg 0) ": received netlink operstate up for " ifname))
|
||||
(stream:close))
|
||||
|
||||
(fn run-events [evs]
|
||||
(each [_ v (ipairs evs)]
|
||||
(print :event v.event v.name)
|
||||
|
||||
(match v
|
||||
;; - up: Reflects the administrative state of the interface (IFF_UP)
|
||||
;; - running: Reflects the operational state (IFF_RUNNING).
|
||||
{:event "newlink" :name ifname :up :yes :running :yes}
|
||||
(notify-ready)
|
||||
|
||||
{:event "newlink" :name ifname :up :no}
|
||||
(os.exit 0))))
|
||||
|
||||
(run-events (sock:query {:link true}))
|
||||
|
||||
(print (.. (. arg 0) ": waiting for netlink NEWLINK " ifname))
|
||||
|
||||
(while (sock:poll)
|
||||
(let [ev (sock:event)]
|
||||
(run-events ev)))
|
Reference in New Issue
Block a user