]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev.c
659aa2b743d8aa72b70b6a822fd5987491dd2a39
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "alloc-util.h"
8 #include "errno-util.h"
13 * @short_description: libudev context
19 * Opaque object representing the library context.
28 * @udev: udev library context
30 * Retrieve stored data pointer from library context. This might be useful
31 * to access from callbacks.
33 * Returns: stored userdata
35 _public_
void* udev_get_userdata(struct udev
*udev
) {
36 assert_return(udev
, NULL
);
38 return udev
->userdata
;
43 * @udev: udev library context
44 * @userdata: data pointer
46 * Store custom @userdata in the library context.
48 _public_
void udev_set_userdata(struct udev
*udev
, void *userdata
) {
52 udev
->userdata
= userdata
;
58 * Create udev library context. This only allocates the basic data structure.
60 * The initial refcount is 1, and needs to be decremented to
61 * release the resources of the udev library context.
63 * Returns: a new udev library context
65 _public_
struct udev
* udev_new(void) {
68 udev
= new(struct udev
, 1);
70 return_with_errno(NULL
, ENOMEM
);
72 *udev
= (struct udev
) {
81 * @udev: udev library context
83 * Take a reference of the udev library context.
85 * Returns: the passed udev library context
87 DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev
, udev
);
91 * @udev: udev library context
93 * Drop a reference of the udev library context. If the refcount
94 * reaches zero, the resources of the context will be released.
96 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
98 _public_
struct udev
* udev_unref(struct udev
*udev
) {
102 assert(udev
->n_ref
> 0);
105 /* This is different from our convention, but let's keep backward
106 * compatibility. So, do not use DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC()
107 * macro to define this function. */
115 * @udev: udev library context
116 * @log_fn: function to be called for log messages
118 * This function is deprecated.
121 _public_
void udev_set_log_fn(
123 void (*log_fn
)(struct udev
*udev
,
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
);