]>
Commit | Line | Data |
---|---|---|
7d68eb1b YW |
1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
2 | #pragma once | |
3 | ||
d02c6f54 YW |
4 | #include "sd-event.h" |
5 | ||
7d68eb1b | 6 | #include "macro.h" |
3797776e | 7 | #include "time-util.h" |
7d68eb1b YW |
8 | |
9 | struct udev_ctrl; | |
100bc5bf | 10 | |
d02c6f54 | 11 | enum udev_ctrl_msg_type { |
78467aeb | 12 | _UDEV_CTRL_END_MESSAGES, |
d02c6f54 YW |
13 | UDEV_CTRL_SET_LOG_LEVEL, |
14 | UDEV_CTRL_STOP_EXEC_QUEUE, | |
15 | UDEV_CTRL_START_EXEC_QUEUE, | |
16 | UDEV_CTRL_RELOAD, | |
17 | UDEV_CTRL_SET_ENV, | |
18 | UDEV_CTRL_SET_CHILDREN_MAX, | |
19 | UDEV_CTRL_PING, | |
20 | UDEV_CTRL_EXIT, | |
21 | }; | |
22 | ||
23 | union udev_ctrl_msg_value { | |
24 | int intval; | |
25 | char buf[256]; | |
26 | }; | |
27 | ||
28 | typedef int (*udev_ctrl_handler_t)(struct udev_ctrl *udev_ctrl, enum udev_ctrl_msg_type type, | |
29 | const union udev_ctrl_msg_value *value, void *userdata); | |
30 | ||
100bc5bf YW |
31 | int udev_ctrl_new_from_fd(struct udev_ctrl **ret, int fd); |
32 | static inline int udev_ctrl_new(struct udev_ctrl **ret) { | |
33 | return udev_ctrl_new_from_fd(ret, -1); | |
34 | } | |
35 | ||
7d68eb1b | 36 | int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl); |
d02c6f54 | 37 | struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl); |
7d68eb1b YW |
38 | struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl); |
39 | int udev_ctrl_cleanup(struct udev_ctrl *uctrl); | |
d02c6f54 YW |
40 | int udev_ctrl_attach_event(struct udev_ctrl *uctrl, sd_event *event); |
41 | int udev_ctrl_start(struct udev_ctrl *uctrl, udev_ctrl_handler_t callback, void *userdata); | |
42 | sd_event_source *udev_ctrl_get_event_source(struct udev_ctrl *uctrl); | |
43 | ||
78467aeb YW |
44 | int udev_ctrl_wait(struct udev_ctrl *uctrl, usec_t timeout); |
45 | ||
46 | int udev_ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf); | |
47 | static inline int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority) { | |
48 | return udev_ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL); | |
49 | } | |
50 | ||
51 | static inline int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl) { | |
52 | return udev_ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL); | |
53 | } | |
54 | ||
55 | static inline int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl) { | |
56 | return udev_ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL); | |
57 | } | |
58 | ||
59 | static inline int udev_ctrl_send_reload(struct udev_ctrl *uctrl) { | |
60 | return udev_ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL); | |
61 | } | |
62 | ||
63 | static inline int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key) { | |
64 | return udev_ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key); | |
65 | } | |
66 | ||
67 | static inline int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count) { | |
68 | return udev_ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL); | |
69 | } | |
70 | ||
71 | static inline int udev_ctrl_send_ping(struct udev_ctrl *uctrl) { | |
72 | return udev_ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL); | |
73 | } | |
74 | ||
75 | static inline int udev_ctrl_send_exit(struct udev_ctrl *uctrl) { | |
76 | return udev_ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL); | |
77 | } | |
7d68eb1b | 78 | |
7d68eb1b | 79 | DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl*, udev_ctrl_unref); |