usb-ks

USB Killswitch
git clone git://git.laack.co/usb-ks.git
Log | Files | Refs | README | LICENSE

monitor.go (545B)


      1 package usbmon
      2 
      3 import (
      4 	"context"
      5 
      6 	"github.com/jochenvg/go-udev"
      7 )
      8 
      9 type Monitor interface {
     10 	DeviceChan(context.Context) (<-chan *udev.Device, error)
     11 }
     12 
     13 type UdevMonitor struct {
     14 	monitor *udev.Monitor
     15 }
     16 
     17 func (m *UdevMonitor) DeviceChan(ctx context.Context) (<-chan *udev.Device, <-chan error, error) {
     18 	return m.monitor.DeviceChan(ctx)
     19 }
     20 
     21 func NewUdevMonitor() *UdevMonitor {
     22 	u := udev.Udev{}
     23 	m := u.NewMonitorFromNetlink("udev")
     24 	_ = m.FilterAddMatchTag("seat")
     25 	_ = m.FilterAddMatchSubsystem("usb")
     26 
     27 	return &UdevMonitor{monitor: m}
     28 }