liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

waitup.fnl (983B)


      1 (local netlink (require :netlink))
      2 (local sock (netlink.socket))
      3 
      4 (when  (< (# arg) 2)
      5   (print "usage: waitup ifname fd")
      6   (os.exit 1))
      7 
      8 (local ifname (. arg 1))
      9 (local fd (tonumber (. arg 2)))
     10 (local stream (io.open (.. "/proc/self/fd/" fd) "w"))
     11 
     12 (fn notify-ready []
     13   (when (= "file" (io.type stream))
     14     (stream:write "\n")
     15     (stream:close))
     16   (print (.. (. arg 0) ": received netlink operstate up for " ifname)))
     17 
     18 
     19 (fn run-events [evs]
     20   (each [_ v (ipairs evs)]
     21     (print :event v.event v.name)
     22 
     23     (match v
     24       ;; - up: Reflects the administrative state of the interface (IFF_UP)
     25       ;; - running: Reflects the operational state (IFF_RUNNING).
     26       {:event "newlink" :name ifname :up :yes :running :yes}
     27       (notify-ready)
     28 
     29       {:event "newlink" :name ifname :up :no}
     30       (os.exit 0))))
     31 
     32 (run-events (sock:query {:link true}))
     33 
     34 (print (.. (. arg 0) ": waiting for netlink NEWLINK " ifname))
     35 
     36 (while (sock:poll)
     37   (let [ev (sock:event)]
     38     (run-events ev)))