forked from rosa/hakurei
internal/uevent: wrap netlink socket
Unfortunately these messages do not have the same format as rtnetlink. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
26
internal/uevent/uevent.go
Normal file
26
internal/uevent/uevent.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Package uevent provides userspace client for consuming events from a
|
||||||
|
// NETLINK_KOBJECT_UEVENT socket, as well as helpers for supplementing
|
||||||
|
// events received from the kernel.
|
||||||
|
package uevent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"hakurei.app/internal/netlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Conn represents a NETLINK_KOBJECT_UEVENT socket.
|
||||||
|
type Conn struct{ conn *netlink.Conn }
|
||||||
|
|
||||||
|
// Close closes the underlying socket.
|
||||||
|
func (c *Conn) Close() error { return c.conn.Close() }
|
||||||
|
|
||||||
|
// Dial returns the address of a newly connected [Conn].
|
||||||
|
func Dial() (*Conn, error) {
|
||||||
|
// kernel group is hard coded in lib/kobject_uevent.c, undocumented
|
||||||
|
c, err := netlink.Dial(syscall.NETLINK_KOBJECT_UEVENT, 1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Conn{c}, err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user