{"id":23409231,"url":"https://github.com/pilebones/go-udev","last_synced_at":"2025-04-07T10:26:17.054Z","repository":{"id":25758854,"uuid":"106330917","full_name":"pilebones/go-udev","owner":"pilebones","description":"Simple udev implementation in Golang","archived":false,"fork":false,"pushed_at":"2023-01-30T05:50:24.000Z","size":811,"stargazers_count":103,"open_issues_count":10,"forks_count":29,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T09:06:22.557Z","etag":null,"topics":["devices","go","golang","linux","udev","udev-rules","udevadm","usb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilebones.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-09T20:16:56.000Z","updated_at":"2025-03-17T06:38:08.000Z","dependencies_parsed_at":"2023-02-16T04:20:41.550Z","dependency_job_id":null,"html_url":"https://github.com/pilebones/go-udev","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilebones%2Fgo-udev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilebones%2Fgo-udev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilebones%2Fgo-udev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilebones%2Fgo-udev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilebones","download_url":"https://codeload.github.com/pilebones/go-udev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634089,"owners_count":20970456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devices","go","golang","linux","udev","udev-rules","udevadm","usb"],"created_at":"2024-12-22T15:33:16.936Z","updated_at":"2025-04-07T10:26:17.027Z","avatar_url":"https://github.com/pilebones.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-udev [![Go Report Card](https://goreportcard.com/badge/github.com/pilebones/go-udev)](https://goreportcard.com/report/github.com/pilebones/go-udev) [![GitHub Repo stars](https://img.shields.io/github/stars/pilebones/go-udev)](https://somsubhra.github.io/github-release-stats/?username=pilebones\u0026repository=go-udev) [![GoDoc](https://godoc.org/github.com/pilebones/go-udev?status.svg)](https://godoc.org/github.com/pilebones/go-udev) [![Release](https://img.shields.io/github/release/pilebones/go-udev.svg)](https://github.com/pilebones/go-udev/releases/latest) [![License](https://img.shields.io/github/license/pilebones/go-udev)](/LICENSE) ![Build Status](https://github.com/pilebones/go-udev/workflows/CI/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/pilebones/go-udev/badge.svg?branch=master)](https://coveralls.io/github/pilebones/go-udev?branch=master)\n\nSimple udev implementation in Golang developed from scratch.\nThis library allow to listen and manage Linux-kernel (since version 2.6.10) Netlink messages to user space (ie: `NETLINK_KOBJECT_UEVENT`).\n\nLike [`udev`](https://en.wikipedia.org/wiki/Udev) you will be able to monitor, display and manage devices plug to the system.\n\n## How to\n\n### Get sources\n\n```\ngo get github.com/pilebones/go-udev\n```\n\n### Unit test\n\n```\ngo test ./...\n```\n\n### Compile\n\n```\ngo build\n```\n\n### Usage\n\n```\n./go-udev -\u003cmode\u003e [-file=\u003cabsolute_path\u003e]\n```\n\nAllowed mode: `info` or `monitor`\nFile should contains matcher rules (see: \"Advanced usage\" section)\n\n### Info Mode\n\nCrawl /sys/devices uevent struct to detect plugged devices:\n\n```\n./go-udev -info\n```\n\n### Monitor Mode\n\nHandle all kernel message to detect change about plugged or unplugged devices:\n\n```\n./go-udev -monitor\n```\n\n#### Examples\n\nExample of output when a USB storage is plugged:\n```\n2017/10/20 23:47:23 Handle netlink.UEvent{\n    Action: \"add\",\n    KObj:   \"/devices/pci0000:00/0000:00:14.0/usb1/1-1\",\n    Env:    {\"PRODUCT\":\"58f/6387/10b\", \"TYPE\":\"0/0/0\", \"BUSNUM\":\"001\", \"DEVNUM\":\"005\", \"SEQNUM\":\"2511\", \"DEVNAME\":\"bus/usb/001/005\", \"DEVPATH\":\"/devices/pci0000:00/0000:00:14.0/usb1/1-1\", \"SUBSYSTEM\":\"usb\", \"MAJOR\":\"189\", \"MINOR\":\"4\", \"DEVTYPE\":\"usb_device\", \"ACTION\":\"add\"},\n}\n2017/10/20 23:47:23 Handle netlink.UEvent{\n    Action: \"add\",\n    KObj:   \"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0\",\n    Env:    {\"SUBSYSTEM\":\"usb\", \"TYPE\":\"0/0/0\", \"INTERFACE\":\"8/6/80\", \"MODALIAS\":\"usb:v058Fp6387d010Bdc00dsc00dp00ic08isc06ip50in00\", \"SEQNUM\":\"2512\", \"DEVPATH\":\"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0\", \"DEVTYPE\":\"usb_interface\", \"PRODUCT\":\"58f/6387/10b\", \"ACTION\":\"add\"},\n}\n2017/10/20 23:47:23 Handle netlink.UEvent{\n    Action: \"add\",\n    KObj:   \"/module/usb_storage\",\n    Env:    {\"SEQNUM\":\"2513\", \"ACTION\":\"add\", \"DEVPATH\":\"/module/usb_storage\", \"SUBSYSTEM\":\"module\"},\n}\n[...]\n```\n\nExample of output when a USB storage is unplugged:\n```\n[...]\n2017/10/20 23:47:29 Handle netlink.UEvent{\n    Action: \"remove\",\n    KObj:   \"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb\",\n    Env:    {\"SUBSYSTEM\":\"block\", \"MAJOR\":\"8\", \"MINOR\":\"16\", \"DEVNAME\":\"sdb\", \"DEVTYPE\":\"disk\", \"SEQNUM\":\"2543\", \"ACTION\":\"remove\", \"DEVPATH\":\"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb\"},\n}\n[...]\n2017/10/20 23:47:29 Handle netlink.UEvent{\n    Action: \"remove\",\n    KObj:   \"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0\",\n    Env:    {\"ACTION\":\"remove\", \"SUBSYSTEM\":\"usb\", \"DEVTYPE\":\"usb_interface\", \"SEQNUM\":\"2548\", \"MODALIAS\":\"usb:v058Fp6387d010Bdc00dsc00dp00ic08isc06ip50in00\", \"DEVPATH\":\"/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0\", \"PRODUCT\":\"58f/6387/10b\", \"TYPE\":\"0/0/0\", \"INTERFACE\":\"8/6/80\"},\n}\n2017/10/20 23:47:29 Handle netlink.UEvent{\n    Action: \"remove\",\n    KObj:   \"/devices/pci0000:00/0000:00:14.0/usb1/1-1\",\n    Env:    {\"PRODUCT\":\"58f/6387/10b\", \"TYPE\":\"0/0/0\", \"DEVNUM\":\"005\", \"SEQNUM\":\"2549\", \"ACTION\":\"remove\", \"DEVPATH\":\"/devices/pci0000:00/0000:00:14.0/usb1/1-1\", \"SUBSYSTEM\":\"usb\", \"MAJOR\":\"189\", \"MINOR\":\"4\", \"DEVNAME\":\"bus/usb/001/005\", \"DEVTYPE\":\"usb_device\", \"BUSNUM\":\"001\"},\n}\n```\n\nNote: To implement your own monitoring system, please see `main.go` as a simple example.\n\n### Advanced usage\n\nIs it possible to filter uevents/devices with a Matcher.\n\nA Matcher is a list of your own rules to match only relevant uevent kernel message (see: `matcher.sample`).\n\nYou could pass this file using for both mode:\n```\n./go-udev -file  matcher.sample [...]\n\n```\n\n## Throubleshooting\n\nDon't hesitate to notice if you detect a problem with this tool or library.\n\n## Links\n\n- Netlink Manual: http://man7.org/linux/man-pages/man7/netlink.7.html\n- Linux source code about: \n  * Struct sockaddr_netlink: http://elixir.free-electrons.com/linux/v3.12/source/lib/kobject_uevent.c#L45\n  * KObject action: http://elixir.free-electrons.com/linux/v3.12/source/lib/kobject_uevent.c#L45\n\n## Documentation\n- [GoDoc Reference](http://godoc.org/github.com/pilebones/go-udev).\n\n## License\n\ngo-udev is available under the [GNU GPL v3 - Clause License](https://opensource.org/licenses/GPL-3.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilebones%2Fgo-udev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilebones%2Fgo-udev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilebones%2Fgo-udev/lists"}