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