UDEV_NEW(3)

πŸ’… UDEV_NEW(3) β€” the udev_new girlies rise up ✨

okay so bestie, today we're talking about udev_new(3), which lives in the udev_new family of libudev functions, and honestly? it's giving "library card for the udev universe" πŸŽ€


🌸 NAME 🌸

udev_new, udev_ref, udev_unref β€” create, acquire and release a udev context object. that's the whole vibe: one makes it, one keeps it alive, one lets it go πŸ˜­πŸ’–


✨ SYNOPSIS ✨

#include <libudev.h>

struct udev *udev_new(void);

struct udev *udev_ref(struct udev *udev);

struct udev *udev_unref(struct udev *udev);

like, look at her. three little functions. iconic behavior honestly πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

so udev_new() allocates a brand-new udev context object and returns a pointer to it. main character energy fr fr 🌟

this object is opaque, and no cap β€” the caller must not access it through any means other than the functions provided by libudev. like, do not go poking around in there with your own little gremlin fingers, that's not the vibe πŸ™ˆ

initially, the reference count of the context is 1. you can acquire further references, and drop gained references, via udev_ref() and udev_unref(). and the moment the reference count hits 0? the context object is destroyed and freed. gone. poof. it's over πŸ’€


πŸ¦‹ RETURN VALUE πŸ¦‹

  • on success, udev_new() returns a pointer to the allocated udev context ✨
  • on failure, NULL is returned 😭
  • udev_ref() returns the argument that it was passed, unmodified β€” she gives it right back to you, no notes 🫢
  • udev_unref() always returns NULL. always. every time. periodt πŸ’…

πŸŽ€ HISTORY πŸŽ€

udev_new(), udev_ref(), and udev_unref() were added in version 221. vintage but still thriving, iykyk 🌈


πŸ‘‘ SEE ALSO πŸ‘‘

go read those next bestie, they're lowkey essential πŸ“šπŸ’–


⚠️ reminder that this whole thing is a C API situation β€” if you call udev_unref() and then keep touching the context, that's undefined behaviour territory and we do not do that here. keep your refcounts balanced, queen 🧚

that's the page!! πŸ“ this lil manual moment came to you courtesy of systemd 261.3 β€” mwah, go write some slay code bestie πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from