]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include "alloc-util.h"
15 #include "string-util.h"
19 * @short_description: libudev context
25 * Opaque object representing the library context.
34 * @udev: udev library context
36 * Retrieve stored data pointer from library context. This might be useful
37 * to access from callbacks.
39 * Returns: stored userdata
41 _public_
void *udev_get_userdata(struct udev
*udev
) {
42 assert_return(udev
, NULL
);
44 return udev
->userdata
;
49 * @udev: udev library context
50 * @userdata: data pointer
52 * Store custom @userdata in the library context.
54 _public_
void udev_set_userdata(struct udev
*udev
, void *userdata
) {
58 udev
->userdata
= userdata
;
64 * Create udev library context. This only allocates the basic data structure.
66 * The initial refcount is 1, and needs to be decremented to
67 * release the resources of the udev library context.
69 * Returns: a new udev library context
71 _public_
struct udev
*udev_new(void) {
74 udev
= new(struct udev
, 1);
76 return_with_errno(NULL
, ENOMEM
);
78 *udev
= (struct udev
) {
87 * @udev: udev library context
89 * Take a reference of the udev library context.
91 * Returns: the passed udev library context
93 DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev
, udev
);
97 * @udev: udev library context
99 * Drop a reference of the udev library context. If the refcount
100 * reaches zero, the resources of the context will be released.
102 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
104 _public_
struct udev
*udev_unref(struct udev
*udev
) {
108 assert(udev
->n_ref
> 0);
111 /* This is different from our convetion, but let's keep backward
112 * compatibility. So, do not use DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC()
113 * macro to define this function. */
121 * @udev: udev library context
122 * @log_fn: function to be called for log messages
124 * This function is deprecated.
127 _public_
void udev_set_log_fn(
129 void (*log_fn
)(struct udev
*udev
,
130 int priority
, const char *file
, int line
, const char *fn
,
131 const char *format
, va_list args
)) {
136 * udev_get_log_priority:
137 * @udev: udev library context
139 * This function is deprecated.
142 _public_
int udev_get_log_priority(struct udev
*udev
) {
143 return log_get_max_level();
147 * udev_set_log_priority:
148 * @udev: udev library context
149 * @priority: the new log priority
151 * This function is deprecated.
154 _public_
void udev_set_log_priority(struct udev
*udev
, int priority
) {
155 log_set_max_level(priority
);