]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2008-2014 Kay Sievers <kay@vrfy.org>
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 #include "alloc-util.h"
32 #include "libudev-private.h"
34 #include "string-util.h"
38 * @short_description: libudev context
40 * The context contains the default values read from the udev config file,
41 * and is passed to all library operations.
47 * Opaque object representing the library context.
51 void (*log_fn
)(struct udev
*udev
,
52 int priority
, const char *file
, int line
, const char *fn
,
53 const char *format
, va_list args
);
59 * @udev: udev library context
61 * Retrieve stored data pointer from library context. This might be useful
62 * to access from callbacks.
64 * Returns: stored userdata
66 _public_
void *udev_get_userdata(struct udev
*udev
) {
69 return udev
->userdata
;
74 * @udev: udev library context
75 * @userdata: data pointer
77 * Store custom @userdata in the library context.
79 _public_
void udev_set_userdata(struct udev
*udev
, void *userdata
) {
82 udev
->userdata
= userdata
;
88 * Create udev library context. This only allocates the basic data structure.
90 * The initial refcount is 1, and needs to be decremented to
91 * release the resources of the udev library context.
93 * Returns: a new udev library context
95 _public_
struct udev
*udev_new(void) {
98 udev
= new0(struct udev
, 1);
110 * @udev: udev library context
112 * Take a reference of the udev library context.
114 * Returns: the passed udev library context
116 _public_
struct udev
*udev_ref(struct udev
*udev
) {
125 * @udev: udev library context
127 * Drop a reference of the udev library context. If the refcount
128 * reaches zero, the resources of the context will be released.
130 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
132 _public_
struct udev
*udev_unref(struct udev
*udev
) {
136 if (udev
->refcount
> 0)
143 * @udev: udev library context
144 * @log_fn: function to be called for log messages
146 * This function is deprecated.
149 _public_
void udev_set_log_fn(struct udev
*udev
,
150 void (*log_fn
)(struct udev
*udev
,
151 int priority
, const char *file
, int line
, const char *fn
,
152 const char *format
, va_list args
)) {
157 * udev_get_log_priority:
158 * @udev: udev library context
160 * This function is deprecated.
163 _public_
int udev_get_log_priority(struct udev
*udev
) {
164 return log_get_max_level();
168 * udev_set_log_priority:
169 * @udev: udev library context
170 * @priority: the new log priority
172 * This function is deprecated.
175 _public_
void udev_set_log_priority(struct udev
*udev
, int priority
) {
176 log_set_max_level(priority
);