Ejemplo n.º 1
0
func (self *Monitor) Close() {
	C.udev_monitor_unref(self.udev_monitor)
	C.udev_unref(self.udev)

	self.udev_monitor = nil
	self.udev = nil
}
Ejemplo n.º 2
0
func MonitorUdev(subsystem string) (*Monitor, error) {
	cName := C.CString("udev")
	defer C.free(unsafe.Pointer(cName))

	udev := C.udev_new()
	udev_monitor := C.udev_monitor_new_from_netlink(udev, cName)

	if udev_monitor == nil {
		C.udev_unref(udev)
		return nil, Error{"udev_monitor_new_from_netlink"}
	}

	if subsystem != "" {
		cSubsystem := C.CString(subsystem)
		defer C.free(unsafe.Pointer(cSubsystem))

		if C.udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, cSubsystem, nil) < 0 {
			C.udev_monitor_unref(udev_monitor)
			C.udev_unref(udev)
			return nil, Error{"udev_monitor_filter_add_match_subsystem_devtype"}
		}
	}

	if C.udev_monitor_enable_receiving(udev_monitor) < 0 {
		C.udev_monitor_unref(udev_monitor)
		C.udev_unref(udev)
		return nil, Error{"udev_monitor_enable_receiving"}
	}

	// set blocking
	if fd := C.udev_monitor_get_fd(udev_monitor); fd < 0 {
		C.udev_monitor_unref(udev_monitor)
		C.udev_unref(udev)
		return nil, Error{"udev_monitor_get_fd"}
	} else if err := syscall.SetNonblock(int(fd), false); err != nil {
		C.udev_monitor_unref(udev_monitor)
		C.udev_unref(udev)
		return nil, err
	}

	return &Monitor{udev, udev_monitor}, nil
}
Ejemplo n.º 3
0
Archivo: udev.go Proyecto: jessta/udev
func (m Monitor) Unref() {
	C.udev_monitor_unref(m.ptr)
}
Ejemplo n.º 4
0
// Unref the monitor
func monitorUnref(m *Monitor) {
	C.udev_monitor_unref(m.ptr)
}