LIBUDEV(3)
β¨ libudev(3) β local-device API, but make it bestie β¨
πΈ NAME πΈ
libudev β API for enumerating and introspecting local devices
π SYNOPSIS π
#include <libudev.h>
pkg-config --cflags --libs libudev
π DESCRIPTION π
Okay so libudev.h provides an API to introspect and enumerate devices on the local system. She is supported, but bestie, she should not be used in new projects. Please see sd-device(3) for an equivalent replacement with a more modern API. π
Every function needs a libudev context to operate. You create that context via udev_new(3), and it tracks library state and links objects together. No global state is used by libudev β everything is always linked to a udev context. Periodt.
All functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time. Different threads may access the same object at different times. Multiple independent objects may be used from different threads in parallel. Threading rules are right there, bestie. π§
Heads up: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. That means the code calling the functions described here must not callsetenv(3)from a parallel thread. It is recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. No cap, respect the early-phase window. π«Ά
To introspect a local device on a system, you can create a udev device object via udev_device_new_from_syspath(3) and friends. That device object lets you query current state, read and write attributes and lookup properties of the device in question. Main character energy for one device. π₯
To enumerate local devices on the system, create an enumeration object via udev_enumerate_new(3). π¦
To monitor the local system for hotplugged or unplugged devices, create a monitor via udev_monitor_new_from_netlink(3). π
Whenever libudev returns a list of objects, the udev_list_entry(3) API should be used to iterate, access and modify those lists. Literally the list-handling bestie. π
Furthermore, libudev also exports legacy APIs that should not be used by new software (and as such are not documented as part of this manual). This includes the hardware database known as udev_hwdb (please use the new sd-hwdb(3) API instead) and the udev_queue object to query the udev daemon (which should not be used by new software at all). We do not stan the legacy path. π
π¦ SEE ALSO π¦
udev_new(3)udev_device_new_from_syspath(3)udev_enumerate_new(3)udev_monitor_new_from_netlink(3)udev_list_entry(3)systemd(1)sd-device(3)sd-hwdb(3)pkg-config(1)
xoxo, systemd 261.3 β LIBUDEV(3) πβ¨
π¦ where this page comes from
- ubuntu stonking: libudev-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms