uevent

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

Golang uevent bindings

This golang library implements uevent bindings for reading and decoding Linux kernel udev events.

Usage

package main

import (
	"fmt"
	"log"

	"github.com/silenium-dev/uevent.go"
)

func main() {
	r, err := uevent.NewReader()
	if err != nil {
		log.Fatal(err)
	}

	dec := uevent.NewDecoder(r)

	for {
		evt, err := dec.Decode()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(evt)
	}
}

Prerequisites

Linux

Documentation

Overview

Package uevent implements a Linux kernel uevent reader and decoder. The reader uses a Netlink (AF_NETLINK) socket to listen to kernel udev events (see netlink(7)). The decoder takes an arbitrary io.Reader and decodes Uevent objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReader

func NewReader() (io.ReadCloser, error)

NewReader returns a new netlink socket reader. It opens a raw AF_NETLINK domain socket using the uevent protocol and binds it to the PID of the calling program.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes uevents from a reader.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates an uevent decoder using the given reader to read uevents from.

func (*Decoder) Decode

func (d *Decoder) Decode() (*Uevent, error)

Decode blocks until the uext uevent happens, decodes and returns it. It is meant to be used in a loop.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements reading uevents from an AF_NETLINK socket.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying netlink socket.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Read reads from the underlying netlink socket. Trying to read from a closed reader return io.EOF.

type Uevent

type Uevent struct {
	Header string

	// default uevent variables as per kobject_uevent.c
	Action    string
	Devpath   string
	Subsystem string
	Seqnum    string

	// A key/value map of all variables
	Vars map[string]string
}

Uevent represents a single uevent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL