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 uses getenv(3), which is declared to be not multi-thread-safe. That means the code calling the functions described here must not call setenv(3) from a parallel thread. It is recommended to only do calls to setenv() 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 πŸ¦‹

xoxo, systemd 261.3 β€” LIBUDEV(3) πŸ’–βœ¨

πŸ“¦ where this page comes from