]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
11 #include "alloc-util.h"
13 #include "string-util.h"
17 * @short_description: libudev context
23 * Opaque object representing the library context.
32 * @udev: udev library context
34 * Retrieve stored data pointer from library context. This might be useful
35 * to access from callbacks.
37 * Returns: stored userdata
39 _public_
void *udev_get_userdata(struct udev
*udev
) {
40 assert_return(udev
, NULL
);
42 return udev
->userdata
;
47 * @udev: udev library context
48 * @userdata: data pointer
50 * Store custom @userdata in the library context.
52 _public_
void udev_set_userdata(struct udev
*udev
, void *userdata
) {
56 udev
->userdata
= userdata
;
62 * Create udev library context. This only allocates the basic data structure.
64 * The initial refcount is 1, and needs to be decremented to
65 * release the resources of the udev library context.
67 * Returns: a new udev library context
69 _public_
struct udev
*udev_new(void) {
72 udev
= new(struct udev
, 1);
74 return_with_errno(NULL
, ENOMEM
);
76 *udev
= (struct udev
) {
85 * @udev: udev library context
87 * Take a reference of the udev library context.
89 * Returns: the passed udev library context
91 DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev
, udev
);
95 * @udev: udev library context
97 * Drop a reference of the udev library context. If the refcount
98 * reaches zero, the resources of the context will be released.
100 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
102 _public_
struct udev
*udev_unref(struct udev
*udev
) {
106 assert(udev
->n_ref
> 0);
109 /* This is different from our convention, but let's keep backward
110 * compatibility. So, do not use DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC()
111 * macro to define this function. */
119 * @udev: udev library context
120 * @log_fn: function to be called for log messages
122 * This function is deprecated.
125 _public_
void udev_set_log_fn(
127 void (*log_fn
)(struct udev
*udev
,
128 int priority
, const char *file
, int line
, const char *fn
,
129 const char *format
, va_list args
)) {
134 * udev_get_log_priority:
135 * @udev: udev library context
137 * This function is deprecated.
140 _public_
int udev_get_log_priority(struct udev
*udev
) {
141 return log_get_max_level();
145 * udev_set_log_priority:
146 * @udev: udev library context
147 * @priority: the new log priority
149 * This function is deprecated.
152 _public_
void udev_set_log_priority(struct udev
*udev
, int priority
) {
153 log_set_max_level(priority
);