1
0
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:
2026-03-27 22:42:25 +09:00
parent ee22847dde
commit 2745602be3

26
internal/uevent/uevent.go Normal file
View 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
}