]> git.proxmox.com Git - systemd.git/blame - src/shared/udev-util.h
New upstream version 250.2
[systemd.git] / src / shared / udev-util.h
CommitLineData
a032b68d 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
60f067b4
JS
2#pragma once
3
8b3d4ff0
MB
4#if HAVE_SYS_SDT_H
5#define SDT_USE_VARIADIC
6#include <sys/sdt.h>
7#endif
8
6e866b33 9#include "sd-device.h"
60f067b4 10
6e866b33 11#include "time-util.h"
60f067b4 12
3a6ce677
BR
13#define UDEV_NAME_SIZE 512
14#define UDEV_PATH_SIZE 1024
15#define UDEV_LINE_SIZE 16384
16
6e866b33
MB
17typedef enum ResolveNameTiming {
18 RESOLVE_NAME_NEVER,
19 RESOLVE_NAME_LATE,
20 RESOLVE_NAME_EARLY,
21 _RESOLVE_NAME_TIMING_MAX,
3a6ce677 22 _RESOLVE_NAME_TIMING_INVALID = -EINVAL,
6e866b33 23} ResolveNameTiming;
b012e921 24
6e866b33
MB
25ResolveNameTiming resolve_name_timing_from_string(const char *s) _pure_;
26const char *resolve_name_timing_to_string(ResolveNameTiming i) _const_;
27
28int udev_parse_config_full(
29 unsigned *ret_children_max,
30 usec_t *ret_exec_delay_usec,
31 usec_t *ret_event_timeout_usec,
a10f5d05
MB
32 ResolveNameTiming *ret_resolve_name_timing,
33 int *ret_timeout_signal);
6e866b33
MB
34
35static inline int udev_parse_config(void) {
a10f5d05 36 return udev_parse_config_full(NULL, NULL, NULL, NULL, NULL);
6e866b33
MB
37}
38
a032b68d
MB
39int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t deadline, sd_device **ret);
40int device_wait_for_devlink(const char *path, const char *subsystem, usec_t deadline, sd_device **ret);
bb4f798a 41int device_is_renaming(sd_device *dev);
3a6ce677
BR
42
43bool device_for_action(sd_device *dev, sd_device_action_t action);
44
45void log_device_uevent(sd_device *device, const char *str);
a032b68d
MB
46
47int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos);
3a6ce677 48size_t udev_replace_whitespace(const char *str, char *to, size_t len);
626cb2db 49size_t udev_replace_ifname(char *str);
3a6ce677
BR
50size_t udev_replace_chars(char *str, const char *allow);
51int udev_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value);
52
53int udev_queue_is_empty(void);
54int udev_queue_init(void);
8b3d4ff0 55
36ceca03
MB
56int on_ac_power(void);
57
8b3d4ff0
MB
58#if HAVE_SYS_SDT_H
59
60/* Each trace point can have different number of additional arguments. Note that when the macro is used only
61 * additional arguments are listed in the macro invocation!
62 *
63 * Default arguments for each trace point are as follows:
64 * - arg0 - action
65 * - arg1 - sysname
66 * - arg2 - syspath
67 * - arg3 - subsystem
68 */
69#define DEVICE_TRACE_POINT(name, dev, ...) \
70 do { \
71 PROTECT_ERRNO; \
72 const char *_n = NULL, *_p = NULL, *_s = NULL; \
73 sd_device *_d = (dev); \
74 sd_device_action_t _a = _SD_DEVICE_ACTION_INVALID; \
75 (void) sd_device_get_action(_d, &_a); \
76 (void) sd_device_get_sysname(_d, &_n); \
77 (void) sd_device_get_syspath(_d, &_p); \
78 (void) sd_device_get_subsystem(_d, &_s); \
79 STAP_PROBEV(udev, name, device_action_to_string(_a), _n, _p, _s __VA_OPT__(,) __VA_ARGS__);\
80 } while(false);
81#else
82#define DEVICE_TRACE_POINT(name, dev, ...) ((void) 0)
83#endif