Git Product home page Git Product logo

uevent's Introduction

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/s-urbaniak/uevent"
)

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

uevent's People

Contributors

s-urbaniak avatar silvanocerza avatar stapelberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

uevent's Issues

Provide a way to shutdown the udev loop gracefully

The project documentation shows a way to use uevent library as:

dec := uevent.NewDecoder(r)

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

I have an app with a goroutine that does this loop. Now I need to stop my application and shutdown the loop. Unfortunately there is no way to do it gracefully. I can do uevent.Close() in another goroutine but it is racy and causes a panic in bufio.Reader (see anatol/booster#22):

panic: bufio: reader returned negative count from Read

goroutine 6 [running]:
bufio.(*Reader).fill(0xc000070f68)
	/usr/lib/go/src/bufio/bufio.go:103 +0x1dd
bufio.(*Reader).ReadSlice(0xc000070f68, 0x0, 0xc, 0x7f6718544c28, 0xc0003c42f0, 0x0, 0xab0fc0)
	/usr/lib/go/src/bufio/bufio.go:360 +0x3d
bufio.(*Reader).collectFragments(0xc000070f68, 0xc000070d00, 0x40d610, 0xc00006b440, 0x30, 0x30, 0x823120, 0xc00005c960, 0x60, 0x7f671854e308, ...)
	/usr/lib/go/src/bufio/bufio.go:435 +0x7a
bufio.(*Reader).ReadString(0xc000070f68, 0xc00005c900, 0x7, 0x0, 0xc00011a9d8, 0x0)
	/usr/lib/go/src/bufio/bufio.go:483 +0x4c
github.com/s-urbaniak/uevent.(*Decoder).next(...)
	/home/anatol/go/pkg/mod/github.com/s-urbaniak/[email protected]/decoder.go:81
github.com/s-urbaniak/uevent.(*Decoder).Decode(0xc000070ed0, 0xc00006b3e0, 0x83cf0f, 0x7)
	/home/anatol/go/pkg/mod/github.com/s-urbaniak/[email protected]/decoder.go:42 +0x75
main.udevListener()
	/mnt/cold/sources/golang/booster/init/main.go:454 +0x185
created by main.boost
	/mnt/cold/sources/golang/booster/init/main.go:782 +0x4bd

Please provide a way to shutdown the uevent loop gracefully.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.