2022-01-17 17:23:02 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/deniswernert/udev"
|
|
|
|
)
|
|
|
|
|
2022-03-21 11:11:52 +08:00
|
|
|
var (
|
|
|
|
GitBranch string
|
|
|
|
GitCommit string
|
|
|
|
|
|
|
|
UNotify chan *udev.UEvent
|
|
|
|
)
|
2022-01-17 17:23:02 +08:00
|
|
|
|
|
|
|
func Mon() {
|
|
|
|
for {
|
|
|
|
uevent := <-UNotify
|
|
|
|
|
|
|
|
log.Println("UEvent.Action: ", uevent.Action)
|
|
|
|
log.Println("UEvent.Devpath: ", uevent.Devpath)
|
|
|
|
log.Println("UEvent.Env: ", uevent.Env)
|
|
|
|
log.Println()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2022-03-21 11:11:52 +08:00
|
|
|
log.Println("MUEvent branch=" + GitBranch + " commit=" + GitCommit)
|
2022-01-17 17:23:02 +08:00
|
|
|
UNotify = make(chan *udev.UEvent, 128)
|
|
|
|
mon, e := udev.NewMonitor()
|
|
|
|
if e != nil {
|
|
|
|
panic(e)
|
|
|
|
}
|
|
|
|
go Mon()
|
|
|
|
mon.Monitor(UNotify)
|
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|